]>
jfr.im git - z_archive/KronOS.git/blob - application/models/user.php
187223e2f2c17755fdd2941207c87e7a411924a6
1 <?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
3 class User
extends CI_Model
{
4 protected $cached_sid, $cached_uid, $cached_level, $cached_display_name;
5 public function __construct() {
10 public function try_login($user, $pass) {
11 $this->db
->select('uid, password, salt');
12 $this->db
->where('username', $user);
13 $q = $this->db
->get('users');
14 if ($q->num_rows() > 0) {
16 $pwdigest = sha1($row->salt
.$pass);
17 if ($pwdigest == $row->password
) {
18 return $this->do_login($row->uid
);
23 public function do_login($uid) {
24 $this->db
->select('display_name, level');
25 $this->db
->where('uid', $uid);
26 $q = $this->db
->get('users');
27 if ($q->num_rows() == 0)
31 $this->display_name($row->display_name
);
32 $this->level($row->level
);
38 'lockip' => $this->input
->ip_address(),
40 $this->db
->insert('sessions', $sdata);
41 $this->sid($this->db
->insert_id());
43 $this->input
->set_cookie('session_id', $this->sid());
48 public function sid($new=NULL) {
50 $old = $this->cached_sid
;
51 $this->cached_sid
= $new;
55 if (isset($this->cached_sid
)) {
56 return $this->cached_sid
;
58 // FIXME needs IP-lock checking...
59 return $this->cached_sid
= $this->input
->cookie('session_id');
62 public function uid($new=NULL) {
64 $old = $this->cached_uid
;
65 $this->cached_uid
= $new;
69 if (isset($this->cached_uid
)) {
70 return $this->cached_uid
;
74 $this->db
->select('uid');
75 $this->db
->where('sid', $sid);
76 $q = $this->db
->get('sessions');
77 if ($q->num_rows() > 0) {
79 return $this->cached_uid
= $row->uid
;
85 public function display_name($new=NULL) {
87 $old = $this->cached_display_name
;
88 $this->cached_display_name
= $new;
92 if (isset($this->cached_display_name
)) {
93 return $this->cached_display_name
;
97 $this->db
->select('display_name');
98 $this->db
->where('uid', $uid);
99 $q = $this->db
->get('users');
100 if ($q->num_rows() > 0) {
102 return $this->cached_display_name
= $row->display_name
;
108 public function level($new=NULL) {
110 $this->cached_level
= $new;
113 public function is_logged_in() {
114 return $this->sid() > 0;