User.class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Define an application user.
  4. *
  5. * @author valentin carruesco
  6. *
  7. * @category Core
  8. *
  9. * @license copyright
  10. */
  11. class User extends Entity
  12. {
  13. public $id,$login,$password,$name,$firstname,$mail,$state,$rank,$rights;
  14. protected $fields =
  15. array(
  16. 'id' => 'key',
  17. 'login' => 'string',
  18. 'password' => 'string',
  19. 'name' => 'string',
  20. 'firstname' => 'string',
  21. 'mail' => 'string',
  22. 'rank' => 'longstring',
  23. 'state' => 'int',
  24. );
  25. public static function check($login, $password)
  26. {
  27. $user = self::load(array('login' => $login, 'password' => self::password_encrypt($password)));
  28. return is_object($user) ? $user : new self();
  29. }
  30. public function can($section, $selectedRight)
  31. {
  32. return !isset($this->rights[$section]) ? false : $this->rights[$section][$selectedRight];
  33. }
  34. public function fullName()
  35. {
  36. $fullName = ucfirst($this->firstname).' '.strtoupper($this->name);
  37. return trim($fullName) != '' ? $fullName : $this->login;
  38. }
  39. public static function password_encrypt($password)
  40. {
  41. return sha1(md5($password));
  42. }
  43. public function connected()
  44. {
  45. return $this->id != 0;
  46. }
  47. }