Exemplo n.º 1
0
 public function getServiceConfig()
 {
     return array('abstract_factories' => array('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Log\\LoggerAbstractServiceFactory'), 'factories' => array('translator' => 'Zend\\Mvc\\Service\\TranslatorServiceFactory', 'Application\\SessionManager' => function ($sm) {
         $config = $sm->get('Config');
         if (isset($config['session'])) {
             $session = $config['session'];
             $sessionConfig = null;
             if (isset($session)) {
                 $sessionConfig = new \Zend\Session\Config\SessionConfig();
                 $sessionConfig->setOptions($session);
             }
             $storagePath = '';
             if (isset($config['app_base_dir'])) {
                 $storagePath = $config['app_base_dir'] . DIRECTORY_SEPARATOR;
             }
             $storagePath .= '/data/sessions/cache';
             $fileCacheStorage = new \Zend\Cache\Storage\Adapter\FileSystem(['cache_dir' => $storagePath]);
             $sessionSaveHandler = new \Zend\Session\SaveHandler\Cache($fileCacheStorage);
             $sessionManager = new \Zend\Session\SessionManager($sessionConfig, null, $sessionSaveHandler);
             if (isset($session['validators'])) {
                 $chain = $sessionManager->getValidatorChain();
                 foreach ($session['validators'] as $validator) {
                     $validator = new $validator();
                     $chain->attach('session.validate', array($validator, 'isValid'));
                 }
             }
         } else {
             $sessionManager = new \Zend\Session\SessionManager();
         }
         \Zend\Session\Container::setDefaultManager($sessionManager);
         return $sessionManager;
     }));
 }
 public function signUp($email, $password, $fullName, $oAuth2Client = null)
 {
     $user = $this->createUser($email, $password, $fullName);
     $adapter = $this->authenticationService->getAdapter();
     $adapter->setIdentityValue($user->getEmail());
     $adapter->setCredentialValue($password);
     $authenticationResult = $this->authenticationService->authenticate();
     if ($authenticationResult->isValid()) {
         $identity = $authenticationResult->getIdentity();
         $this->authenticationService->getStorage()->write($identity);
         // if ($this->params()->fromPost('rememberMe')) {
         $time = 1209600;
         // 14 days (1209600/3600 = 336 hours => 336/24 = 14 days)
         $sessionManager = new \Zend\Session\SessionManager();
         $sessionManager->rememberMe($time);
         // }
         return true;
         // redirect using cookie
         // if(isset($cookie->requestedUri)) {
         //     $requestedUri = $cookie->requestedUri;
         //     $redirectUri = $this->getRequest()->getUri()->getScheme() . '://' . $this->getRequest()->getUri()->getHost() . $requestedUri;
         //     return $this->redirect()->toUrl($redirectUri);
         // }
         // $this->getLogger()->log(\Zend\Log\Logger::INFO, 'Signed up', ['user' => $this->identity()]);
         // $this->flashMessenger()->addInfoMessage('We just sent you an email asking you to confirm your registration. Please search for fryday@fryady.net in your inbox and click on the "Confirm my registration" button');
         // $redirectRoute = $this->options->getSignUpRedirectRoute();
         // return $this->redirect()->toRoute($redirectRoute);
     }
     return false;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $request = $serviceLocator->get('request');
     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['savehandler'])) {
             /**
              * getting session save handler from service manager,
              * session save handler service name is configured on global config
              */
             $sessionSaveHandler = $serviceLocator->get($session['savehandler']['database']['savehandler']);
         }
         $sessionManager = new \Zend\Session\SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
         $sessionManager->start();
         $metaData = $sessionManager->getStorage()->getMetadata();
         if (empty($sessionManager->getStorage()->getMetadata('_VALID'))) {
             if (isset($config['session']['validators'])) {
                 $chain = $sessionManager->getValidatorChain();
                 foreach ($config['session']['validators'] as $validator) {
                     switch ($validator) {
                         case 'Zend\\Session\\Validator\\HttpUserAgent':
                             $validator = new $validator($request->getServer()->get('HTTP_USER_AGENT'));
                             break;
                         case 'Zend\\Session\\Validator\\RemoteAddr':
                             $validator = new $validator($request->getServer()->get('REMOTE_ADDR'));
                             break;
                         default:
                             $validator = new $validator();
                     }
                     $chain->attach('session.validate', array($validator, 'isValid'));
                 }
             }
         } else {
         }
     } else {
         $sessionManager = new \Zend\Session\SessionManager();
     }
     \Zend\Session\Container::setDefaultManager($sessionManager);
     $sessionManager->start();
     return $sessionManager;
 }
