作者:JonathanConne
项目:SocialNe
public function indexAction()
{
$form = new LoginForm();
$authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['email']);
$adapter->setCredentialValue($data['password']);
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
$identity = $authResult->getIdentity();
$authService->getStorage()->write($identity);
$time = 1209600;
// 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
//- if ($data['rememberme']) $authService->getStorage()->session->getManager()->rememberMe($time); // no way to get the session
if ($data['remember-me']) {
$sessionManager = new SessionManager();
$sessionManager->rememberMe($time);
}
return $this->redirect()->toRoute('user_dashboard');
} else {
$this->flashMessenger()->addErrorMessage("Invalid login credentials provided. Try again, or sign up!");
}
}
}
$view = new ViewModel(array('form' => $form));
return $view;
}
作者:mxmz
项目:LfjOpaut
public function onBootstrap(Event $e)
{
$session = new SessionManager();
if (!$session->sessionExists()) {
$session->start();
}
}
作者:Rafael-Fonte
项目:CFP_E
public function loginAction()
{
$form = $this->getAuthForm();
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$authenticationService = $this->getAuthenticationService();
$authAdapter = $authenticationService->getAdapter();
$authAdapter->setLogin($request->getPost('email'));
$authAdapter->setSenha($request->getPost('senha'));
$resultado = $authenticationService->authenticate()->isValid();
if ($resultado) {
$authenticationService->getStorage()->write($authenticationService->getIdentity()['cliente']);
if ($request->getPost('lembrar') == 'sim') {
$tempo = 2592000000.0;
// 30 dias em milissegundos
$SessionManager = new SessionManager();
$SessionManager->rememberMe($tempo);
}
return $this->redirect()->toRoute('cliente', array('controller' => 'cliente', 'action' => 'index'));
} else {
echo "Login ou senha incorreto";
}
}
}
$viewModel = new ViewModel(['form' => $form]);
return $viewModel->setTerminal(true);
}
作者:DCONLINE198
项目:surveyengin
public function initSession($config)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
作者:petresevi
项目:tes
public function sessionStart(MvcEvent $event)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array());
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
作者:kayo-almeid
项目:cms-zen
/**
* @return void
*/
private function init()
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($this->config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
作者:blackjacked
项目:FreeMLi
public function getServiceConfig()
{
return array('factories' => array('JYLibrary\\Model\\SessionTable' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$table = new SessionTable($dbAdapter);
return $table;
}, 'Zend\\Session\\SessionManager' => function ($sm) {
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
if (isset($session['validator'])) {
$chain = $sessionManager->getValidatorChain();
foreach ($session['validator'] as $validator) {
$validator = new $validator();
$chain->attach('session.validate', array($validator, 'isValid'));
}
}
} else {
$sessionManager = new SessionManager();
/*
$adapter = new \Zend\Db\Adapter\Adapter(array(
'driver' => 'Mysqli',
'database' => 'jymobile',
'username' => 'root',
'password' => '',
'hostname'=>'localhost'
));
$tableGateway = new TableGateway('session', $adapter);
$saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);
//echo '×Ô¶¨ÒåsessionManager';
*/
}
Container::setDefaultManager($sessionManager);
return $sessionManager;
}));
}
作者:RodMin
项目:iER
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$session = new SessionManager();
$session->start();
$eventManager->attach('dispatch', array($this, 'secureSession'));
}
作者:qshuric
项目:aut
public function preDispatch(MvcEvent $event)
{
$sessionManager = new SessionManager();
$existedSessionId = $this->getSessionIfFromRequest($event->getRequest());
if ($existedSessionId) {
$sessionManager->setId($existedSessionId);
}
AuthenticationManager::getInstance()->setSessionManager($sessionManager);
}
作者:phiKreme
项目:WebDo
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sess = new SessionManager();
$sess->start();
Container::setDefaultManager($sess);
}
作者:Mendi
项目:ep3-b
/**
* Creates a new user session manager object.
*
* @param ConfigManager $configManager
* @param UserManager $userManager
* @param SessionManager $sessionManager;
*/
public function __construct(ConfigManager $configManager, UserManager $userManager, SessionManager $sessionManager)
{
$this->configManager = $configManager;
$this->userManager = $userManager;
$this->sessionManager = $sessionManager;
/* Prepare session validators */
$sessionManager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
$sessionManager->getValidatorChain()->attach('session.validate', array(new RemoteAddr(), 'isValid'));
}
作者:necromant200
项目:tt-tes
public function configure($object, array $options = [])
{
$manager = new Session\SessionManager();
$manager->setStorage(new Session\Storage\ArrayStorage());
$manager->setSaveHandler(new Session\SaveHandler\Cache(new CacheStorageAdapterMemory()));
$manager->setConfig(new Session\Config\StandardConfig());
$session = new Session\Container('Default', $manager);
$object->getServiceLocator()->set('Zend\\Session\\Container', $session);
}
作者:zealprojec
项目:zeal-sessio
public function getServiceConfig()
{
return array('factories' => array('Zend\\Session\\SessionManager' => function ($sm) {
$db = $sm->get('Zend\\Db\\Adapter\\Adapter');
$saveHandler = new SaveHandler();
$saveHandler->setDb($db);
$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);
return $manager;
}));
}
作者:pnagaraju2
项目:HtSessio
public function getSessionManager()
{
$sessionManager = new ZendSessionManager($this->getConfigObject(), $this->getStorageObject(), $this->getSessionSaveHandler());
$chain = $sessionManager->getValidatorChain();
foreach ($this->getSessionOptions()->getValidators() as $validatorName) {
$validator = $this->validatorPluginManager->get($validatorName);
$chain->attach('session.validate', array($validator, 'isValid'));
}
SessionContainer::setDefaultManager($sessionManager);
return $sessionManager;
}
作者:vatoe
项目:EOfficeZf
/**
COPY DARI SIMBRA :D
**/
public function getServiceConfig()
{
return array('factories' => array('Fauth\\Model\\User' => function ($sm) {
$adapter = $sm->get('TNDE\\DbAdapter');
$table = new UserDbTable($adapter);
return $table;
}, 'Zend\\Session\\SessionManager' => function ($sm) {
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
if (isset($session['validator'])) {
$chain = $sessionManager->getValidatorChain();
foreach ($session['validator'] as $validator) {
$validator = new $validator();
$chain->attach('session.validate', array($validator, 'isValid'));
}
}
} else {
$sessionManager = new SessionManager();
}
Container::setDefaultManager($sessionManager);
return $sessionManager;
}, 'Fauth\\sessionContainer' => function ($sm) {
$container = new Container('container');
if (!isset($container->init)) {
$session = $sm->get('Zend\\Session\\SessionManager');
$session->regenerateId(true);
$container->init = 1;
}
return $container;
}, 'Fauth\\authService' => function ($sm) {
$container = $sm->get('Fauth\\sessionContainer');
$authService = new AuthService($container);
return $authService;
}));
}
作者:rhionair
项目:myzen
public function logoutAction()
{
$auth = new AuthenticationService();
if ($auth->hasIdentity()) {
$identity = $auth->getIdentity();
$auth->clearIdentity();
$sessionManager = new SessionManager();
$sessionManager->forgetMe();
}
$this->redirect()->toRoute('backend_login');
}
作者:NguyenQuiDuon
项目:Funi
public function onBootstrap(MvcEvent $e)
{
/* @var $sm \Zend\ServiceManager\ServiceManager */
$sm = $e->getApplication()->getServiceManager();
$config = $sm->get('Config');
// bootstrap session
$tableGateway = new TableGateway($config['app']['session.tableName'], $sm->get('dbAdapter'));
$saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
// translate
$sm->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// bootstrap locale
// $headers = $app->getRequest()->getHeaders();
// Locale::setDefault($config['locale']['default']);
// if($headers->has('Accept-Language')) {
// $locales = $headers->get('Accept-Language')->getPrioritized();
// // Loop through all locales, highest priority first
// foreach($locales as $locale) {
// if(!!($match = Locale::lookup($config['locale']['supported'], $locale->typeString))) {
// // The locale is one of our supported list
// Locale::setDefault($match);
// break;
// }
// }
// if(!$match) {
// // Nothing from the supported list is a match
// Locale::setDefault($config['locale']['default']);
// }
// }
// switch layout
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
$config = $e->getApplication()->getServiceManager()->get('config');
$routeMatch = $e->getRouteMatch();
$actionName = strtolower($routeMatch->getParam('action', 'not-found'));
// get the action name
if (isset($config['module_layouts'][$moduleNamespace][$actionName])) {
$controller->layout($config['module_layouts'][$moduleNamespace][$actionName]);
} elseif (isset($config['module_layouts'][$moduleNamespace]['default'])) {
$controller->layout($config['module_layouts'][$moduleNamespace]['default']);
}
}, 100);
}
作者:arb
项目:MyCod
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$sm = $app->getServiceManager();
$request = $app->getRequest();
$response = $app->getResponse();
$appConfig = $sm->get('Configuration');
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($appConfig['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
$responseHeaders = $response->getHeaders();
$requestHeaders = $request->getHeaders();
$this->checkCloudFlareHttpHeader();
$requestUriPath = $request->getUri()->getPath();
$requestExtension = pathinfo($requestUriPath, PATHINFO_EXTENSION);
if (!in_array($requestExtension, ['js', 'css'])) {
$eventManager = $app->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sharedManager = $eventManager->getSharedManager();
$sharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) use($sm) {
$controller = $e->getTarget();
$controller->getEventManager()->attachAggregate($sm->get('Visitor'));
}, 2);
$client = new RemoteAddress();
$queryParams = $request->getQuery();
$setPartnerId = (isset($queryParams['gid']) and is_numeric($queryParams['gid'])) ? ['gid' => (int) $queryParams['gid'], 'url' => $request->getUri()] : FALSE;
$setLang = (isset($queryParams['lang']) and is_string($queryParams['lang'])) ? ['lang' => $queryParams['lang'], 'url' => $request->getUri()] : FALSE;
$setCurrency = (isset($queryParams['cur']) and is_string($queryParams['cur'])) ? ['cur' => $queryParams['cur'], 'url' => $request->getUri()] : FALSE;
if ($requestHeaders->has('Accept-Language')) {
$browserLang = $requestHeaders->get('Accept-Language')->getPrioritized();
} else {
$browserLang = FALSE;
}
if ($requestHeaders->has('User-Agent')) {
$userAgent = $requestHeaders->get('User-Agent')->getFieldValue();
} else {
$userAgent = FALSE;
}
if ($requestHeaders->has('Referer')) {
$referer = $requestHeaders->get('Referer');
} else {
$referer = FALSE;
}
$eventManager->trigger('detectVisitor', $this, array('setLang' => $setLang, 'setCurrency' => $setCurrency, 'browserLang' => $browserLang, 'userAgent' => $userAgent, 'referer' => $referer, 'request' => $request, 'clientIp' => $client->getIpAddress(), 'clientProxy' => $client->getUseProxy(), 'setPartnerId' => $setPartnerId, 'sessionManager' => $sessionManager, 'response' => $response, 'responseHeaders' => $responseHeaders, 'requestHeaders' => $requestHeaders, 'serviceLocator' => $sm));
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, array($this, 'onPreDispatch'));
}
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
GlobalAdapterFeature::setStaticAdapter($dbAdapter);
}
作者:kivagan
项目:staticus-cor
public function __invoke()
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($this->config['options']);
$sessionManager = new SessionManager($sessionConfig);
if (class_exists(\Redis::class)) {
$saveHandler = new Redis($this->config['redis']['host'], $this->config['redis']['port'], $this->config['redis']['password']);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
} else {
trigger_error('Redis extension is not found. ' . \Staticus\Auth\AuthSessionMiddleware::class . ' will not work.', E_USER_NOTICE);
}
return $sessionManager;
}
作者:sunnyc
项目:silexcmf-zend-sessio
/**
* Registers services on the given app.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Application $app
*/
public function register(Application $app)
{
$app['zend.session.handler._factory'] = $app->protect(function ($type, $options) use($app) {
switch ($type) {
case 'SilexCMF\\ZendSession\\SaveHandler\\Db':
return new Db($app[$options['connection']], new DbOptions());
case 'Zend\\Session\\SaveHandler\\MongoDB':
return new MongoDB($app['mongo'], new MongoDBOptions($options));
}
return null;
});
$app['zend.session.manager'] = $app->share(function () use($app) {
$options = isset($app['zend.session.options']) ? $app['zend.session.options'] : [];
$config = null;
if (isset($options['config'])) {
$config = new SessionConfig();
$config->setOptions($options['config']);
}
$storage = null;
if (isset($options['storage'])) {
$storage = Factory::factory($options['storage']['type'], isset($options['storage']['options']) ? $options['storage']['options'] : []);
}
$handler = null;
if (isset($options['handler'])) {
$handler = $app['zend.session.handler._factory']($options['handler']['type'], isset($options['handler']['options']) ? $options['handler']['options'] : []);
}
$manager = new SessionManager($config, $storage, $handler);
if (isset($options['validators'])) {
/* @var $request \Symfony\Component\HttpFoundation\Request */
$request = $app['request_stack']->getCurrentRequest();
foreach ($options['validators'] as $validator) {
switch ($validator) {
case 'Zend\\Session\\Validator\\HttpUserAgent':
$validator = new $validator($request->server->get('HTTP_USER_AGENT'));
break;
case 'Zend\\Session\\Validator\\RemoteAddr':
$validator = new $validator($request->server->get('REMOTE_ADDR'));
break;
default:
$validator = new $validator();
}
$manager->getValidatorChain()->attach('session.validate', array($validator, 'isValid'));
}
}
Container::setDefaultManager($manager);
return $manager;
});
}