UserModel.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Api\Model;
  3. use Api\Model\BaseModel;
  4. class UserModel extends BaseModel {
  5. /**
  6. * 用户名是否已经存在
  7. *
  8. */
  9. public function isExist($username){
  10. return $this->where("username = '%s'",array($username))->find();
  11. }
  12. /**
  13. * 注册新用户
  14. *
  15. */
  16. public function register($username,$password){
  17. $password = md5(base64_encode(md5($password)).'576hbgh6');
  18. return $this->add(array('username'=>$username ,'password'=>$password , 'reg_time'=>time()));
  19. }
  20. //修改用户密码
  21. public function updatePwd($uid, $password){
  22. $password = md5(base64_encode(md5($password)).'576hbgh6');
  23. return $this->where("uid ='%d' ",array($uid))->save(array('password'=>$password));
  24. }
  25. /**
  26. * 返回用户信息
  27. * @return
  28. */
  29. public function userInfo($uid){
  30. return $this->where("uid = '%d'",array($uid))->find();
  31. }
  32. /**
  33. *@param username:登录名
  34. *@param password 登录密码
  35. */
  36. public function checkLogin($username,$password){
  37. $password = md5(base64_encode(md5($password)).'576hbgh6');
  38. $where=array($username,$password,$username,$password);
  39. return $this->where("( username='%s' and password='%s' ) ",$where)->find();
  40. }
  41. }