summaryrefslogtreecommitdiffstats
path: root/application/models/muser.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/models/muser.php')
-rw-r--r--application/models/muser.php70
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$");
+ }
+
+}
+