コード例 #1
0
 protected function getDetailsForIdentity($identity)
 {
     if (array_key_exists($identity, $this->detailsCache)) {
         return $this->detailsCache[$identity];
     }
     $details = User::findFirst((int) $identity);
     $this->detailsCache[$identity] = $details;
     return $details;
 }
コード例 #2
0
 public function authenticate()
 {
     $username = $this->request->getUsername();
     $password = $this->request->getPassword();
     $session = $this->authManager->loginWithUsernamePassword(\App\Auth\UsernameAccountType::NAME, $username, $password);
     $transformer = new \App\Transformers\UserTransformer();
     $transformer->setModelClass('App\\Model\\User');
     $user = $this->createItemResponse(\App\Model\User::findFirst($session->getIdentity()), $transformer);
     $response = ['token' => $session->getToken(), 'expires' => $session->getExpirationTime(), 'user' => $user];
     return $this->createArrayResponse($response, 'data');
 }
コード例 #3
0
 public function login($data)
 {
     /** @var \Phalcon\Security $security */
     $security = Di::getDefault()->get(Services::SECURITY);
     $email = $data[Manager::LOGIN_DATA_EMAIL];
     $password = $data[Manager::LOGIN_DATA_PASSWORD];
     /** @var \App\Model\User $user */
     $user = \App\Model\User::findFirst(['conditions' => 'email = :email:', 'bind' => ['email' => $email]]);
     if (!$user) {
         return null;
     }
     if (!$security->checkHash($password, $user->password)) {
         return null;
     }
     return (string) $user->id;
 }