Exemplo n.º 4
0
 public function logoutAction()
 {
     $auth = new AuthenticationService();
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
     }
     $auth->clearIdentity();
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     return $this->redirect()->toRoute('myauth', array('controller' => 'index', 'action' => 'login'));
 }
Exemplo n.º 5
0
 public function logoutAction()
 {
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
     }
     $auth->clearIdentity();
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     return $this->redirect()->toRoute('home/login');
 }
 public function logoutAction()
 {
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     // @todo Set up the auth adapter, $authAdapter
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
     }
     $auth->clearIdentity();
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     return $this->redirect()->toRoute($this->getOptions()->getLogoutRedirectRoute());
 }
Exemplo n.º 7
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $session = new \Zend\Session\SessionManager();
     $session->start();
     $container = new Container('initialized');
     if (!isset($container->init)) {
         $session->regenerateId(true);
         $container->init = 1;
         $container->userId = 0;
     }
     return $session;
 }
Exemplo n.º 8
0
 public function logoutAction()
 {
     $authService = $this->_get_auth_service();
     if ($authService->hasIdentity()) {
         // Identity exists; get it
         $identity = $authService->getIdentity();
     }
     $authService->clearIdentity();
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     return $this->redirect()->toRoute('home');
 }
 public function setUp()
 {
     $_SESSION = array();
     \Zend\Session\Container::setDefaultManager(null);
     $config = new \Zend\Session\Config\StandardConfig(array('storage' => 'Zend\\Session\\Storage\\ArrayStorage'));
     $sessionManager = new \Zend\Session\SessionManager($config);
     $sessionManager->start();
     \Zend\Session\Container::setDefaultManager($sessionManager);
     self::$manager = $sessionManager;
     $services = bootstrap::getServiceManager();
     $this->context = $services->get('NetgluePrismic\\Context');
 }
Exemplo n.º 10
0
 public function logoutAction()
 {
     $auth = new AuthenticationService();
     // or prepare in the globa.config.php and get it from there
     // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
     }
     $auth->clearIdentity();
     //		$auth->getStorage()->session->getManager()->forgetMe(); // no way to get the sessionmanager from storage
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     return $this->redirect()->toRoute('auth/default', array('controller' => 'index', 'action' => 'login'));
 }
Exemplo n.º 11
0
 public function init($sid = '')
 {
     try {
         if ($sid != '') {
             parent::setId($sid);
         }
         parent::start();
         $this->default = $this->container('Manager');
         if (!$this->default->timestamp) {
             $this->default->timestamp = time();
         }
     } catch (EMException $e) {
         throw $e;
     }
 }
