/** * @return array {key == lang code, value == array {key == timeOffset, value == array of recipients}} */ private function getRecipients() { $recipients = array(); $emailValidator = new Gpf_Rpc_Form_Validator_EmailValidator(); foreach ($this->recipients as $email => $recipient) { if (!$emailValidator->validate($email)) { Gpf_Log::warning('Email will not be sent to the address "' . $email . '". Address is not valid.'); continue; } try { $authuser = new Gpf_Db_AuthUser(); $authuser->setNotificationEmail($email); $authuser->loadFromData(array(Gpf_Db_Table_AuthUsers::NOTIFICATION_EMAIL)); $recipients = $this->insertRecipient($recipients, $recipient, $this->getAccountUser($authuser->getId())); } catch (Gpf_Exception $e) { try { $authuser->setUsername($email); $authuser->loadFromUsername(); $recipients = $this->insertRecipient($recipients, $recipient, $this->getAccountUser($authuser->getId())); } catch (Gpf_DbEngine_NoRowException $e) { $recipients = $this->insertRecipient($recipients, $recipient); } } } return $recipients; }
/** * Set new password for user, which requested new password * * @service * @anonym * @param Gfp_Rpc_Params $params * @return Gpf_Rpc_Form */ public function setNewPassword(Gpf_Rpc_Params $params) { $response = new Gpf_Rpc_Form($params); if (!Gpf_Captcha::isValid('set_pw_captcha', $response->getFieldValue('set_pw_captcha'))) { $response->setFieldError('set_pw_captcha', $this->_("You entered invalid security code")); return $response; } Gpf_Db_Table_PasswordRequests::expireOldRequest(); $errorMessageInvalidUsername = $this->_('You entered invalid username'); $user = new Gpf_Db_AuthUser(); $user->setUsername($response->getFieldValue('username')); try { $user->loadFromData(array(Gpf_Db_Table_AuthUsers::USERNAME)); } catch (Gpf_Exception $e) { $response->setFieldError('username', $errorMessageInvalidUsername); return $response; } $errorMessage = $this->getInvalidPasswordRequestErrorMessage(); $passwordRequest = new Gpf_Db_PasswordRequest(); $passwordRequest->setId($response->getFieldValue('requestid')); try { $passwordRequest->load(); } catch (Gpf_Exception $e) { $response->setErrorMessage($errorMessage); return $response; } if ($user->getId() != $passwordRequest->getAuthUser()) { $response->setFieldError('username', $errorMessageInvalidUsername); return $response; } if ($passwordRequest->getStatus() != Gpf_Db_Table_PasswordRequests::STATUS_PENDING || $user->getUsername() != $response->getFieldValue('username')) { $response->setErrorMessage($errorMessage); return $response; } $user->setPassword($response->getFieldValue('password')); try { $user->update(array(Gpf_Db_Table_AuthUsers::PASSWORD)); } catch (Gpf_DbEngine_Row_ConstraintException $e) { $response->setErrorMessage($e->getMessage()); return $response; } $passwordRequest->setStatus(Gpf_Db_Table_PasswordRequests::STATUS_APPLIED); $passwordRequest->update(array(Gpf_Db_Table_PasswordRequests::STATUS)); $response->setInfoMessage($this->_("Your password was changed. Go back to login dialog and login.")); return $response; }
private function addRecipientsFilter(Gpf_SqlBuilder_Filter $filter) { $condition = new Gpf_SqlBuilder_CompoundWhereCondition(); $condition->add('m.' . Gpf_Db_Table_Mails::TO_RECIPIENTS, '=', $filter->getValue(), 'OR'); try { $dbUser = new Gpf_Db_AuthUser(); $dbUser->setUsername($filter->getValue()); $dbUser->loadFromData(array(Gpf_Db_Table_AuthUsers::USERNAME)); if (strlen($dbUser->getNotificationEmail())) { $condition->add('m.' . Gpf_Db_Table_Mails::TO_RECIPIENTS, '=', $dbUser->getNotificationEmail(), 'OR'); } } catch (Exception $e) { } $this->_selectBuilder->where->addCondition($condition); }