示例#1
0
文件: Login.php 项目: skybird/phalcon
 public function loginByCookie($tokenString)
 {
     $this->getDI()->getEventsManager()->fire('user:beforeLoginByCookie', $tokenString);
     $tokenArray = explode('|', $tokenString);
     if (!$tokenArray || count($tokenArray) < 3) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_FORMAT_INCORRECT'));
         return false;
     }
     $token = new Entities\Tokens();
     $token->assign(array('sessionId' => $tokenArray[0], 'token' => $tokenArray[1], 'userHash' => $tokenArray[2]));
     $tokenInfo = $token::findFirst();
     if (!$tokenInfo) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_NOT_FOUND'));
         return false;
     }
     if ($tokenInfo->expiredAt < time()) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_EXPIRED'));
         return false;
     }
     $login = new Login();
     $login->id = $tokenInfo->userId;
     return $login->login();
 }
示例#2
0
文件: Login.php 项目: skybird/EvaUser
 public function getRememberMeToken()
 {
     if (!$this->username) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_NO_USER_INPUT'));
         return false;
     }
     $sessionId = $this->getDI()->getSession()->getId();
     if (!$sessionId) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_NO_SESSION'));
         return false;
     }
     $userinfo = self::findFirst("username = '******'");
     if (!$userinfo) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_USER_NOT_FOUND'));
         return false;
     }
     $token = new Entities\Tokens();
     $token->sessionId = $sessionId;
     $token->token = md5(uniqid(rand(), true));
     $token->userHash = $this->getRememberMeHash($userinfo);
     $token->userId = $userinfo->id;
     $token->refreshAt = time();
     $token->expiredAt = time() + $this->rememberMeTokenExpires;
     $token->save();
     $tokenString = $sessionId . '|' . $token->token . '|' . $token->userHash;
     return $tokenString;
 }