Beispiel #1
0
 /**
  * @param \User\Model\User $user
  * @return boolean
  */
 public function updateUser(\User\Model\User $user)
 {
     if (!$user->getId() && !$user->getEmail() && !$user->getUsername()) {
         return false;
     }
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     if ($user->getPassword()) {
         $user->setSalt(substr(md5(rand(2000, 5000) . time() . rand(2000, 5000)), 0, 20));
         $user->setPassword(md5($user->getSalt() . $user->getPassword()));
     }
     return $userMapper->updateUser($user);
 }
 public function addAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     /* @var $cityMapper \Address\Model\CityMapper */
     $cityMapper = $sl->get('Address\\Model\\CityMapper');
     $city = new \Address\Model\City();
     /* @var $districtMapper \Address\Model\DistrictMapper */
     $districtMapper = $sl->get('Address\\Model\\DistrictMapper');
     $district = new \Address\Model\District();
     $districts = array();
     if (!!($cityId = $request->getPost('cityId'))) {
         $district->setCityId($cityId);
         $districts = $districtMapper->fetchAll($district);
     }
     $form = new \System\Form\User\Add($this->getServiceLocator());
     $form->setCities($city->toSelectBoxArray($cityMapper->fetchAll()));
     $form->setDistricts($district->toSelectBoxArray($districts));
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $user = new User();
             $user->exchangeArray($form->getData());
             $user->setSalt($user->generateSalt());
             $user->setPassword($user->createPassword());
             if (!$user->getRole()) {
                 $user->setRole(User::ROLE_GUEST);
             }
             if ($user->getBirthdate()) {
                 $user->setBirthdate(DateBase::toCommonDate($user->getBirthdate()));
             }
             $user->setActive(1);
             $user->setCreatedById($this->user()->getIdentity());
             $user->setCreatedDate(DateBase::getCurrentDate());
             $user->setCreatedDateTime(DateBase::getCurrentDateTime());
             $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper');
             $userMapper->save($user);
             if ($form->get('afterSubmit')->getValue()) {
                 return $this->redirect()->toUrl($form->get('afterSubmit')->getValue());
             }
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }