作者:spoore
项目:hangma
public function createService(ServiceLocatorInterface $serviceLocator)
{
$adapter = $serviceLocator->get('auth-adapter');
$auth = new AuthenticationService();
$auth->setAdapter($adapter);
return $auth;
}
作者:kalel
项目:inventor
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;
}
}
作者:phtfa
项目:gefram
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("geframa_admin"));
$auth->clearIdentity();
return $this->redirect()->toRoute('geframa_login');
}
作者:argentinalui
项目:Learning-ZF
/**
* 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');
}
作者:pengtt011
项目:CotestWeb
/**
* @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数据库中的两列。
}
作者:feijoj
项目:EADGesta
public function validaAuth($e)
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("SONUSer"));
$controller = $e->getTarget();
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
}
作者:kalel
项目:inventor
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;
}
作者:anillaogi01
项目:zend-admi
public function indexAction()
{
/* $temp = $this->forward()->dispatch('Application/Controller/Album', array('action' => 'index'));
echo '<pre>'; print_r($temp); echo '<pre>';die; */
$auth = new AuthenticationService();
if (!$auth->hasIdentity()) {
return $this->redirect()->toRoute('home');
}
$select = new Select();
$search = @$_REQUEST['search'];
if (!empty($search)) {
$select->where->like('name', '%' . $search . '%');
}
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'id';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : Select::ORDER_ASCENDING;
$page = $this->params()->fromRoute('page') ? (int) $this->params()->fromRoute('page') : 1;
$category = $this->getCategoryTable()->fetchAllCategory($select->order($order_by . ' ' . $order), $search);
$itemPerPage = 2;
$category->current();
$paginator = new Paginator(new PaginatorIterator($category));
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($itemPerPage);
$paginator->setPageRange(10);
return new ViewModel(array('order_by' => $order_by, 'order' => $order, 'page' => $page, 'paginator' => $paginator));
}
作者:patking
项目:ejemploZF
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);
}
}
作者:PoetikDrago
项目:USCS
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);
}
作者:neuwe
项目:idaut
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;
}
作者:abelclope
项目:ZF2-Intermediario-com-ac
public function logoutAction()
{
$auth = new AuthenticationService();
//$auth->setStorage(new SessionStorage("ACPLOUser"));
$auth->clearIdentity();
return $this->redirect()->toRoute('acplouser-auth');
}
作者:bix0
项目:Stjornvis
public function dispatch(MvcEvent $event)
{
$request = $event->getRequest();
if ($request instanceof ConsoleRequest) {
return true;
}
$auth = new AuthenticationService();
//ALREADY LOGGED IN
// user has auth,
if ($auth->hasIdentity()) {
return true;
//NOT LOGGED IN
//
} else {
/** @var $request \Zend\Http\PhpEnvironment\Request */
$cookies = $request->getCookie();
/** @var $cookies \Zend\Http\Header\Cookie */
$userService = $this->getServiceLocator()->get('Stjornvisi\\Service\\User');
/** @var $user \Stjornvisi\Service\User */
if ($cookies && $cookies->offsetExists('backpfeifengesicht')) {
if (($user = $userService->getByHash($cookies->offsetGet('backpfeifengesicht'))) != false) {
$authAdapter = $this->getServiceLocator()->get('Stjornvisi\\Auth\\Adapter');
$authAdapter->setIdentifier($user->id);
$result = $auth->authenticate($authAdapter);
$result->isValid();
}
}
}
}
作者:creativewil
项目:TS3U
public function createService(ServiceLocatorInterface $serviceLocator)
{
$authAdapter = $serviceLocator->get("TSCore\\Auth\\Adapter");
$auth = new AuthenticationService();
$auth->setAdapter($authAdapter);
return $auth;
}
作者:felipe107
项目:testeXy
public function logoutAction()
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("auth_enquete"));
$auth->clearIdentity();
$this->redirect()->toRoute("auth");
}
作者:AgnaldoJaw
项目:CredentialFace
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));
}
作者:kevcas
项目:lsrefactorin
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;
}));
}
作者:kokoa
项目:Projet_zend_IU
public function membreAction()
{
$return = null;
$identifiantMembre = (int) $this->params()->fromRoute('id', 0);
$auth = new AuthenticationService();
$logged = null;
if ($auth->hasIdentity()) {
$session = new Container('user');
$logged = $session->offsetGet('id');
}
$like = array();
$images = $this->getImageTable()->fetchAllById($identifiantMembre);
if ($logged != null) {
foreach ($images as $image) {
$isLike = $this->getLikeTable()->fetchCorrespondance($logged, $image->id);
foreach ($isLike as $isLikeTest) {
if ($isLikeTest->id != null) {
array_push($like, 'FALSE');
} else {
array_push($like, 'TRUE');
}
}
}
}
return new ViewModel(array('images' => $this->getImageTable()->fetchAllById($identifiantMembre), 'user' => $this->getUserTable()->getUser($identifiantMembre), 'like' => $like));
}
作者:victoryno
项目:Test
/**
* @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);
}
}
作者:binnguye
项目:kaffacoffe
public function logoutAction()
{
Utility::insertHistory('logout');
$auth = new AuthenticationService();
$auth->clearIdentity();
$this->redirect()->toRoute('admin/child', array('controller' => 'login'));
}