You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 regels
971 B

3 jaren geleden
  1. <?php
  2. namespace Home\Model;
  3. use Home\Model\BaseModel;
  4. /**
  5. *
  6. * @author star7th
  7. */
  8. class UserTokenModel extends BaseModel {
  9. public function createToken($uid,$token_expire = 0 ){
  10. $token_expire = $token_expire > 0 ? (time() + $token_expire ) : (time() + 60*60*24*90 );
  11. $token = md5(md5($uid.$token_expire.time().rand()."showdoc")."rdgsvgsrgr67hghf54t").md5($uid.$token_expire.time().rand()."showdoc");
  12. $data['uid'] = $uid ;
  13. $data['token'] = $token ;
  14. $data['token_expire'] = $token_expire ;
  15. $data['ip'] = getIPaddress() ;
  16. $data['addtime'] = time() ;
  17. $ret = $this->add($data);
  18. if ($ret) {
  19. //删除过期的token
  20. $this->where( "token_expire < ".time() )->delete();
  21. return $token ;
  22. }
  23. return false ;
  24. }
  25. public function getToken($token){
  26. return $this->where("token='%s'",array($token))->find();
  27. }
  28. public function setLastTime($token){
  29. return $this->where("token='%s'",array($token))->save(array("last_check_time"=>time()));
  30. }
  31. }