Advertisement
Guest User

User.php

a guest
Oct 21st, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2. class User {
  3. private $_db,
  4. $_data,
  5. $_sessionName;
  6.  
  7. public function __construct($user = null) {
  8. $this->_db = DB::getInstance();
  9.  
  10. $this->_sessionName = Conig::get('session/session_name');
  11. }
  12.  
  13. public function create($fields = array()) {
  14. if (!$this->_db->insert('users', $fields)) {
  15. throw new Exception('There was a problem creating an account.');
  16. }
  17. }
  18.  
  19. public function find($user = null) {
  20. if ($user) {
  21. $field = (is_numeric($user)) ? 'id' : 'username';
  22. $data = $this->_db->get('users', array($field, '=', $user));
  23.  
  24. if ($data->count()) {
  25. $this->_data = $data->first();
  26. return true;
  27. }
  28. }
  29. return false;
  30. }
  31.  
  32. public function login($username = null, $password = null) {
  33. $user = $this->find($username);
  34.  
  35. if ($user) {
  36. if($this->data()->password === Hash::make($password, $this->data()->salt)) {
  37. Session::put();
  38. }
  39. }
  40.  
  41. return false;
  42. }
  43.  
  44. private function data() {
  45. return $this->_data;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement