Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User {
- private $registry;
- private $id;
- private $username;
- private $email;
- private $reset_key;
- private $reset_expires;
- private $banned;
- private $admin;
- private $active;
- private $exists = FALSE;
- public function __construct(Registry $registry, $id=0, $username='', $password='') {
- $this->registry = $registry;
- if (intval($id) > 0) {
- $sqlQuery = "SELECT * FROM `users` WHERE id='$id'";
- $db = $this->registry->getObj('db');
- $db->query($sqlQuery);
- if ($db->getNumRows() == 1) {
- $row = $db->getRows();
- $this->id = $row['id'];
- $this->username = $row['username'];
- $this->email = $row['email'];
- $this->reset_key = $row['reset_key'];
- $this->reset_expires = $row['reset_expires'];
- $this->active = $row['active'];
- $this->banned = $row['banned'];
- $this->admin = $row['admin'];
- $this->exists = TRUE;
- }
- }
- else if ($username !== '' && $password !== '') {
- $db = $this->registry->getObj('db');
- $username = $db->sanitize($username);
- $password_hash = md5($password);
- $sqlQuery = "SELECT * FROM `users` WHERE username='$username' AND
- password_hash='$password_hash'";
- $db->query($sqlQuery);
- if ($db->getNumRows() == 1) {
- $row = $db->getRows();
- $this->id = $row['id'];
- $this->username = $row['username'];
- $this->email = $row['email'];
- $this->reset_key = $row['reset_key'];
- $this->reset_expires = $row['reset_expires'];
- $this->active = $row['active'];
- $this->banned = $row['banned'];
- $this->admin = $row['admin'];
- $this->exists = TRUE;
- }
- }
- }
- public function getId() {
- return $this->id;
- }
- public function getUsername() {
- return $this->username;
- }
- public function getEmail() {
- return $this->email;
- }
- public function isBanned() {
- return ($this->banned)?TRUE:FALSE;
- }
- public function isAdmin() {
- return ($this->admin)?TRUE:FALSE;
- }
- public function isActive() {
- return ($this->active)?TRUE:FALSE;
- }
- public function isValid() {
- return ($this->exists)?TRUE:FALSE;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement