Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2.  
  3. class User {
  4.  
  5.     private $registry;
  6.  
  7.     private $id;
  8.     private $username;
  9.     private $email;
  10.     private $reset_key;
  11.     private $reset_expires;
  12.     private $banned;
  13.     private $admin;
  14.     private $active;
  15.     private $exists = FALSE;
  16.  
  17.     public function __construct(Registry $registry, $id=0, $username='', $password='') {
  18.  
  19.         $this->registry = $registry;
  20.  
  21.         if (intval($id) > 0) {
  22.             $sqlQuery = "SELECT * FROM `users` WHERE id='$id'";
  23.             $db = $this->registry->getObj('db');
  24.             $db->query($sqlQuery);
  25.             if ($db->getNumRows() == 1) {
  26.                 $row = $db->getRows();
  27.                 $this->id = $row['id'];
  28.                 $this->username = $row['username'];
  29.                 $this->email = $row['email'];
  30.                 $this->reset_key = $row['reset_key'];
  31.                 $this->reset_expires = $row['reset_expires'];
  32.                 $this->active = $row['active'];
  33.                 $this->banned = $row['banned'];
  34.                 $this->admin = $row['admin'];
  35.                 $this->exists = TRUE;
  36.             }
  37.         }
  38.         else if ($username !== '' && $password !== '') {
  39.             $db = $this->registry->getObj('db');
  40.             $username = $db->sanitize($username);
  41.             $password_hash = md5($password);
  42.  
  43.             $sqlQuery = "SELECT * FROM `users` WHERE username='$username' AND
  44.                password_hash='$password_hash'";
  45.             $db->query($sqlQuery);
  46.             if ($db->getNumRows() == 1) {
  47.                 $row = $db->getRows();
  48.                 $this->id = $row['id'];
  49.                 $this->username = $row['username'];
  50.                 $this->email = $row['email'];
  51.                 $this->reset_key = $row['reset_key'];
  52.                 $this->reset_expires = $row['reset_expires'];
  53.                 $this->active = $row['active'];
  54.                 $this->banned = $row['banned'];
  55.                 $this->admin = $row['admin'];
  56.                 $this->exists = TRUE;
  57.  
  58.             }
  59.         }
  60.     }
  61.  
  62.     public function getId() {
  63.  
  64.         return $this->id;
  65.  
  66.     }
  67.  
  68.     public function getUsername() {
  69.  
  70.         return $this->username;
  71.     }
  72.  
  73.     public function getEmail() {
  74.  
  75.         return $this->email;
  76.  
  77.     }
  78.  
  79.     public function isBanned() {
  80.  
  81.         return ($this->banned)?TRUE:FALSE;
  82.     }
  83.  
  84.     public function isAdmin() {
  85.  
  86.         return ($this->admin)?TRUE:FALSE;
  87.     }
  88.  
  89.     public function isActive() {
  90.  
  91.         return ($this->active)?TRUE:FALSE;
  92.  
  93.     }
  94.  
  95.     public function isValid() {
  96.  
  97.         return ($this->exists)?TRUE:FALSE;
  98.     }
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement