User.class.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class User extends SQLiteEntity{
  3. protected $id,$login,$password;
  4. protected $TABLE_NAME = 'user';
  5. protected $CLASS_NAME = 'User';
  6. protected $object_fields =
  7. array(
  8. 'id'=>'key',
  9. 'login'=>'string',
  10. 'password'=>'string'
  11. );
  12. function __construct(){
  13. parent::__construct();
  14. }
  15. function exist($login,$password){
  16. $userManager = new User();
  17. return $userManager->load(array('login'=>$login,'password'=>User::encrypt($password)));
  18. }
  19. function existAuthToken($auth){
  20. $result = false;
  21. $userManager = new User();
  22. $users = $userManager->populate('id');
  23. foreach($users as $user){
  24. if(sha1($user->getPassword().$user->getLogin())==$auth) $result = $user;
  25. }
  26. return $result;
  27. }
  28. function getId(){
  29. return $this->id;
  30. }
  31. function getLogin(){
  32. return $this->login;
  33. }
  34. function setLogin($login){
  35. $this->login = $login;
  36. }
  37. function getPassword(){
  38. return $this->password;
  39. }
  40. function setPassword($password){
  41. $this->password = User::encrypt($password);
  42. }
  43. static function encrypt($password){
  44. return sha1($password);
  45. }
  46. }
  47. ?>