Пример #1
0
 public function indexAction()
 {
     $formlogin = new \Application\Form\Login();
     $formlogin->bind($this->request->getPost());
     $messages = array();
     if ($this->request->isPost()) {
         $formlogin->setData($this->request->getPost());
         if ($formlogin->isValid()) {
             $loginCredentials = $this->request->getPost('Login');
             $messages = $this->cs->auth($loginCredentials['username'], $this->cs->_hashing($loginCredentials['password']));
             //$messages = $this->cs->auth($loginCredentials['username'],$loginCredentials['password']);
             if (empty($messages)) {
                 $identity = $this->authservice->getIdentity();
                 $this->userid = $identity['pkUserid'];
                 //If valid, check if account password requires resetting, if true direct user to renew password
                 if (!$this->cs->hasPasswordExpired($this->userid, $this->em)) {
                     //Log time and ip address
                     $ipaddress = new RemoteAddress();
                     $pr = new \Application\Model\Preferences($this->em);
                     //Get user entity
                     $userentity = $this->em->getRepository("\\Application\\Entity\\User")->find($this->userid);
                     $userentity->setLastloginip($userentity->getIpaddress());
                     $userentity->setIpaddress($ipaddress->getIpAddress());
                     $userentity->setLastlogindate($userentity->getLogindate());
                     $userentity->setLogindate(new \Datetime());
                     $logintimes = (int) $userentity->getLogintimes() + 1;
                     $userentity->setLogintimes($logintimes);
                     //Update session information
                     $pr->saveUser($userentity);
                     return $this->redirect()->toRoute('home', array('action' => 'index'));
                 }
                 $usersession = new Container('USER');
                 $usersession->userid = $this->userid;
                 //Clear session
                 $this->authservice->clearIdentity();
                 return $this->redirect()->toRoute('login', array('action' => 'renewpassword'));
             } else {
                 //If it new student then authenticate using email address in enrolment
                 //                   $enrollmentauth = $this->cs->authNewStudent($loginCredentials['username'], $loginCredentials['password'],$this->em);
                 //                   if(count($enrollmentauth)){
                 //                       $registersession = new Container('ENROLLMENT');
                 //                       $registersession->emailaddress = $loginCredentials['username'];
                 //                       return $this->redirect()->toRoute('login', array('action' => 'register'));
                 //                   }
                 //                   //Not new student and user account does not exist
                 //                   if(!empty($messages['username']))
                 //                        $formlogin->get('Login')->get('username')->setMessages(array($messages['username']));
                 //                   if(!empty($messages['password']))
                 //                        $formlogin->get('Login')->get('password')->setMessages(array($messages['password']));
             }
         } else {
             $messages = $formlogin->getMessages();
         }
     }
     return new ViewModel(array("frmlogin" => $formlogin, "errormessage" => $messages));
 }