From 056ae54a15686f871b3fbad58bb580aea383c393 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Sat, 5 Sep 2015 18:32:07 +0200 Subject: [PATCH] Fixed: Change E-Mail broken --- .../user/controllers/AccountController.php | 2 +- .../user/models/forms/AccountChangeEmail.php | 27 +++++++++--------- .../modules/user/views/mails/ChangeEmail.php | 28 +++++++++---------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/protected/humhub/modules/user/controllers/AccountController.php b/protected/humhub/modules/user/controllers/AccountController.php index 2147aa6afe..3fbebb7611 100644 --- a/protected/humhub/modules/user/controllers/AccountController.php +++ b/protected/humhub/modules/user/controllers/AccountController.php @@ -215,7 +215,7 @@ class AccountController extends Controller { $user = Yii::$app->user->getIdentity(); if ($user->auth_mode != User::AUTH_MODE_LOCAL) { - throw new CHttpException(500, Yii::t('UserModule.controllers_AccountController', 'You cannot change your e-mail address here.')); + throw new HttpException(500, Yii::t('UserModule.controllers_AccountController', 'You cannot change your e-mail address here.')); } $model = new \humhub\modules\user\models\forms\AccountChangeEmail; diff --git a/protected/humhub/modules/user/models/forms/AccountChangeEmail.php b/protected/humhub/modules/user/models/forms/AccountChangeEmail.php index 41df9dce09..4ed02b1001 100644 --- a/protected/humhub/modules/user/models/forms/AccountChangeEmail.php +++ b/protected/humhub/modules/user/models/forms/AccountChangeEmail.php @@ -21,6 +21,7 @@ namespace humhub\modules\user\models\forms; use Yii; +use yii\helpers\Url; use humhub\models\Setting; /** @@ -67,21 +68,21 @@ class AccountChangeEmail extends \yii\base\Model */ public function sendChangeEmail() { + $user = Yii::$app->user->getIdentity(); - if ($this->validate()) { + $token = md5(Setting::Get('secret') . $user->guid . $this->newEmail); - $user = Yii::app()->user->getIdentity(); - - $token = md5(Setting::Get('secret') . $user->guid . $this->newEmail); - - $message = new HMailMessage(); - $message->view = "application.modules_core.user.views.mails.ChangeEmail"; - $message->addFrom(Setting::Get('systemEmailAddress', 'mailing'), Setting::Get('systemEmailName', 'mailing')); - $message->addTo($this->newEmail); - $message->subject = Yii::t('UserModule.forms_AccountChangeEmailForm', 'E-Mail change'); - $message->setBody(array('user' => $user, 'newEmail' => $this->newEmail, 'token' => $token), 'text/html'); - Yii::app()->mail->send($message); - } + $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/ChangeEmail'], [ + 'user' => $user, + 'newEmail' => $this->newEmail, + 'approveUrl' => Url::to(["/user/account/change-email-validate", 'email' => $this->newEmail, 'token' => $token], true) + ]); + $mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]); + $mail->setTo($this->newEmail); + $mail->setSubject(Yii::t('UserModule.forms_AccountChangeEmailForm', 'E-Mail change')); + $mail->send(); + + return true; } } diff --git a/protected/humhub/modules/user/views/mails/ChangeEmail.php b/protected/humhub/modules/user/views/mails/ChangeEmail.php index ef16018721..b8c8eb3756 100644 --- a/protected/humhub/modules/user/views/mails/ChangeEmail.php +++ b/protected/humhub/modules/user/views/mails/ChangeEmail.php @@ -1,5 +1,7 @@ -beginContent('application.views.mail.template'); ?> + @@ -25,9 +27,9 @@ - - Confirm your new email address'); ?> - + + Confirm your new email address'); ?> + @@ -92,9 +94,9 @@ - displayName); ?>,

+ displayName); ?>,

- Your new e-mail address is {newemail}.

To confirm your new e-mail address please click on the button below.', array('{newemail}' => CHtml::encode($newEmail))); ?> + Your new e-mail address is {newemail}.

To confirm your new e-mail address please click on the button below.', array('{newemail}' => Html::encode($newEmail))); ?> @@ -119,11 +121,11 @@ - - $newEmail, 'token'=>$token)); ?>" style="text-decoration: none; color: #ffffff; font-weight: 300;"> - - - + + + + + @@ -152,6 +154,4 @@ - - -endContent(); ?> \ No newline at end of file + \ No newline at end of file