Beispiel #1
0
 public function loginAction()
 {
     $user = $this->identity();
     $form = new AuthForm();
     $form->get('submit')->setValue('Войти');
     $messages = null;
     $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_email', 'usr_password', "MD5(CONCAT('{$staticSalt}', ?, usr_password_salt)) AND usr_active = 1");
             $authAdapter->setIdentity($data['usr_email'])->setCredential($data['usr_password']);
             $auth = new AuthenticationService();
             $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, 'usr_password'));
                     $time = 1209600;
                     // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                     if ($data['rememberme']) {
                         $sessionManager = new \Zend\Session\SessionManager();
                         $sessionManager->rememberMe($time);
                     }
                     break;
                 default:
                     break;
             }
             foreach ($result->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
         }
     }
     return new ViewModel(array('form' => $form, 'messages' => $messages));
 }
 public function indexAction()
 {
     $form = new RegistrationForm();
     $form->get('submit')->setValue('Регистрация');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $data = $this->prepareData($data);
             $auth = new Auth();
             $auth->exchangeArray($data);
             $this->getUsersTable()->saveUser($auth);
             $this->sendConfirmationEmail($auth);
             $this->flashMessenger()->addMessage($auth->usr_email);
             return $this->redirect()->toRoute('myauth', array('controller' => 'registration', 'action' => 'registration-success'));
         }
     }
     return new ViewModel(array('form' => $form));
 }