protected function renderContent() { if (isset($this->block) && $this->block != null) { $model = new UserRegisterForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'userregister-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['UserRegisterForm'])) { $model->attributes = $_POST['UserRegisterForm']; // validate user input password if ($model->validate()) { $new_user = new User(); $new_user->scenario = 'create'; //$new_user->username=$model->username; $new_user->username = $new_user->email = $model->email; $new_user->display_name = $model->username; $old_password = $new_user->password = $model->password; //Create hash activation key $new_user->user_activation_key = md5(time() . $new_user->username . USER_SALT); if ($new_user->save()) { //We will send mail for the user $ses = new SimpleEmailService(ConstantDefine::AMAZON_SES_ACCESS_KEY, ConstantDefine::AMAZON_SES_SECRET_KEY); $ses->enableVerifyHost(false); $m = new SimpleEmailServiceMessage(); $m->addTo($new_user->email); $m->setFrom(ConstantDefine::AMAZON_SES_EMAIL); $m->setSubject('[' . SITE_NAME . '] Confirm your email at ' . SITE_NAME_URL); $m_content = 'Hi ' . $new_user->display_name . '<br /><br />'; $m_content .= 'Welcome to ' . SITE_NAME . '! Please take a second to confirm ' . $new_user->email . ' as your email address by clicking this link: <br /><br />'; $link_content = FRONT_SITE_URL . '/user-activation/?key=' . $new_user->user_activation_key . '&user_id=' . $new_user->user_id; $m_content .= '<a href="' . $link_content . '">' . $link_content . '</a><br /><br />'; $m_content .= 'Thank you for being with us!<br /><br />'; $m_content .= SITE_NAME . ' Team'; $m->setMessageFromString($m_content, $m_content); $ses->sendEmail($m); //Redirect to the Dashboard Page $login_form = new UserLoginForm(); $login_form->username = $new_user->username; $login_form->password = $old_password; if ($login_form->login()) { Yii::app()->controller->redirect(bu()); } else { throw new CHttpException(503, t('Error while setting up your Account. Please try again later')); } } } } $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model)); } else { echo ''; } }
protected function renderContent() { if (isset($this->block) && $this->block != null) { $model = new UserRecoverPassForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'recoverpassword-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['UserRecoverPassForm'])) { $model->attributes = $_POST['UserRecoverPassForm']; // validate user input and redirect to the previous page if valid if ($model->validate()) { //Find the user with the email $user = User::model()->find('email=:email', array(':email' => $model->email)); if ($user) { //Create a new password recover key $key = md5(USER_RECOVER_PASS_SALT . time() . $user->username . $user->email); $user->email_recover_key = $key; if ($user->save()) { $ses = new SimpleEmailService(ConstantDefine::AMAZON_SES_ACCESS_KEY, ConstantDefine::AMAZON_SES_SECRET_KEY); $ses->enableVerifyHost(false); $m = new SimpleEmailServiceMessage(); $m->addTo($user->email); $m->setFrom(ConstantDefine::AMAZON_SES_EMAIL); $m->setSubject('[' . SITE_NAME . '] Password reset instructions'); $m_content = 'Hi ' . $user->display_name . '<br /><br />'; $m_content .= 'A request to reset your ' . SITE_NAME . ' password has been made. If you did not make this request, simply ignore this email. If you did make this request, just click the link below:<br /><br />'; $link_content = FRONT_SITE_URL . '/reset-password/?key=' . $user->email_recover_key . '&user_id=' . $user->user_id; $m_content .= '<a href="' . $link_content . '">' . $link_content . '</a><br /><br />'; $m_content .= 'If the URL above does not work, try copying and pasting it into your browser.<br /><br />'; $m_content .= 'If you continue to have problems, please feel free to contact us: <a href="mailto:' . ConstantDefine::SUPPORT_EMAIL . '">' . ConstantDefine::SUPPORT_EMAIL . '</a><br /><br />'; $m_content .= 'Thank you for being with us!<br /><br />'; $m_content .= SITE_NAME . ' Team'; $m->setMessageFromString($m_content, $m_content); $ses->sendEmail($m); user()->setFlash('success', 'Instructions to reset your password have been sent to you. Please check your email.'); Yii::app()->controller->redirect(bu() . '/sign-in'); } } else { user()->setFlash('error', 'Email is not existed'); } } } $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model)); } else { echo ''; } }
public function sendEmail() { $email = str_replace('INTRODUCEE_NAME', $this->introducee->getName(), str_replace('OTHER_NAME', $this->other->getName(), str_replace('INTRODUCER_NAME', $this->userName, str_replace('LINK', $this->introductionUrl . '', Content::getInstance()->getEmail('email-introduction'))))); $subject = str_replace('INTRODUCEE_NAME', $this->introducee->getName(), str_replace('INTRODUCER_NAME', $this->userName, Content::c()->introduce->email)); // Send the email with AWS SES $ses = new SimpleEmailService(SES_KEY, SES_SECRET); $ses->enableVerifyHost(false); $ses->enableVerifyPeer(false); $m = new SimpleEmailServiceMessage(); $m->addTo($this->introducee->getEmail()); $m->setFrom(SES_FROM); $m->setSubject($subject); $m->setMessageFromString($subject . ' ' . $this->introductionUrl, $email); $result = $ses->sendEmail($m); if (!$result) { return false; } // Save the email result to the database $sth = $this->db->prepare('INSERT INTO aws_ses (recipient_id, ses_message_id, ses_request_id, introduction_id) VALUES (:recipient_id, :ses_message_id, :ses_request_id, :introduction_id)'); $sth->execute(array(':recipient_id' => $this->introducee->getId(), ':ses_message_id' => $result['MessageId'], ':ses_request_id' => $result['RequestId'], ':introduction_id' => $this->introductionId)); return true; }