changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / include / classes / user_class.php
1 <?php
2 /*
3  * OpenCaps
4  * http://opencaps.atrc.utoronto.ca
5  * 
6  * Copyright 2009 Heidi Hazelton
7  * Adaptive Technology Resource Centre, University of Toronto
8  * 
9  * Licensed under the Educational Community License (ECL), Version 2.0. 
10  * You may not use this file except in compliance with this License.
11  * http://www.opensource.org/licenses/ecl2.php
12  * 
13  */
14
15 class user {
16         public $id;
17         public $username;
18         public $name;
19         
20         public $preferences = Array();
21         public $valid;
22
23         public function __construct($id, $username) {
24                 $this->id = $id;
25                 
26                 if ($id = 99999)
27                         $this->username = "guest";
28                 else
29                         $this->username = $username;
30                         
31                 $this->valid = false;
32                 
33                 //default $preferences
34         }
35         
36         public function login($username, $password) {
37                 global $this_db;
38                 $row = '';
39                 $result = '';
40                 
41                 //check if user exists in db with this password
42                 if (isset($username, $password)) {
43                         /*if (version_compare(PHP_VERSION, '5.1.0', '>=')) {
44                                 session_regenerate_id(TRUE);
45                         }*/
46                         
47                         if ($username=="guest" && $password=="guest") {
48                                 $this->valid    = true;
49                                 $this->id               = '99999';
50                                 $this->username = $username;
51                                 
52                                 $_SESSION['valid_user'] = true;
53                                 $_SESSION['mid'] = $this->id;
54                                 $_SESSION['username'] = $this->username;
55                                 
56                                 return;
57                         }
58                                 
59                 
60                         $username = addslashes($username);
61                         $password = addslashes($password);
62                 
63                         //$sql = "SELECT member_id, login, SHA1(CONCAT(password, '-', '".DB_PASSWORD."')) AS pass FROM members WHERE login='$this_login' AND SHA1(CONCAT(password, '$_SESSION[token]'))='$this_password'";
64                         
65                         $sql = "SELECT member_id, login, password FROM members WHERE login='$username' AND password='$password'";
66                         $result = mysql_query($sql, $this_db->db);
67                 
68                         if ($row = mysql_fetch_assoc($result)) {
69                                 
70                                 $this->valid    = true;
71                                 $this->id               = intval($row['member_id']);
72                                 $this->username = $row['login'];
73                                 
74                                 $_SESSION['mid'] = $this->id;
75                                 $_SESSION['username'] = $this->username;
76                                 $_SESSION['valid_user'] = true;
77                                 
78                                 $sql = "UPDATE members SET last_login=NOW() WHERE member_id=$_SESSION[mid]";
79                                 mysql_query($sql, $this_db->db);
80                 
81                                 $_SESSION['feedback'][] = 'Successfully logged in.';
82         
83                         } else {
84                                 $this->valid    = false;
85                                 $this->id               = 0;
86                                 $this->username = '';
87                                 $_SESSION['errors'][] = 'Invalid login.';                               
88                         }
89                         header('Location:start.php');
90                         exit;
91                 }               
92                 
93                 //create cookies
94         }               
95         
96         /* checks if a user is logged in and valid */
97         public function authenticate() {
98                 if ($this->valid) {
99                         return true;            
100                 } 
101                         
102                 return false;
103         }
104         
105         public function logout() {
106                 unset($_SESSION['valid_user']);
107                 unset($_SESSION['member_id']);
108                 unset($_SESSION['errors']);             
109                 $_SESSION['feedback'][] = 'Successfully logged out.';
110                 
111                 header('Location: index.php');
112                 exit;
113         }
114
115         public function savePrefs() {
116                 
117         }
118         
119         public function getPrefs() {
120                 
121         }
122         
123 }
124
125 ?>