public function resetAction() { $users = new Users_Model_Users(); $user = $users->getUserWithToken($this->_getParam('token')); if (!$user) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Wrong Token')); $this->_redirect(''); return; } $newPassword = $user->generateRandomPassword(); $user->setClearPassword($newPassword); // reset token $user->token = Users_Model_User::generateToken(); $user->save(); $file = CommunityID_Resources::getResourcePath('passwordreset2_mail.txt'); $emailTemplate = file_get_contents($file); $emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate); $emailTemplate = str_replace('{password}', $newPassword, $emailTemplate); $this->_sendMail($user->email, $this->view->translate('Community-ID password reset'), $emailTemplate); $this->_helper->FlashMessenger->addMessage($this->view->translate('You\'ll receive your new password via E-mail')); $this->_redirect(''); }
public function saveAction() { $form = new Users_Form_Register(null, $this->view->base); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { $appSession = Zend_Registry::get('appSession'); $appSession->registerForm = $form; return $this->_forward('index', null, null); } $users = new Users_Model_Users(); if ($users->getUserWithUsername($form->getValue('username'), false, $this->view)) { $form->username->addError($this->view->translate('This username is already in use')); $appSession = Zend_Registry::get('appSession'); $appSession->registerForm = $form; return $this->_forward('index', null, null); } if ($users->getUserWithEmail($form->getValue('email'))) { $form->email->addError($this->view->translate('This E-mail is already in use')); $appSession = Zend_Registry::get('appSession'); $appSession->registerForm = $form; return $this->_forward('index', null, null); } $user = $users->createRow(); $user->firstname = $form->getValue('firstname'); $user->lastname = $form->getValue('lastname'); $user->email = $form->getValue('email'); $user->username = $form->getValue('username'); preg_match('#(.*)/users/register/save#', Zend_OpenId::selfURL(), $matches); $user->generateOpenId($matches[1]); if ($this->_config->ldap->enabled) { // when using ldap, unconfirmed users' password is saved unhashed temporarily, while he registers, // and then it's stored in LDAP and cleared from the db $user->setPassword($form->getValue('password1')); } else { $user->setClearPassword($form->getValue('password1')); } $user->role = Users_Model_User::ROLE_GUEST; $user->token = Users_Model_User::generateToken(); $user->accepted_eula = 0; $user->registration_date = date('Y-m-d'); $mail = self::getMail($user, $this->view->translate('Community-ID registration confirmation')); try { $mail->send(); $user->save(); $user->createDefaultProfile($this->view); $this->_helper->FlashMessenger->addMessage($this->view->translate('Thank you.')); $this->_helper->FlashMessenger->addMessage($this->view->translate('You will receive an E-mail with instructions to activate the account.')); } catch (Zend_Mail_Exception $e) { if ($this->_config->environment->production) { $this->_helper->FlashMessenger->addMessage($this->view->translate('The confirmation E-mail could not be sent, so the account creation was cancelled. Please contact support.')); } else { $this->_helper->FlashMessenger->addMessage($this->view->translate('The account was created but the E-mail could not be sent')); // I still wanna create the user when in development mode $user->save(); } if ($this->_config->logging->level == Zend_Log::DEBUG) { $this->_helper->FlashMessenger->addMessage($e->getMessage()); } } $this->_redirect(''); }