当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthenticationService::getAdapter方法代码示例

本文整理汇总了PHP中Zend\Authentication\AuthenticationService::getAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationService::getAdapter方法的具体用法?PHP AuthenticationService::getAdapter怎么用?PHP AuthenticationService::getAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Authentication\AuthenticationService的用法示例。


在下文中一共展示了AuthenticationService::getAdapter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexAction

 public function indexAction()
 {
     $request = $this->getRequest();
     $user = new User();
     $this->connexionForm->bind($user);
     if ($request->isPost()) {
         $data = $request->getPost();
         $this->connexionForm->setData($data);
         if ($this->connexionForm->isValid()) {
             /** @var User $user */
             $user = $this->connexionForm->getData();
             $adapter = $this->authenticationService->getAdapter();
             $adapter->setIdentityValue($user->getUsername());
             $adapter->setCredentialValue($user->getPassword());
             $result = $this->authenticationService->authenticate();
             if ($result->isValid()) {
                 $this->flashMessenger()->addSuccessMessage($this->getTranslation('FORM_SUCCESS_LOGIN'));
                 return $this->redirect()->toRoute('admin/posts');
             }
         }
         $this->flashMessenger()->addErrorMessage($this->getTranslation('FORM_ERROR_LOGIN'));
         return $this->redirect()->toRoute('admin');
     }
     return new ViewModel(array('form' => $this->connexionForm));
 }
开发者ID:DavBfr,项目名称:BlogMVC,代码行数:25,代码来源:ConnexionController.php

示例2: login

 /**
  * @param $data
  * @return mixed
  */
 public function login($data)
 {
     /** @var ObjectRepository $adapter */
     $adapter = $this->authService->getAdapter();
     $adapter->setIdentityValue($data->login);
     $adapter->setCredentialValue($data->password);
     $result = $adapter->authenticate();
     switch ($result->getCode()) {
         case Result::SUCCESS:
             $identity = $result->getIdentity();
             $this->authService->getStorage()->write($identity);
             if (isset($data->rememberMe)) {
                 $this->sessionManager->rememberMe(1209600);
             }
             $toJson['user'] = $identity->toArray();
             $toJson['session_id'] = $this->sessionManager->getId();
             $toJson['success'] = true;
             return json_decode(json_encode($toJson));
         case Result::FAILURE_IDENTITY_NOT_FOUND:
             return ['success' => false, 'message' => 'User not found.'];
         case Result::FAILURE_CREDENTIAL_INVALID:
             return ['success' => false, 'message' => 'Invalid password'];
         default:
             return ['success' => false, 'message' => 'Error while login'];
     }
 }
开发者ID:sauron07,项目名称:rest_helper,代码行数:30,代码来源:UserService.php

示例3: authenticateAction

 public function authenticateAction()
 {
     if ($this->identity()) {
         return $this->redirect()->toRoute($this->routes['redirect']['name'], $this->routes['redirect']['params'], $this->routes['redirect']['options'], $this->routes['redirect']['reuseMatchedParams']);
     }
     $form = new SigninForm();
     $form->setAttribute('action', $this->url()->fromRoute($this->routes['authenticate']['name'], $this->routes['authenticate']['params'], $this->routes['authenticate']['options'], $this->routes['authenticate']['reuseMatchedParams']));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         $form->setData($post);
         if ($form->isValid()) {
             $authAdapter = $this->authenticationService->getAdapter();
             $authAdapter->setIdentityValue($form->get('username')->getValue());
             $authAdapter->setCredentialValue(sha1(sha1($form->get('password')->getValue())));
             $authResult = $this->authenticationService->authenticate();
             if ($authResult->isValid()) {
                 $identity = $authResult->getIdentity();
                 $authStorage = $this->authenticationService->getStorage();
                 if ($form->get('remember-me')->getValue() == 1) {
                     $authStorage->setRememberMe(1);
                 }
                 $authStorage->write($identity);
                 $this->flashMessenger()->addSuccessMessage(_('Sign in with success!'));
                 return $this->redirect()->toRoute($this->routes['redirect']['name'], $this->routes['redirect']['params'], $this->routes['redirect']['options'], $this->routes['redirect']['reuseMatchedParams']);
             } else {
                 $this->flashMessenger()->addErrorMessage(_('Username or password is invalid.'));
             }
         }
     }
     return $this->redirect()->toRoute($this->routes['signin']['name'], $this->routes['signin']['params'], $this->routes['signin']['options'], $this->routes['signin']['reuseMatchedParams']);
 }
