User.class.php 1.0 KB

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