本文整理汇总了PHP中Zend\Authentication\AuthenticationService::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationService::getStorage方法的具体用法?PHP AuthenticationService::getStorage怎么用?PHP AuthenticationService::getStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Authentication\AuthenticationService
的用法示例。
在下文中一共展示了AuthenticationService::getStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(Request $req, Response $res, callable $next)
{
$res = $next($req, $res);
$identity = $this->authService->getIdentity();
if (!$identity) {
return $res;
}
try {
$user = R::findOne('user', 'mail = ?', [$identity->mail]);
if (!$user) {
$user = R::dispense('user');
$user->uid = $identity->uid;
$user->mail = $identity->mail;
$user->display_name = $identity->displayName;
$user->office_name = $identity->officeName;
$user->authentication_source = $identity->authenticationSource;
$user->password = '';
$user->created = time();
$user->role = 'school';
$this->logger->info(sprintf('User %s imported from sso.sch.gr to database', $identity->mail));
}
$user->last_login = time();
$user_id = R::store($user);
$identityClass = get_class($identity);
$newIdentity = new $identityClass($user_id, $user->uid, $user->mail, $user->display_name, $user->office_name, $user->authentication_source);
$this->authService->getStorage()->write($newIdentity);
} catch (\Exception $e) {
$this->authService->clearIdentity();
$this->flash->addMessage('danger', 'A problem occured storing user in database. <a href="%s" title="SSO logout">SSO Logout</a>');
$this->logger->error('Problem inserting user form CAS in database', $identity->toArray());
$this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
return $res->withRedirect($this->userErrorRedirectUrl);
}
return $res;
}
示例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'];
}
}
示例3: updateEmail
/**
* Updates user's email address and updates auth storage with
* updated user data
*
* @param array $user User data
* @param string $email New email address
*
* @return array User data
*/
public function updateEmail(array $user, $email)
{
$user = $this->dao->updateEmail($user['id'], $email);
$this->auth->clearIdentity();
$this->auth->getStorage()->write($user);
return $user;
}
示例4: proceed
public function proceed($userId, $tokenHash)
{
/** @var UserInterface $user */
$user = $this->userRepository->findOneBy(array('id' => new \MongoId($userId), 'tokens.hash' => $tokenHash));
if (!$user) {
throw new UserNotFoundException('User or token does not exists');
}
$this->checkAllTokens($user, $tokenHash);
$this->authenticationService->getStorage()->write($user->getId());
}
示例5: proceed
public function proceed($userId)
{
if (!($user = $this->userRepository->find($userId))) {
throw new Exception\UserNotFoundException('User cannot be found');
}
/* \Auth\Entity\Info */
$user->getInfo()->setEmailVerified(true);
$user->setEmail($user->getInfo()->getEmail());
// Set verified email as primary email.
$this->userRepository->store($user);
$this->authenticationService->getStorage()->write($user->getId());
}
示例6: __invoke
/**
*
* @param MvcAuthEvent $mvcAuthEvent
* @throws \Dws\Exception\Service\ModelNotFoundException
*/
public function __invoke(MvcAuthEvent $mvcAuthEvent)
{
// Add validated identity to ZfcUser storage
$identity = $mvcAuthEvent->getIdentity();
if ($identity instanceof AuthenticatedIdentity) {
$user = $this->userService->getUserMapper()->findById($identity->getAuthenticationIdentity()['user_id']);
if ($user) {
$this->authenticationService->getStorage()->write($user);
}
$identity->setName(implode(', ', $user->getRoles()->toArray()));
}
}
示例7: verificaAuth
/**
* verify authentication
*/
public function verificaAuth()
{
$this->identity = $this->auth->getStorage()->read();
if (!$this->auth->hasIdentity()) {
//there is no id?
$this->redirect()->toRoute('Locador/logoff');
} else {
$this->locador = $this->identity[0];
$this->layout()->locador = $this->locador;
$visitas = $this->getEm()->getRepository("MyClasses\\Entities\\Locador")->find($this->locador->getId())->getVisitas()->filter(function ($visita) {
return $visita->getStatus() == "agendada";
})->count();
$this->layout()->visitas = $visitas;
}
}
示例8: impersonateAction
/**
* @return \Zend\View\Model\ViewModel
*/
public function impersonateAction()
{
$user = $this->checkIfUserExists();
$this->auth->getStorage()->write($user);
$this->flashMessenger()->addSuccessMessage($this->translate('You have impersonated the account succesfully'));
return $this->redirect()->toRoute('users', ['controller' => 'account', 'action' => 'my-account']);
}
示例9: loginAction
public function loginAction()
{
$messages = null;
$form = new AuthForm();
$form->get('submit')->setvalue('Login');
$request = $this->getRequest();
if ($request->isPost()) {
$authFormFilters = new Auth();
$form->setInputFilter($authFormFilters->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$sm = $this->getServiceLocator();
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$config = $this->getServiceLocator()->get('Config');
$staticSalt = $config['static_salt'];
$authAdapter = new AuthAdapter($dbAdapter, 'users', 'usr_name', 'usr_password', "MD5(CONCAT('{$staticSalt}', ?, usr_password_salt)) AND usr_active = 1");
$authAdapter->setIdentity($data['usr_name'])->setCredential($data['usr_password']);
$auth = new AuthenticationService();
// or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module.
// $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
// $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called.
$result = $auth->authenticate($authAdapter);
// echo '<pre>';
// print_r($result);
// echo '</pre>';
switch ($result->getCode()) {
case Result::FAILURE_IDENTITY_NOT_FOUND:
// do stuff for nonexistent identity
break;
case Result::FAILURE_CREDENTIAL_INVALID:
// do stuff for invalid credential
break;
case Result::SUCCESS:
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(null, 'usr_password'));
$time = 1209600;
// 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
// if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
// if ($data['rememberme']) {
// $sessionManager = new \Zend\Session\SessionManager();
// $sessionManager->rememberMe($time);
// }
break;
default:
// do stuff for other failure
break;
}
foreach ($result->getMessages() as $message) {
$messages .= "{$message}\n";
}
} else {
echo '<h1> The form is NOT valid </h1>';
}
}
// echo '<pre>';
// print_r($_SESSION);
// echo '</pre>';
return new ViewModel(array('form' => $form, 'messages' => $messages));
}
示例10: addAction
public function addAction()
{
$viewModel = new ViewModel();
$form = $this->getServiceLocator()->get("Process\\Form\\ReceiveInventoryForm");
$viewModel->setVariable('form', $form);
$request = $this->getRequest();
if ($request->isPost()) {
$receiveInventory = new ReceiveInventory();
$form->setInputFilter($receiveInventory->getInputFilter());
$data = $request->getPost()->toArray();
$form->setData($data);
if ($form->isValid()) {
$fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
$fileService->setDestination($this->config['component']['receive_inventory']['file_path']);
$fileService->setSize($this->config['file_characteristics']['file']['size']);
$fileService->setExtension($this->config['file_characteristics']['file']['extension']);
$invoiceFile = $fileService->copy($this->params()->fromFiles('invoice_file'));
$data['invoice_file'] = $invoiceFile ? $invoiceFile : "";
$authenticationService = new AuthenticationService();
$user = $authenticationService->getStorage()->read()->id;
$receiveInventory->setUser($user);
$receiveInventory->exchangeArray($data);
$receiveInventoryId = $this->getReceiveInventoryTable()->save($receiveInventory);
$container = new Container('receive_inventory');
$container->id = $receiveInventoryId;
$container->user = $user;
return $this->redirect()->toRoute('process/receive_inventory/add/details');
}
}
$viewModel->setVariable('config', $this->config);
return $viewModel;
}
示例11: 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;
}
}
示例12: checkAcl
public function checkAcl(MvcEvent $e)
{
//guardamos el nombre de la ruta o recurso a permitir o denegar
$route = $e->getRouteMatch()->getMatchedRouteName();
//Instanciamos el servicio de autenticacion
$auth = new AuthenticationService();
$identi = $auth->getStorage()->read();
// Establecemos nuestro rol
// $userRole = 'admin';
// Si el usuario esta identificado le asignaremos el rol admin y si no el rol visitante.
if ($identi != false && $identi != null) {
$userRole = $identi->role;
} else {
$userRole = 'visitante';
}
/*
Esto se puede mejorar fácilmente, si tenemos un campo rol en la BD cuando el usuario
se identifique en la sesión se guardarán todos los datos del mismo, de modo que
$userRole=$identi->role;
*/
//Comprobamos si no está permitido para ese rol esa ruta
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
//Devolvemos un error 404
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $e->getRequest()->getBaseUrl() . '/404');
$response->setStatusCode(404);
}
}
示例13: 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;
}
}
}
示例14: addAction
public function addAction()
{
$viewModel = new ViewModel();
$form = $this->getServiceLocator()->get("Process\\Form\\OutputInventoryForm");
$viewModel->setVariable('form', $form);
$request = $this->getRequest();
if ($request->isPost()) {
$outputInventory = new OutputInventory();
$form->setInputFilter($outputInventory->getInputFilter());
$data = $request->getPost()->toArray();
$form->setData($data);
if ($form->isValid()) {
$authenticationService = new AuthenticationService();
$user = $authenticationService->getStorage()->read()->id;
$outputInventory->setUser($user);
$outputInventory->exchangeArray($data);
$outputInventoryId = $this->getOutputInventoryTable()->save($outputInventory);
$container = new Container('output_inventory');
$container->id = $outputInventoryId;
$container->user = $user;
return $this->redirect()->toRoute('process/output_inventory/add/details');
}
}
$viewModel->setVariable('config', $this->config);
return $viewModel;
}
示例15: get_auth
/**
* @return string 用户名字符串
* 如果没有登录,返回null
*/
public static function get_auth()
{
$auth = new AuthenticationService();
$tmp = $auth->getStorage()->read();
return $tmp;
//返回一个类,有username和schoolID和userID和type这四个在userservice里面get——auth函数里write数据库中的两列。
}