开发者ID:zetta-code,项目名称:tss-authentication,代码行数:32,代码来源:AuthController.php

示例4: __construct

 public function __construct(AuthenticationService $authService)
 {
     parent::__construct('login');
     $this->filter = new InputFilter();
     $email = new Element\Email('email');
     $email->setAttribute('required', true);
     $email->setAttribute('placeholder', 'Email Address');
     $this->add($email);
     $emailFilter = new Input('email');
     $emailFilter->setRequired(true);
     $this->filter->add($emailFilter);
     $password = new Element\Password('password');
     $password->setAttribute('required', true);
     $password->setAttribute('placeholder', 'Password');
     $this->add($password);
     $passwordFilter = new Input('password');
     $passwordFilter->setRequired(true);
     $passwordFilter->getValidatorChain()->attach(new AuthValidator\Authentication(array('message' => 'Invalid email address or password', 'service' => $authService, 'adapter' => $authService->getAdapter(), 'identity' => 'email', 'credential' => 'password')));
     $this->filter->add($passwordFilter);
     $buttons = new Form('buttons');
     $buttons->setOption('twb-layout', 'inline');
     $buttons->setAttribute('class', 'form-group');
     $submit = new Element\Submit('submit');
     $submit->setAttribute('class', 'btn-primary pull-right');
     $submit->setOption('glyphicon', 'log-in');
     $submit->setLabel('Log In');
     $buttons->add($submit);
     $forgot = new Element\Submit('forgot');
     $forgot->setAttribute('formnovalidate', true);
     $forgot->setAttribute('class', 'btn-warning pull-right');
     $forgot->setOption('glyphicon', 'question-sign');
     $forgot->setLabel('Forgot Password');
     $buttons->add($forgot);
     $this->add($buttons);
 }
开发者ID:PoetikDragon,项目名称:USCSS,代码行数:35,代码来源:Login.php

示例5: onKernelRequest

 /**
  * Handle authentication
  *
  * @param  GetResponseEvent $event
  * @throws RuntimeException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->isRequestNeedProcessing($request) || $this->authentication->hasIdentity()) {
         return;
     }
     /* @var $adapter \SilexCMF\ZendAuthentication\Adapter\Http\HttpBasedAdapter */
     $adapter = $this->authentication->getAdapter();
     if (!$adapter || !$adapter instanceof HttpBasedAdapter) {
         throw new RuntimeException(sprintf('Unsupported adapter type %s', is_object($adapter) ? get_class($adapter) : gettype($adapter)));
     }
     $result = $this->authentication->authenticate();
     if (!$result->isValid()) {
         $event->setResponse($adapter->getResponse());
     }
 }
开发者ID:sunnyct,项目名称:silexcmf-zend-authentication,代码行数:22,代码来源:HttpListener.php

示例6: loginAction

 public function loginAction()
 {
     if ($this->authenticationService->hasIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $this->layout('layout/layout-blank');
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         $jsonData = $this->getRequest()->getPost('login');
         $data = Json::decode($jsonData, Json::TYPE_ARRAY);
         // If you used another name for the authentication service, change it here
         $adapter = $this->authenticationService->getAdapter();
         $adapter->setIdentityValue($data['username']);
         $adapter->setCredentialValue($data['password']);
         $authResult = $this->authenticationService->authenticate();
         //@todo remember me
         if ($authResult->isValid()) {
             if ($data['rememberMe']) {
                 $this->authenticationService->getStorage()->getManager()->rememberMe(36000);
             }
             return $resultModel;
         } else {
             $resultModel->addErrors('password', '登录名或密码错误');
             return $resultModel;
         }
     }
 }
开发者ID:phox,项目名称:xsale,代码行数:27,代码来源:AccountController.php

示例7: __invoke

 public function __invoke(Request $req, Response $res)
 {
     if ($req->isPost()) {
         $adapter = $this->authService->getAdapter();
         if ($adapter instanceof ValidatableAdapterInterface) {
             $adapter->setIdentity($req->getParam('identity'));
             $adapter->setCredential($req->getParam('credential'));
         }
         $result = $this->authService->authenticate($adapter);
         if (!$result->isValid()) {
             $this->flash->addMessage('danger', reset($result->getMessages()));
             return $res->withRedirect($req->getUri());
         }
         return $res->withRedirect($this->successUrl);
     }
     return $this->view->render($res, 'user/login.twig', []);
 }
