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


PHP AuthenticationService::authenticate方法代码示例

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


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

 public function testCanAuthenticateWithGoodCredentials()
 {
     $authAdapter = Bootstrap::getServiceManager()->get('ZfSimpleAuth\\Authentication\\Adapter');
     $authAdapter->setIdentity('demo-admin');
     $authAdapter->setCredential('foobar');
     $result = $this->authenticationService->authenticate($authAdapter);
     $this->assertTrue($result->isValid());
     $identity = $this->authenticationService->getIdentity();
     $this->assertInstanceOf('\\ZfSimpleAuth\\Authentication\\Identity', $identity);
     /* @var \ZfSimpleAuth\Authentication\Identity $identity */
     $this->assertEquals('demo-admin', $identity->getName());
     $this->assertEquals(array('admin', 'member'), $identity->getRoles());
 }
开发者ID:devdragons,项目名称:zf-simple-auth,代码行数:13,代码来源:AuthenticationTest.php

示例3: indexAction

 public function indexAction()
 {
     $form = new LoginForm();
     $error = FALSE;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             $sessionStorage = new SessionStorage("EOSUser");
             //Storage para guardar sessão de autenticação
             $auth = new AuthenticationService();
             $auth->setStorage($sessionStorage);
             //define sessionStorage para Auth
             $authAdapter = $this->getServiceLocator()->get('EOSUser\\Auth\\Adapter');
             $authAdapter->setUsername($data['email']);
             $authAdapter->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $user = $auth->getIdentity();
                 $user = $user['user'];
                 $sessionStorage->write($user, null);
                 //                    $sessionStorage->write($auth->getIdentity()['user'], NULL);
                 return $this->redirect()->toRoute('eosuser-admin/default', array('controller' => 'users'));
             } else {
                 $error = TRUE;
             }
         }
     }
     return new ViewModel(array('form' => $form, 'error' => $error));
 }
开发者ID:EnnioSimoes,项目名称:Base-ZF2-Doctrine,代码行数:31,代码来源:AuthController.php

示例4: indexAction

 public function indexAction()
 {
     try {
         $request = $this->getRequest();
         if ($request->isPost()) {
             $data = $request->getPost();
             $auth = new AuthenticationService();
             $sessionStorage = new SessionStorage();
             $auth->setStorage($sessionStorage);
             $authAdapter = $this->getServiceLocator()->get('Application\\Model\\Adapter');
             $authAdapter->setName($data['userName']);
             $authAdapter->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             $user = $result->getIdentity()['user'];
             if ($result->isValid()) {
                 $this->session = new Container('App_Auth');
                 $this->session->user = $result->getIdentity()['user'];
                 $this->session->selectedPill = 1;
                 return $this->redirect()->toUrl('/home');
             } else {
                 return $this->errorMessage('Usuário ou senha inválidos', '/login');
             }
         } else {
             if ($this->isLogged()) {
                 return $this->redirect()->toUrl('/home');
             }
             return array();
         }
     } catch (\Exception $e) {
         return $this->errorMessage('Não foi possível realizar o login', '/login');
     }
 }
开发者ID:MarceloPilatti,项目名称:oficinaderecreacao-site-zend,代码行数:32,代码来源:AuthController.php

示例5: authenticate

 public function authenticate(AdapterInterface $adapter = null)
 {
     if (!$adapter) {
         if (!($adapter = $this->getAdapter())) {
             throw new \Exception('An adapter must be set or passed prior to calling authenticate()');
         }
     }
     if ($this->hasIdentity()) {
         $identity = $this->getIdentity();
         // if some of fields is empty, put '.' - otherwise DbTable will return a RuntimeException
         if (!isset($identity[$this->getIdentityColumn('login')])) {
             $identity[$this->getIdentityColumn('login')] = '.';
         }
         if (!isset($identity[$this->getIdentityColumn('password')])) {
             $identity[$this->getIdentityColumn('password')] = '.';
         }
         if (!isset($identity['signature'])) {
             $identity['signature'] = '.';
         }
         if (!isset($identity['timeout'])) {
             $identity['timeout'] = '.';
         }
         $adapter->setFirstLogin(false);
         $adapter->setIdentity($identity[$this->getIdentityColumn('login')]);
         $adapter->setCredential($identity[$this->getIdentityColumn('password')]);
         $adapter->setSessionFingerprinting($identity['signature']);
         $adapter->setSessionLimit($identity['timeout']);
     }
     $result = parent::authenticate($adapter);
     if (Result::SUCCESS == $result->getCode() && ($this->regenerateId || time() % 2 == 0)) {
         session_regenerate_id(true);
     }
     return $result;
 }
