Advertisement
Guest User

larsemil

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