Exemplo n.º 12
0
 /**
  * Form login user authentication
  *
  * @return Redirect
  * @throws Exception
  */
 public function authenticateAction()
 {
     $redirect = 'login';
     $request = $this->getRequest();
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $appServiceLoader = $this->recoverAppServiceLoader();
     $configurations = $appServiceLoader->recoverService('configurations');
     $helper = new SetupAbstractControllerHelper();
     $helper->setConfigurations($configurations);
     $helper->setRequest($request);
     $helper->setupZf2appDir();
     $helper->setupAppDirRelativePath();
     $formValidator = new UserFormAuthenticationInputFilter();
     $form = new UserFormAuthentication();
     $form->setInputFilter($formValidator->getInputFilter());
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Check authentication...
             $this->getAuthService()->getAdapter()->setIdentity($request->getPost('username'))->setCredential($request->getPost('password'));
             $result = $this->getAuthService()->authenticate();
             foreach ($result->getMessages() as $message) {
                 $this->flashmessenger()->addMessage($message);
             }
             if ($result->isValid()) {
                 $redirect = 'admin';
                 // set session timeout stored in MyAuthStorage class...
                 $this->getSessionStorage()->setRememberMe();
                 // set storage into the auth service
                 $this->getAuthService()->setStorage($this->getSessionStorage());
                 $this->getAuthService()->getStorage()->write($request->getPost('username'));
                 // Search user into db
                 $usersGetterWrapper = new UsersGetterWrapper(new UsersGetter($entityManager));
                 $usersGetterWrapper->setInput(array('username' => $request->getPost('username'), 'password' => $request->getPost('password'), 'adminAccess' => 1, 'limit' => 1));
                 $usersGetterWrapper->setupQueryBuilder();
                 $records = $usersGetterWrapper->getRecords();
                 if (isset($records) and count($records) == 1) {
                     $records = $records[0];
                     // Set ACL
                     $aclSetter = new AclSetter(new Acl());
                     $aclSetter->setUsersRolesGetterWrapper(new UsersRolesGetterWrapper(new UsersRolesGetter($entityManager)));
                     $aclSetter->addRoles($aclSetter->recoverRoles(array()));
                     if ($records['roleName'] === 'WebMaster') {
                         // Assign all permissions
                         $aclSetter->getAcl()->allow($records['roleName']);
                         $wrapper = new UsersRolesPermissionsGetterWrapper(new UsersRolesPermissionsGetter($entityManager));
                         $wrapper->setInput(array());
                         $wrapper->setupQueryBuilder();
                         $permissionsRecords = $wrapper->getRecords();
                         if (empty($permissionsRecords)) {
                             throw new NullException("Error: no permissions stored on database!");
                         }
                         foreach ($permissionsRecords as $permissionsRecord) {
                             $aclSetter->getAcl()->addResource($permissionsRecord['flag']);
                             $aclSetter->getAcl()->allow($records['roleName'], $permissionsRecord['flag']);
                         }
                     } else {
                         $wrapper = new UsersRolesPermissionsRelationsGetterWrapper(new UsersRolesPermissionsRelationsGetter($entityManager));
                         $wrapper->setInput(array('roleId' => $records['roleId']));
                         $wrapper->setupQueryBuilder();
                         $permissionsRecords = $wrapper->getRecords();
                         if (empty($permissionsRecords)) {
                             throw new NullException("Error: no permissions stored on database!");
                         }
                         foreach ($permissionsRecords as $permissionsRecord) {
                             $aclSetter->getAcl()->addResource($permissionsRecord['flag']);
                             $aclSetter->getAcl()->allow($records['roleName'], $permissionsRecord['flag']);
                         }
                     }
                     $sitename = $configurations['sitename'];
                     if (!$sitename) {
                         throw new NullException('Site name is not set. Cannot complete the login');
                     }
                     $ckFinderUploadDir = $helper->getAppDirRelativePath() . '/public/' . $configurations['media_dir'] . $configurations['media_project'] . 'ckfinder_files';
                     $userDetails = new \stdClass();
                     $userDetails->sitename = $sitename;
                     $userDetails->id = $records['id'];
                     $userDetails->name = $records['name'];
                     $userDetails->surname = $records['surname'];
                     $userDetails->email = $records['email'];
                     $userDetails->acl = $aclSetter->getAcl();
                     $userDetails->salt = $records['salt'];
                     $userDetails->passwordLastUpdate = $records['passwordLastUpdate'];
                     $userDetails->role = $records['roleName'];
                     /* Set user session values */
                     $sessionContainer = new SessionContainer();
                     $sessionContainer->offsetSet('userDetails', $userDetails);
                     $sessionContainer->offsetSet('ckFinderUploadDir', $ckFinderUploadDir);
                     /* Regenerate Session ID after login */
                     $manager = new \Zend\Session\SessionManager();
                     $manager->regenerateId();
                     /* Log entering admin area */
                     $logWriter = new LogWriter($entityManager->getConnection());
                     $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Ingresso nell'area riservata", 'description' => $records['name'] . ' ' . $records['surname'] . " ha effettuato un ingresso nell'area riservata", 'type' => 'info', 'reference_id' => 0, 'backend' => 1));
                 } else {
                     $this->flashmessenger()->addMessage(print_r("Nome utente e \\ o password non validi", 1));
                 }
             }
         } else {
             $sessionContainer = new SessionContainer();
             $loginFailures = $sessionContainer->offsetGet('loginFailures');
             $sessionContainer->offsetSet('loginFailures', $loginFailures);
             foreach ($form->getMessages() as $message) {
                 $this->flashmessenger()->addMessage(print_r($message, 1));
             }
         }
     }
     return $this->redirect()->toRoute($redirect, array("lang" => 'it'));
 }
 public function signOutAction()
 {
     // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
     if ($this->doctineAuthenticationService->hasIdentity()) {
         $this->doctineAuthenticationService->clearIdentity();
         $sessionManager = new \Zend\Session\SessionManager();
         $sessionManager->forgetMe();
     }
     return $this->redirect()->toRoute($this->redirects['after-sign-out']['route']);
     // return $this->redirectToRefer();
 }