开发者ID:elthu,项目名称:MARTINS_CORDIER,代码行数:34,代码来源:AuthenticationService.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: authenticate

 public function authenticate($username, $password)
 {
     $callback = function ($password, $hash) {
         $bcrypt = new Bcrypt();
         return $bcrypt->verify($hash, $password);
     };
     $authenticationService = new AuthenticationService();
     $callbackCheckAdapter = new CallbackCheckAdapter($this->dbAdapter, "users", 'username', 'password', $callback);
     $callbackCheckAdapter->setIdentity($username)->setCredential($password);
     $authenticationService->setAdapter($callbackCheckAdapter);
     $authResult = $authenticationService->authenticate();
     if ($authResult->isValid()) {
         $userObject = $callbackCheckAdapter->getResultRowObject();
         $authenticationService->getStorage()->write($userObject);
         if ($userObject->status == 0) {
             $authenticationService->clearIdentity();
             $this->setCode(-5);
             return false;
         } else {
             return true;
         }
     } else {
         $this->setCode($authResult->getCode());
         return false;
     }
 }
开发者ID:kalelc,项目名称:inventory,代码行数:26,代码来源:AuthSessionAdapter.php

示例8: __invoke

 /**
  * @param Request $request
  * @param Response $response
  * @param callable $next
  * @return \Psr\Http\Message\MessageInterface|HtmlResponse
  * @throws Exception
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     //$form = new LoginForm('Login', []);
     //$form->get('submit')->setValue('Login');
     if ($request->getMethod() == 'POST') {
         $auth = new AuthenticationService();
         $query = $request->getParsedBody();
         $authAdapter = new AuthAdapter($query['login'], $query['password'], $this->authConfig);
         $result = $auth->authenticate($authAdapter);
         if (!$result->isValid()) {
             //$response->getBody()->write("Not valid authentication\n");
             //return $response->withStatus(403)->withHeader("Content-type", 'text/html');
             throw new Exception("Not valid authentication\n", 403);
         } else {
             if ($request->getUri()->getPath() === '/auth') {
                 $render = $this->template->render('app::homepage');
                 $query = $request->getParsedBody();
                 $query['view']['render'] = $render;
                 $query['view']['code'] = 200;
                 $request = $request->withParsedBody($query);
             }
             return $next($request, $response);
         }
     } else {
         $render = $this->template->render('app::login', ['error' => null]);
         $query = $request->getParsedBody();
         $query['view']['render'] = $render;
         $query['view']['code'] = 200;
         $request = $request->withParsedBody($query);
         return $next($request, $response);
     }
 }
开发者ID:victorynox,项目名称:TestR,代码行数:39,代码来源:AuthenticationMiddleware.php

示例9: loginAction

 public function loginAction()
 {
     $messages = null;
     $isAuth = false;
     $form = new LoginForm();
     $auth = new AuthenticationService();
     $sessionStorage = new SessionStorage("Login");
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost()->toArray();
         $form->setData($data);
         if ($form->isValid()) {
             $auth->setStorage($sessionStorage);
             $authAdapter = $this->getPluginManager()->getServiceLocator()->get('VMBLogin\\Auth\\Adapter');
             $authAdapter->setUsername($data['username'])->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 $messages = "you are now authenticated";
                 $isAuth = true;
             } else {
                 $messages = "username or password is incorrect";
             }
         }
     }
     return new ViewModel(array('form' => $form, 'messages' => $messages, 'auth' => $isAuth));
 }
开发者ID:vitorbarros,项目名称:vmb-zf2-module-login,代码行数:27,代码来源:LoginController.php

示例10: authenticate

 public function authenticate(array $credentials)
 {
     $username = $credentials['username'];
     $password = $credentials['password'];
     $dbAdapter = $this->serviceManager->get('Zend\\Db\\Adapter\\Adapter');
     $dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'users', 'username', 'password', 'MD5(?)');
     $dbTableAuthAdapter->setIdentity($username);
     $dbTableAuthAdapter->setCredential($password);
     $authService = new AuthenticationService();
     $authService->setAdapter($dbTableAuthAdapter);
     //$authService->setStorage($this->getServiceManager()->get('IdAuth\Storage'));
     $authResult = $authService->authenticate();
     $result = new ProviderResult();
     $result->setAuthCode($authResult->getCode());
     $result->setMessages($authResult->getMessages());
     $result->setValid($authResult->isValid());
     $result->setName('IdAuth\\Providers\\DbTable');
     $config = $this->serviceManager->get('Config');
     $options = $config['idAuth']['providerOptions']['DbTable'];
     $result->setOptions($options);
     if ($authResult->isValid()) {
         $result->setIdentity($this->queryIdentity($username));
     }
     return $result;
 }
开发者ID:neuweb,项目名称:idauth,代码行数:25,代码来源:DbTableProvider.php

示例11: 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

示例12: indexAction

 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function indexAction()
 {
     $form = new LoginForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             $authAdapter = $this->getServiceLocator()->get('SONUser\\Auth\\Adapter');
             $authAdapter->setUsername($data['email']);
             $authAdapter->setPassword($data['password']);
             $auth = new AuthenticationService();
             $sessionStorage = new SessionStorage('SONUser');
             $auth->setStorage($sessionStorage);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 return $this->redirect()->toRoute('sonuser-admin/default', array('controller' => 'users'));
             } else {
                 $this->error = true;
             }
         }
     }
     return new ViewModel(array('form' => $form, 'error' => $this->error));
 }
开发者ID:Tortinhex,项目名称:son-zf2-inter,代码行数:28,代码来源:AuthController.php

示例13: indexAction

 public function indexAction()
 {
     $form = new LoginForm('login');
     $error = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             // Criando Storage para gravar sessão da authtenticação
             $sessionStorage = new SessionStorage("geframa_admin");
             $auth = new AuthenticationService();
             $auth->setStorage($sessionStorage);
             // Definindo o SessionStorage para a auth
             $authAdapter = $this->getServiceLocator()->get("Admin\\Auth\\Adapter");
             $authAdapter->setUsername($data['email']);
             $authAdapter->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 /*
                                     $user = $auth->getIdentity();
                                     $user = $user['user'];
                                     $sessionStorage->write($user,null);
                 */
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 return $this->redirect()->toRoute('geframa_admin', array('controller' => 'users'));
             } else {
                 $error = true;
             }
         }
     }
     $view = new ViewModel(array('form' => $form, 'error' => $error));
     $view->setTerminal(true);
     return $view;
 }
