diff options
author | Florian Pritz <bluewind@xinu.at> | 2012-04-08 23:13:15 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2012-04-09 20:47:36 +0200 |
commit | 3f01ddce9dff69a49493541882de85854cbcebe5 (patch) | |
tree | 13c23f0a6893970ca71fbbfe763c3c696c8a0a4b /application/models/muser.php | |
parent | b18f4e453ecdf3404a107f9fc72d7bd9249401d0 (diff) |
start working on users
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models/muser.php')
-rw-r--r-- | application/models/muser.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/application/models/muser.php b/application/models/muser.php new file mode 100644 index 000000000..0b3d26be7 --- /dev/null +++ b/application/models/muser.php @@ -0,0 +1,70 @@ +<?php + +class Muser extends CI_Model { + function __construct() + { + parent::__construct(); + $this->load->library("session"); + } + + function logged_in() + { + return $this->session->userdata('logged_in') == true; + } + + function login($username, $password) + { + $query = $this->db->query(' + SELECT * + FROM `users` + WHERE `username` = ? + ', array($username))->row_array(); + + if (crypt($password, $query["password"] == $password)) { + $this->session->set_userdata('logged_in', true); + $this->session->set_userdata('username', $username); + return true; + } else { + return false; + } + } + + function logout() + { + $this->session->unset_userdata('logged_in'); + $this->session->unset_userdata('username'); + } + + function get_username() + { + return $this->session->userdata('username'); + } + + function get_userid() + { + $query = $this->db->query(" + SELECT id + FROM users + WHERE username = ? + ", array($this->get_username()))->row_array(); + return $query["id"]; + } + + function require_access() + { + if ($this->logged_in()) { + return true; + } else { + $this->session->set_flashdata("uri", $this->uri->uri_string()); + redirect('user/login'); + } + } + + function hash_password($password) + { + $salt = random_alphanum(22); + return crypt($password, "$2a$10$$salt$"); + } + +} + |