SHOW:
|
|
- or go back to the newest paste.
1 | - | <?php |
1 | + | <?php |
2 | - | define("ADMINISTRATOR","0"); |
2 | + | define("ADMINISTRATOR","0"); |
3 | - | define("OWNER", "1"); |
3 | + | define("OWNER", "1"); |
4 | - | define("USER", "2"); |
4 | + | define("USER", "2"); |
5 | - | define("EMAIL", "3"); |
5 | + | define("EMAIL", "3"); |
6 | - | define("GUEST","4"); |
6 | + | define("GUEST","4"); |
7 | - | |
7 | + | |
8 | - | |
8 | + | |
9 | - | class users |
9 | + | class users |
10 | - | { |
10 | + | { |
11 | - | protected $username = ''; |
11 | + | protected $username = ''; |
12 | - | protected $loggedIn = false; |
12 | + | protected $loggedIn = false; |
13 | - | protected $userRole = GUEST; |
13 | + | protected $userRole = GUEST; |
14 | - | |
14 | + | |
15 | - | function __construct($username, $password = false) |
15 | + | function __construct($username, $password = false) |
16 | - | { |
16 | + | { |
17 | - | // we get either a emailadress or a username, lets see which |
17 | + | // we get either a emailadress or a username, lets see which |
18 | - | $this->username = $username; |
18 | + | $this->username = $username; |
19 | - | |
19 | + | |
20 | - | //does username contain @ |
20 | + | //does username contain @ |
21 | - | if(strstr($this->username,"@")) |
21 | + | if(strstr($this->username,"@")) |
22 | - | { |
22 | + | { |
23 | - | $this->loginEmailUser($username,$password); |
23 | + | $this->loginEmailUser($username,$password); |
24 | - | } |
24 | + | } |
25 | - | else |
25 | + | else |
26 | - | { |
26 | + | { |
27 | - | $sql = "select * from user where username = '".$this->username."'"; |
27 | + | $sql = "select * from user where username = '".$this->username."'"; |
28 | - | foreach(DB::$dbh->query($sql) as $user) |
28 | + | foreach(DB::$dbh->query($sql) as $user) |
29 | - | { |
29 | + | { |
30 | - | if($this->username == $user['username'] ) |
30 | + | if($this->username == $user['username'] ) |
31 | - | { |
31 | + | { |
32 | - | if($password == $user['password']) |
32 | + | if($password == $user['password']) |
33 | - | { |
33 | + | { |
34 | - | $this->userRole = $user['adminlevel']; |
34 | + | $this->userRole = $user['adminlevel']; |
35 | - | $this->password = md5($password); |
35 | + | $this->password = md5($password); |
36 | - | $this->loggedIn = true; |
36 | + | $this->loggedIn = true; |
37 | - | } |
37 | + | } |
38 | - | |
38 | + | |
39 | - | } |
39 | + | } |
40 | - | } |
40 | + | } |
41 | - | |
41 | + | |
42 | - | } |
42 | + | } |
43 | - | |
43 | + | |
44 | - | |
44 | + | |
45 | - | } |
45 | + | } |
46 | - | |
46 | + | |
47 | - | function loginEmailUser($username, $password) |
47 | + | function loginEmailUser($username, $password) |
48 | - | { |
48 | + | { |
49 | - | $this->db = DB::init("mailserver","root","*","dalnix.se", true); |
49 | + | $this->db = DB::init("mailserver","root","*","dalnix.se", true); |
50 | - | |
50 | + | |
51 | - | $sql = "select * from view_users where email = '$username'"; |
51 | + | $sql = "select * from view_users where email = '$username'"; |
52 | - | foreach($this->db->query($sql) as $user) |
52 | + | foreach($this->db->query($sql) as $user) |
53 | - | { |
53 | + | { |
54 | - | if($user['email'] == $username) |
54 | + | if($user['email'] == $username) |
55 | - | { |
55 | + | { |
56 | - | if($user['password'] == md5($password) ) |
56 | + | if($user['password'] == md5($password) ) |
57 | - | { |
57 | + | { |
58 | - | $this->username = $username; |
58 | + | $this->username = $username; |
59 | - | $this->userRole = EMAIL; |
59 | + | $this->userRole = EMAIL; |
60 | - | $this->loggedIn = true; |
60 | + | $this->loggedIn = true; |
61 | - | $this->password = md5($password); |
61 | + | $this->password = md5($password); |
62 | - | $objs = explode("@",$username); |
62 | + | $objs = explode("@",$username); |
63 | - | $this->parentDomain = $objs[1]; |
63 | + | $this->parentDomain = $objs[1]; |
64 | - | $this->emailUser = $objs[0]; |
64 | + | $this->emailUser = $objs[0]; |
65 | - | } |
65 | + | } |
66 | - | } |
66 | + | } |
67 | - | |
67 | + | |
68 | - | } |
68 | + | } |
69 | - | } |
69 | + | } |
70 | - | |
70 | + | |
71 | - | function isLoggedIn() |
71 | + | function isLoggedIn() |
72 | - | { |
72 | + | { |
73 | - | if($this->loggedIn) |
73 | + | if($this->loggedIn) |
74 | - | return true; |
74 | + | return true; |
75 | - | else |
75 | + | else |
76 | - | return false; |
76 | + | return false; |
77 | - | } |
77 | + | } |
78 | - | |
78 | + | |
79 | - | function getUserRole() |
79 | + | function getUserRole() |
80 | - | { |
80 | + | { |
81 | - | |
81 | + | |
82 | - | return $this->userRole; |
82 | + | return $this->userRole; |
83 | - | } |
83 | + | } |
84 | - | |
84 | + | |
85 | - | function getUid() |
85 | + | function getUid() |
86 | - | { |
86 | + | { |
87 | - | |
87 | + | |
88 | - | return $this->username; |
88 | + | return $this->username; |
89 | - | } |
89 | + | } |
90 | - | |
90 | + | |
91 | - | // get only username, you sqrewed up nbmy super coding adding UR:. shame on you ;) |
91 | + | // get only username, you sqrewed up nbmy super coding adding UR:. shame on you ;) |
92 | - | function getUsername() |
92 | + | function getUsername() |
93 | - | { |
93 | + | { |
94 | - | return $this->username; |
94 | + | return $this->username; |
95 | - | } |
95 | + | } |
96 | - | |
96 | + | |
97 | - | function getPassword() |
97 | + | function getPassword() |
98 | - | { |
98 | + | { |
99 | - | return $this->password; |
99 | + | return $this->password; |
100 | - | |
100 | + | |
101 | - | } |
101 | + | } |
102 | - | |
102 | + | |
103 | - | |
103 | + | |
104 | - | } |
104 | + | } |
105 | ?> |