开发者ID:phtfao,项目名称:geframa,代码行数:35,代码来源:LoginController.php

示例14: indexAction

 /**
  * Login User
  *
  * @return \Zend\Http\Response|ViewModel
  */
 public function indexAction()
 {
     $form = new FormLogin();
     $error = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             $auth = new AuthenticationService();
             $sessionStorage = new SessionStorage('BookstoreAdmin');
             $auth->setStorage($sessionStorage);
             $authAdapter = $this->getServiceLocator()->get('Bookstore\\Auth\\Adapter');
             $authAdapter->setUsername($data['email'])->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 return $this->redirect()->toRoute('home-admin', ['controller' => 'categories']);
             } else {
                 $error = true;
             }
         }
     }
     return new ViewModel(['form' => $form, 'error' => $error]);
 }
开发者ID:argentinaluiz,项目名称:Learning-ZF2,代码行数:30,代码来源:AuthController.php

示例15: indexAction

 public function indexAction()
 {
     $this->layout('layout/layoutLogin');
     $request = $this->getRequest();
     $form = new LoginForm();
     if ($request->isPost()) {
         $form->setData($request->getPost()->toArray());
         if ($form->isValid()) {
             $post = $request->getPost()->toArray();
             #Criando storage para gravar sessão de authenticacação
             $sessionStorage = new SessionStorage('FuncSessao');
             $auth = new AuthenticationService();
             $auth->setStorage($sessionStorage);
             #Definindo session storage pra auth
             $authAdapter = $this->getServiceLocator()->get('Application\\Auth\\Adapter');
             $authAdapter->setUsername($post['usuarioFunc']);
             $authAdapter->setPassword($post['senhaFunc']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $sessionStorage->write($auth->getIdentity()['funcionarioUser']);
                 return $this->redirect()->toUrl('/application/index/index');
             } else {
                 var_dump("ERROR");
                 $error = true;
             }
         }
     }
     $view = new ViewModel();
     $view->setVariable('form', $form);
     return $view;
 }
开发者ID:projetopim2015job,项目名称:homologacao,代码行数:31,代码来源:AuthController.php


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