Exemplo n.º 14
0
 public function signinAction()
 {
     $user = $this->identity();
     $auth = new AuthenticationService();
     if (!$auth->hasIdentity()) {
         $messages = null;
         $form = new SigninForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $signinFormFilter = new SigninUserModel();
             $form->setInputFilter($signinFormFilter->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');
                 $authAdapter = new AuthAdapter($dbAdapter, 'user', 'email', 'password');
                 $authAdapter->setIdentity($data['email']);
                 $authAdapter->setCredential(md5($data['password']));
                 $result = $auth->authenticate($authAdapter);
                 switch ($result->getCode()) {
                     case Result::FAILURE_IDENTITY_NOT_FOUND:
                         break;
                     case Result::FAILURE_CREDENTIAL_INVALID:
                         break;
                     case Result::SUCCESS:
                         $storage = $auth->getStorage();
                         $storage->write($authAdapter->getResultRowObject(null, 'password'));
                         $time = 604800;
                         //7 days
                         if ($data['rememberme']) {
                             $sessionManager = new \Zend\Session\SessionManager();
                             $sessionManager->rememberMe($time);
                         }
                         return $this->redirect()->toRoute('user', array('action' => 'index'));
                     default:
                         break;
                 }
                 foreach ($result->getMessages() as $message) {
                     $messages .= "{$message}\n";
                 }
             }
         }
         return new ViewModel(array('form' => $form, 'messages' => $messages));
     } else {
         return $this->redirect()->toRoute('user', array('action' => 'index'));
     }
     //        $user_session = new \Zend\Session\Container('user');
     //        if ($user_session->email!=null) {
     //            return $this->redirect()->toRoute('user',array('action'=>'index'));
     //        }
     //        $form = new SigninForm();
     //        $item = new SigninUserModel();
     //        $request = $this->getRequest();
     //        if ($request->isPost()) {
     //            $form->setInputFilter($item->getInputFilter());
     //            $form->setData($request->getPost());
     //            if ($form->isValid()) {
     //                $item->email = $form->get('email')->getValue();
     //                $item->password = $form->get('password')->getValue();
     //                $success = $this->getTable()->signin($item);
     //                if ($success) {
     //                    $user_session = new \Zend\Session\Container('user');
     //                    $user_session->email=$success->email;
     //                    $user_session->role=$success->role;
     //                    return $this->redirect()->toRoute('user');
     //                } else {
     //                    $error='Wrong email or password';
     //                }
     //            }
     //        }
     //
     //        return array(
     //            'form'=>$form,
     //            'error'=>$error
     //        );
 }
Exemplo n.º 15
0
<?php

