本文整理汇总了PHP中Zend\Authentication\AuthenticationService::setStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationService::setStorage方法的具体用法?PHP AuthenticationService::setStorage怎么用?PHP AuthenticationService::setStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Authentication\AuthenticationService
的用法示例。
在下文中一共展示了AuthenticationService::setStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
public function loginAction()
{
if ($this->authenticationService->hasIdentity()) {
return $this->redirect()->toRoute('dashboard');
}
$storage = $this->authenticationService->getStorage();
$this->authenticationService->setStorage(new NonPersistent());
$redir = $this->params()->fromQuery('redir', $this->params()->fromPost('redir'));
if ($redir !== null) {
$this->authSession->url = $redir;
return $this->redirect()->toRoute('login');
}
if ($this->getRequest()->isPost()) {
$this->authenticateForm->setData($this->getRequest()->getPost());
if ($this->authenticateForm->isValid()) {
/** @var AccountInterface $account */
$account = $this->zourceAccount();
$this->authSession->identity = $this->identity();
$this->authSession->verified = false;
$this->authenticationService->setStorage($storage);
return $this->redirectAfterLogin($account);
}
}
$this->resetTwoFactorAuthentication();
return new ViewModel(['authenticateForm' => $this->authenticateForm]);
}
示例2: validaAuth
public function validaAuth($e)
{
$sessionStorage = new SessionStorage("geframa_admin");
$authService = new AuthenticationService();
$authService->setStorage($sessionStorage);
$controller = $e->getTarget();
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
// die("<pre>" . __FILE__ . "\nLinha " . __LINE__ . "\n\n" . \Zend\Debug\Debug::dump($matchedRoute) . "</pre>");
if (!$authService->hasIdentity() and !(strpos($matchedRoute, 'geframa_login') === 0 || strpos($matchedRoute, 'layout_') === 0 || strpos($matchedRoute, 'core_') === 0)) {
// die("<pre>" . __FILE__ . "\nLinha " . __LINE__ . "\n\n" . print_r($matchedRoute, 1) . "</pre>");
return $controller->redirect()->toRoute("geframa_login");
}
/*
$sessionStorage = new SessionStorage($namespace);
$this->authService = new AuthenticationService;
$this->authService->setStorage($sessionStorage);
if ($this->getAuthService()->hasIdentity()) {
return $this->getAuthService()->getIdentity();
}
else {
return false;
}
*/
}
示例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();
}
$auth = new AuthenticationService();
$sessionStorage = new SessionStorage("Application");
$auth->setStorage($sessionStorage);
$authAdapter = $this->getServiceLocator()->get('Application\\Auth\\DoctrineAdapter');
$authAdapter->setUsername($data['email'])->setPassword($data['password']);
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$sessionStorage->write($auth->getIdentity()['user'], null);
return $this->redirect()->toRoute("Application", array('controller' => 'IndexController', 'action' => 'index'));
} else {
$error = true;
}
}
return new ViewModel(array('form' => $form, 'error' => $error));
}
示例4: validAuthAcl
public function validAuthAcl($e)
{
$storage = new SessionStorage();
$auth = new AuthenticationService();
$auth->setStorage($storage);
//pega controller e action
$controller = $e->getTarget();
$em = $controller->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
$matchedController = $controller->getEvent()->getRouteMatch()->getParam('controller');
$matchedAction = $controller->getEvent()->getRouteMatch()->getParam('action', 'index');
//user logado
if ($auth->hasIdentity()) {
$arrayUser = $auth->getIdentity();
$repository = $em->getRepository("Zf2User\\Entity\\User");
$user = $repository->findOneById($arrayUser->getId());
$role = $user->getRole()->getName();
} elseif (!$auth->hasIdentity()) {
$role = 'Visit';
}
//acl
$acl = $controller->getServiceLocator()->get("Zf2Acl\\Permissions\\Acl");
if (!$acl->isAllowed($role, $matchedController, $matchedAction)) {
$e->getResponse()->setStatusCode(Response::STATUS_CODE_404);
$e->stopPropagation();
}
}
示例5: 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();
// Criando Storage para gravar sessão da authtenticação
$sessionStorage = new SessionStorage();
$auth = new AuthenticationService();
$auth->setStorage($sessionStorage);
// Definindo o SessionStorage para a auth
$authAdapter = $this->getServiceLocator()->get("ACPLOUser\\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('acplouser-admin/default', array('controller' => 'users'));
} else {
$error = true;
}
}
}
return new ViewModel(array('form' => $form, 'error' => $error));
}
示例6: logoutAction
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage('SONUser'));
$auth->clearIdentity();
return $this->redirect()->toRoute('sonuser-auth');
}
示例7: 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');
}
}
示例8: getServiceConfig
public function getServiceConfig()
{
return array('factories' => array('Album\\Model\\AlbumTable' => function ($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
}, 'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('z_album', $dbAdapter, null, $resultSetPrototype);
}, 'Album\\Model\\MyAuthStorage' => function ($sm) {
return new \Album\Model\MyAuthStorage('Album');
}, 'AuthService' => function ($sm) {
//My assumption, you've alredy set dbAdapter
//and has users table with columns : user_name and pass_word
//that password hashed with md5
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'z_user', 'user_name', 'password', "sha(CONCAT(sha(?), '{$this->_salt}'))");
$authService = new AuthenticationService();
$authService->setAdapter($dbTableAuthAdapter);
$authService->setStorage($sm->get('Album\\Model\\MyAuthStorage'));
return $authService;
}));
}
示例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));
}
示例10: logoutAction
/**
* Logout user
*
* @return \Zend\Http\Response
*/
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage('BookstoreAdmin'));
$auth->clearIdentity();
return $this->redirect()->toRoute('bookstore-admin-auth');
}
示例11: logoutAction
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("auth_enquete"));
$auth->clearIdentity();
$this->redirect()->toRoute("auth");
}
示例12: getServiceConfig
public function getServiceConfig()
{
return array('factories' => array('Zend\\Db\\Adapter\\Adapter' => 'Zend\\Db\\Adapter\\AdapterServiceFactory', 'SanAuth\\Model\\MyAuthStorage' => function ($sm) {
return new \SanAuth\Model\MyAuthStorage('zf_tutorial');
}, 'AuthService' => function ($sm) {
$dbTableAuthAdapter = $sm->get('TableAuthService');
$authService = new AuthenticationService();
$authService->setStorage(new \Zend\Authentication\Storage\Session('Auth'));
// $authService->setStorage($sm->get('SanAuth\Model\MyAuthStorage')); //
$authService->setAdapter($dbTableAuthAdapter);
return $authService;
}, 'AuthService2' => function ($sm) {
$dbTableAuthAdapter = $sm->get('TableAuth2Service');
$authService = new AuthenticationService();
$authService->setStorage(new \Zend\Authentication\Storage\Session('Auth'));
// $authService->setStorage($sm->get('SanAuth\Model\MyAuthStorage')); //
$authService->setAdapter($dbTableAuthAdapter);
return $authService;
}, 'TableAuthService' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'ta_cliente', 'va_email', 'va_contrasena', 'SHA1(?)');
//
return $dbTableAuthAdapter;
}, 'TableAuth2Service' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'ta_cliente', 'va_email', 'va_contrasena_facebook', 'SHA1(?)');
//
return $dbTableAuthAdapter;
}));
}
示例13: validaAuth
public function validaAuth($e)
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("SONUSer"));
$controller = $e->getTarget();
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
}
示例14: getServiceConfig
public function getServiceConfig()
{
return array('factories' => array('Admin\\Model\\AdminTable' => function ($sm) {
$tableGateway = $sm->get('AdminTableGateway');
$table = new AdminTable($tableGateway);
return $table;
}, 'AdminTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Admin());
return new TableGateway('admin', $dbAdapter, null, $resultSetPrototype);
}, 'Admin\\Model\\PlayerTable' => function ($sm) {
$tableGateway = $sm->get('PlayerTableGateway');
$table = new PlayerTable($tableGateway);
return $table;
}, 'PlayerTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Player());
return new TableGateway('player', $dbAdapter, null, $resultSetPrototype);
}, 'Admin\\Model\\MyAuthStorage' => function ($sm) {
return new \Admin\Model\MyAuthStorage('adminstore');
}, 'AuthService' => function ($sm) {
//My assumption, you've alredy set dbAdapter
//and has users table with columns : user_name and pass_word
//that password hashed with md5
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'admin', 'email', 'password', 'MD5(?)');
$authService = new AuthenticationService();
$authService->setAdapter($dbTableAuthAdapter);
$authService->setStorage($sm->get('Admin\\Model\\MyAuthStorage'));
return $authService;
}));
}
示例15: logoutAction
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage('FuncSessao'));
#Definindo session storage pra auth
$auth->clearIdentity();
return $this->redirect()->toUrl('/application/auth/index');
}