public function userdetailsAction()
 {
     $staffdetails = array();
     $successMsg = "";
     $flashMessenger = $this->flashMessenger();
     if ($flashMessenger->hasSuccessMessages()) {
         $successMsg = implode("<br>", $flashMessenger->getSuccessMessages());
     }
     //Reset password form
     $resetform = new \Application\Form\Resetpassword($this->em);
     $resetform->bind($this->request->getPost());
     if ($this->request->getPost('save')) {
         $resetform->setData($this->request->getPost());
         if ($resetform->isValid()) {
             $formData = $resetform->getData();
             //Get password expiry days
             $days = $this->preferences->getSystemsettings()->getPasswordExpireydays() + 1;
             //Set date interval
             $interval = "P" . $days . "D";
             $date = new \DateTime();
             //Back date password change date
             $date->sub(new \DateInterval($interval));
             $user = $this->em->getRepository('\\Application\\Entity\\User')->find($formData['Password']['pkUserid']);
             $user->setPassword($this->cs->_hashing($formData['Password']['password']));
             $user->setPasswordlastchanged($date);
             $this->preferences->saveUser($user);
         }
     }
     //Change department information form
     $deptform = new \Application\Form\Staff($this->em);
     if ($this->request->getPost('savedeptinfo')) {
         $staff = new \Application\Model\Staff($this->em);
         $deptform->bind($this->request->getPost());
         $deptform->setData($this->request->getPost());
         if ($deptform->isValid()) {
             $formdata = $deptform->getData();
             //Initialize entity
             $staffentity = $this->em->getRepository('\\Application\\Entity\\Staff')->find($formdata['Staff']['pkStaffid']);
             $deptentity = $this->em->getRepository('\\Application\\Entity\\Department')->find($formdata['Staff']['fkDeptid']);
             $staffentity->setWorkmode($formdata['Staff']['workmode']);
             $staffentity->setFkDeptid($deptentity);
             $staff->saveStaff($staffentity);
         }
     }
     //Edit basic user details
     $userinfoform = new \Application\Form\Userinformation($this->em);
     $userinfoform->bind($this->request->getPost());
     if ($this->request->getPost('btnchange')) {
         $userinfoform->setData($this->request->getPost());
         if ($userinfoform->isValid()) {
             $formData = $userinfoform->getData();
             $user = $this->em->getRepository('\\Application\\Entity\\User')->find($formData['User']['pkUserid']);
             $user->setFirstname($formData['User']['basicdetails']['firstname']);
             $user->setSurname($formData['User']['basicdetails']['surname']);
             $user->setGender($formData['User']['basicdetails']['gender']);
             $user->setEmailaddress($formData['User']['emailaddress']);
             $user->setTitle($formData['User']['basicdetails']['title']);
             $user->setOthernames($formData['User']['basicdetails']['othernames']);
             $user->setUsername($formData['User']['username']);
             $user->setFkRoleid($user->getFkRoleid());
             $this->preferences->saveUser($user);
         }
     }
     $id = $this->getEvent()->getRouteMatch()->getParam('id');
     //Get user details in user table
     $user = $this->em->getRepository("\\Application\\Entity\\User")->find($id);
     //Determine type of account
     if ($user->getAccounttype() == "STAFF") {
         $staffdetails = $this->em->getRepository("\\Application\\Entity\\Staff")->findOneBy(array("fkUserid" => $id));
     }
     return new ViewModel(array("msg" => $successMsg, "user" => $user, "staffdetails" => $staffdetails, "resetform" => $resetform, "basicform" => $userinfoform, "deptform" => $deptform));
 }
Пример #2
0
 public function renewpasswordAction()
 {
     $form = new \Application\Form\Resetpassword($this->em);
     $usersession = new Container('USER');
     $userid = $usersession->userid;
     $form->bind($this->request->getPost());
     if ($this->request->isPost()) {
         $form->setData($this->request->getPost());
         if ($form->isValid()) {
             //Reset password
             $formdata = $form->getData();
             $preferences = new \Application\Model\Preferences($this->em);
             //Get current id object
             $userEntity = $this->em->getRepository('\\Application\\Entity\\User')->find($formdata['Password']['pkUserid']);
             $userEntity->setPassword($this->cs->_hashing($formdata['Password']['password']));
             $userEntity->setPasswordlastchanged(new \DateTime());
             $preferences->saveUser($userEntity);
             $usersession->getManager()->getStorage()->clear('USER');
             return $this->redirect()->toRoute('login', array('action' => 'index'));
         }
     }
     return new ViewModel(array("form" => $form, "userid" => $userid));
 }