$manager = new \Zend\Session\SessionManager();
$manager->setName('abbrevia');
\Zend\Session\Container::setDefaultManager($manager);
$auth = new Zend\Authentication\AuthenticationService();
$db->session = $manager->getStorage();
$facebookSession = new \Zend\Session\Container('facebook_id');
if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'login' && array_key_exists('xhrValidate', $_REQUEST) && array_key_exists('username', $_REQUEST) && array_key_exists('password', $_REQUEST)) {
    if (is_numeric(session_id())) {
        session_destroy();
    }
    $authAdapter = new \login\Auth($db, $_REQUEST['username'], $_REQUEST['password']);
    $authResult = $auth->authenticate($authAdapter);
    if ($authResult->getCode() != \Zend\Authentication\Result::SUCCESS) {
        $control->addValidationMessage('username_login', 'Credenziali errate');
    }
    $db->session->plain_pwd = $_REQUEST['password'];
} else {
    if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'register' && array_key_exists('username', $_REQUEST) && array_key_exists('password', $_REQUEST)) {
        $_REQUEST['task'] = 'register';
        if (array_key_exists('xhrValidate', $_REQUEST)) {
            if (!filter_var($_REQUEST['username'], FILTER_VALIDATE_EMAIL)) {
                $control->addValidationMessage('username_register', 'Inserisci una mail valida');
            }
            if (strlen($_REQUEST['password']) < 3) {
                $control->addValidationMessage('password_register', 'La password deve avere almeno tre caratteri');
            }
            if ($_REQUEST['password'] !== $_REQUEST['passwordr']) {
                $control->addValidationMessage('password_register', 'Le due password non coincidono');
            }
 function commonLogin($data, $has_encrypt)
 {
     $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     $adapter = $authService->getAdapter();
     $adapter->setIdentityValue($data['email']);
     if ($has_encrypt) {
         $data['password'] = $this->encriptPassword($this->getStaticSalt(), $data['password']);
     }
     $adapter->setCredentialValue($data['password']);
     $authResult = $authService->authenticate();
     if ($authResult->isValid()) {
         // if(!$authResult->getIdentity()->getIsActive()) {
         //     $data['random_number'] = rand();
         //     $helper = $this->CommanHelper();
         //     $user = $helper->updateUser($authResult->getIdentity()->getId(), $data);
         //     $authService->clearIdentity();
         //     $this->activateAccountEmail($user);
         //     return array('status'=>'error', 'data'=>'Please Activate your account , we sent an email with link');
         // }
         // if($authResult->getIdentity()->getIsloggedIn()) {
         //     $last_login_time = $authResult->getIdentity()->getLastLogin();
         //     $current_time = date("Y-m-d H:i:s");
         //     $newtimestamp = strtotime("$last_login_time + 10 minute");
         //     $last_login_time_plus_10_min = date('Y-m-d H:i:s', $newtimestamp);
         //     if($last_login_time_plus_10_min <= $current_time) {
         //         $this->commonLogout();
         //     }
         //     // $this->getResponse()->setStatusCode(400);
         //     return array('status'=>'error', 'data'=>'Sorry you have already logged in another system, your last session is not properly logged out please try after some time');
         // }
         // $data['is_logged_in'] = 1;
         // $data['last_login'] = date("Y-m-d H:i:s");
         $helper = $this->CommanHelper();
         $user = $helper->updateUser($authResult->getIdentity()->getId(), $data);
         $identity = $authResult->getIdentity();
         $sessionManager = new \Zend\Session\SessionManager();
         $sessionManager->regenerateId();
         $user = $identity->toArray();
         unset($user['password']);
         return array('status' => 'ok', 'data' => $user);
     } else {
         // $this->getResponse()->setStatusCode(400);
         return array('status' => 'error', 'data' => "Invalid Credentials");
     }
 }
Exemplo n.º 17
0
use Application\Service\InvoiceService;
use Application\Service\LanguageService;
use Application\Service\MailService;
use Application\Service\SettingsService;
use Application\Service\StatisticsService;
use Application\Service\SupplierService;
use Application\Service\TemplateService;
use Application\Service\WarehouseDocumentService;
use Application\Service\WarehouseService;
use Application\View\Helper\Messages;
use DoctrineModule\Persistence\ObjectManagerAwareInterface;
use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\ServiceManager;
use Zend\Validator\Translator\TranslatorAwareInterface;
return array('router' => array('routes' => array('home' => array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/', 'defaults' => array('controller' => 'Application\\Controller\\Index', 'action' => 'index'))), 'language' => array('type' => 'Segment', 'options' => array('route' => '/language/:language', 'defaults' => array('__NAMESPACE__' => 'Application\\Controller', 'controller' => 'Index', 'action' => 'language'))), 'application' => array('type' => 'Segment', 'options' => array('route' => '/application[/:controller[/:action]]', 'constraints' => array('controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*'), 'defaults' => array('__NAMESPACE__' => 'Application\\Controller', 'controller' => 'Index', 'action' => 'index')), 'may_terminate' => true, 'child_routes' => array('default' => array('type' => 'wildcard'))))), 'service_manager' => array('abstract_factories' => array('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Log\\LoggerAbstractServiceFactory'), 'aliases' => array('translator' => 'MvcTranslator'), 'invokables' => array(), 'factories' => array('sessionManager' => function (ServiceManager $sm) {
    $sessionManager = new \Zend\Session\SessionManager();
    $configuration = $sm->get('Config');
    if (isset($configuration['sessionConfiguration'])) {
        $sessionConfig = new \Zend\Session\Config\SessionConfig();
        if (isset($configuration['sessionConfiguration']['rememberMeSeconds'])) {
            $sessionConfig->setRememberMeSeconds($configuration['sessionConfiguration']['rememberMeSeconds']);
        }
        if (isset($configuration['sessionConfiguration']['savePath'])) {
            $target = $configuration['sessionConfiguration']['savePath'];
            if ($target === true) {
                $target = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/../data/session';
            }
            if (!file_exists($target)) {
                mkdir($target);
            }
            $sessionConfig->setSavePath($target);
Exemplo n.º 18
0
 /**
  * @param IDS_Report $report
  * @param int $impact
  * @param string $level
  * @return bool
  */
 public function run(IDS_Report $report, $impact, $level, Monitor $monitor = null)
 {
     $session = new \Zend\Session\SessionManager();
     $session->destroy($this->config);
     return false;
 }
Exemplo n.º 19
0
 public function signOutAction()
 {
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     if ($auth->hasIdentity()) {
         $auth->clearIdentity();
         $sessionManager = new \Zend\Session\SessionManager();
         $sessionManager->forgetMe();
     }
     return $this->redirect()->toRoute('om-zf2-user-account-sign-in');
 }
Exemplo n.º 20
0
<?php

require_once './autoloader.php';
require_once EVA_LIB_PATH . '/Markdown/markdownextra.php';
$sm1 = new Zend\Session\SessionManager();
$sm1->setId(md5('session1'));
$sessionContainer1 = new Zend\Session\Container('Namespace', $sm1);
$sessionContainer1->offsetSet('testKey', 'foo');
echo $sessionContainer1->offsetGet('testKey');
//output foo
$sm2 = new Zend\Session\SessionManager();
$sm2->setId(md5('session2'));
/*
$sessionContainer2 = new Zend\Session\Container('Namespace', $sm2);
$sessionContainer2->offsetSet('testKey', 'bar');

echo $sessionContainer2->offsetGet('testKey'); //output bar
*/
Exemplo n.º 21
0
<?php

ini_set('date.timezone', 'America/New_York');
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}
// Setup autoloading
require 'init_autoloader.php';
$sessionManager = new Zend\Session\SessionManager();
$sessionManager->setName('vfadmin');
$sessionManager->start();
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
Exemplo n.º 22
0
 public function getDispatchStatistics()
 {
     $session = new \Zend\Session\SessionManager();
     $session->start();
     $request = FrontController::getInstance()->getRequest();
     $this_module = $request->getModuleName();
     $this_controller = $request->getControllerName();
     $this_action = $request->getActionName();
     $timerNamespace = new \Zend\Session\Container('ZFDebug_Time');
     $timerNamespace->data[$this_module][$this_controller][$this_action][] = round($this->_timer['dispatchLoopShutdown'], 2);
     // Limit to last 10 requests
     while (10 < count($timerNamespace->data[$this_module][$this_controller][$this_action])) {
         array_shift($timerNamespace->data[$this_module][$this_controller][$this_action]);
     }
     foreach ($timerNamespace->data as $module => $controller) {
         if ($module != $this_module) {
             continue;
         }
         foreach ($controller as $con => $action) {
             if ($con != $this_controller) {
                 continue;
             }
             foreach ($action as $key => $data) {
                 if ($key != $this_action) {
                     continue;
                 }
                 $stats = ' – avg ' . $this->_calcAvg($data) . 'ms/' . count($data) . ' requests';
                 // $html = 'Min: ' . round(min($data), 2) . ' ms'.$this->getLinebreak();
                 // $html .= 'Max: ' . round(max($data), 2) . ' ms'.$this->getLinebreak();
             }
         }
     }
     return $stats;
 }
Exemplo n.º 23
0
 /**
  * Logout and clear the identity
  */
 public function logoutAction()
 {
     $this->UserAuthentication()->getAuthAdapter()->resetAdapters();
     $this->UserAuthentication()->getAuthAdapter()->logoutAdapters();
     $this->getServiceLocator()->get('user_remember')->forgetMe();
     $this->UserAuthentication()->getAuthService()->clearIdentity();
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     $redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false));
     if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) {
         return $this->redirect()->toUrl($redirect);
     }
     return $this->redirect()->toRoute($this->getOptions()->getLogoutRedirectRoute());
 }
Exemplo n.º 24
0
 public function logoutAction()
 {
     // in the controller
     // $auth = new AuthenticationService();
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     // @todo Set up the auth adapter, $authAdapter
     if ($auth->hasIdentity()) {
         // Identity exists; get it
         $identity = $auth->getIdentity();
         //-			echo '<pre>';
         //-			print_r($identity);
         //-			echo '</pre>';
     }
     $auth->clearIdentity();
     //-		$auth->getStorage()->session->getManager()->forgetMe(); // no way to get to the sessionManager from the storage
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->forgetMe();
     // $view = new ViewModel(array(
     //    'message' => 'Hello world',
     // ));
     // $view->setTemplate('foo/baz-bat/do-something-crazy');
     // return $view;
     // return $this->redirect()->toRoute('home');
     return $this->redirect()->toRoute('auth-doctrine/default', array('controller' => 'index', 'action' => 'login'));
 }
Exemplo n.º 25
0
 public function authenticate(AuthEvent $e)
 {
     if ($this->isSatisfied()) {
         $storage = $this->getStorage()->read();
         $e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
         return;
     }
     $identity = $e->getRequest()->getPost()->get('identity');
     $credential = $e->getRequest()->getPost()->get('credential');
     $remember = $e->getRequest()->getPost()->get('remember');
     $credential = $this->preProcessCredential($credential);
     $userObject = NULL;
     // Cycle through the configured identity sources and test each
     $fields = $this->getOptions()->getAuthIdentityFields();
     while (!is_object($userObject) && count($fields) > 0) {
         $mode = array_shift($fields);
         switch ($mode) {
             case 'username':
                 $userObject = $this->getMapper()->findByUsername($identity);
                 var_dump($userObject);
                 break;
             case 'email':
                 $userObject = $this->getMapper()->findByEmail($identity);
                 var_dump($userObject);
                 break;
         }
     }
     if (!$userObject) {
         $e->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.'));
         $this->setSatisfied(false);
         return false;
     }
     if ($this->getOptions()->getEnableUserState()) {
         // Don't allow user to login if state is not in allowed list
         if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) {
             $e->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.'));
             $this->setSatisfied(false);
             return false;
         }
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->getOptions()->getPasswordCost());
     var_dump($credential, $userObject->getPassword());
     exit;
     if (!$bcrypt->verify($credential, $userObject->getPassword())) {
         // Password does not match
         $e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.'));
         $this->setSatisfied(false);
         return false;
     }
     // Success!
     $e->setIdentity($userObject->getId());
     // Update user's password hash if the cost parameter has changed
     $this->updateUserPasswordHash($userObject, $credential, $bcrypt);
     $this->setSatisfied(true);
     // One Yeah session 31536000 seconds
     if ($remember == 1) {
         $this->getServiceManager()->get('user_remember')->setRememberMe(1);
     }
     $this->setStorage($this->getServiceManager()->get('user_remember'));
     $storage = $this->getStorage()->read();
     $storage['identity'] = $e->getIdentity();
     $this->getStorage()->write($storage);
     $time = 1209600;
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->rememberMe($time);
     $e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
 }