开发者ID:kanellov,项目名称:gredu_labs,代码行数:17,代码来源:Login.php

示例8: authentificate

 /**
  * Authentificate user by username/password pair
  *
  * @param string $username
  * @param string $password
  * @param boolean $remember
  * @return \Zend\Authentication\Result
  * @throws \Exception
  */
 public function authentificate($username, $password, $remember = false)
 {
     $adapter = $this->authService->getAdapter();
     if (!$adapter instanceof \Zend\Authentication\Adapter\DbTable) {
         throw new \Exception('invalid auth adapter type');
     }
     $adapter->setIdentity($username)->setCredential($password);
     $result = $this->authService->authenticate();
     if ($result->getCode() == \Zend\Authentication\Result::SUCCESS) {
         if ($remember) {
             $this->sessionContainer->getManager()->rememberMe();
         }
         $this->sessionContainer->userEntity = (array) $adapter->getResultRowObject();
     } else {
         $this->sessionContainer->userEntity = null;
     }
     return $result;
 }
开发者ID:ponchov,项目名称:teeforall,代码行数:27,代码来源:AuthService.php

示例9: isValid

 /**
  * Test if authentication is valid
  * 
  * @see \Zend\Validator\ValidatorInterface::isValid()
  * @param mixed $value
  * @param array $context
  * @return boolean
  */
 public function isValid($value, array $context = null)
 {
     $context = (array) $context;
     if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
         //             $this->error(self::IDENTITY_EMPTY);
         return false;
     }
     if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
         //             $this->error(self::CREDENTIAL_EMPTY);
         return false;
     }
     $authAdapter = $this->auth->getAdapter();
     $authAdapter->setIdentity($context[$this->identity]);
     $authAdapter->setCredential($context[$this->credential]);
     $result = $this->authResult = $this->auth->authenticate();
     if (!$result->isValid()) {
         $this->error($result->getCode());
         return false;
     }
     return true;
 }
开发者ID:sporkcode,项目名称:spork,代码行数:29,代码来源:AuthAdapter.php

示例10: authenticate

 /**
  * authenticate
  *
  * Perform the authentication.
  *
  * @param  mixed  $data  The authentication data.
  *
  * @return boolean
  *
  * @throws \InvalidArgumentException  If $data is not an array.
  */
 public function authenticate($data)
 {
     if (!is_array($data)) {
         throw new \InvalidArgumentException(sprintf('The \'data\' argument must be of type \'array\'; \'%s\' given in \'%s\'.', gettype($data), __METHOD__));
     }
     $eventManager = $this->getEventManager();
     /** @var AuthenticationEvent $event */
     $event = $this->getEvent();
     $event->setName(AuthenticationEvent::EVENT_PREPARE)->setAdapter($this->auth->getAdapter())->setStorage($this->auth->getStorage())->setParams($data);
     // trigger authentication 'prepare' event
     $eventManager->trigger($event);
     // trigger the authentication event
     $event->setName(AuthenticationEvent::EVENT_AUTHENTICATE);
     $eventManager->trigger($event);
     if ($this->hasIdentity()) {
         $event->setName(AuthenticationEvent::EVENT_SUCCESS);
         $eventManager->trigger($event);
         return true;
     }
     $event->setName(AuthenticationEvent::EVENT_FAILURE);
     $eventManager->trigger($event);
     return false;
 }
开发者ID:alex-patterson-webdev,项目名称:arp-auth,代码行数:34,代码来源:AuthenticationService.php

示例11: authenticateUser

 public static function authenticateUser($user, $pass, AuthenticationService $authService)
 {
     $authService->getAdapter()->setIdentity($user)->setCredential($pass);
     $result = $authService->authenticate();
     return $result;
 }
开发者ID:rodrigogk87,项目名称:djme,代码行数:6,代码来源:UserUtils.php

示例12: authenticate

 /**
  * Authenticates user
  *
  * @param  string                                         $email    User email
  * @param  string                                         $password User password
  * @return Zend\Authentication\Result
  * @throws Zend\Authentication\Exception\RuntimeException
  */
 public function authenticate($email, $password)
 {
     $adapter = $this->auth->getAdapter();
     $adapter->setCredentials($email, $password);
     return $this->auth->authenticate();
 }
开发者ID:neophyt3,项目名称:flaming-archer,代码行数:14,代码来源:UserService.php


注:本文中的Zend\Authentication\AuthenticationService::getAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。