From 706ca1938bb13407a9cd93b2d63e6c95bf8194fe Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 16 Aug 2018 18:10:09 +0800 Subject: [PATCH] Update mail template of password reset --- app/Http/Controllers/AuthController.php | 4 +-- app/Mail/ForgotPassword.php | 8 +++--- resources/lang/en/auth.yml | 8 +++--- resources/lang/zh_CN/auth.yml | 8 +++--- resources/views/auth/mail.tpl | 26 ------------------- .../views/mails/password-reset.blade.php | 3 +++ tests/AuthControllerTest.php | 8 +++--- 7 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 resources/views/auth/mail.tpl create mode 100644 resources/views/mails/password-reset.blade.php diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index edaa4f47..021c3b94 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -167,12 +167,12 @@ class AuthController extends Controller } catch (\Exception $e) { report($e); - return json(trans('auth.mail.failed', ['msg' => $e->getMessage()]), 2); + return json(trans('auth.forgot.failed', ['msg' => $e->getMessage()]), 2); } Session::put('last_mail_time', time()); - return json(trans('auth.mail.success'), 0); + return json(trans('auth.forgot.success'), 0); } public function reset($uid, UserRepository $users) diff --git a/app/Mail/ForgotPassword.php b/app/Mail/ForgotPassword.php index b4fcfe41..b5259a99 100644 --- a/app/Mail/ForgotPassword.php +++ b/app/Mail/ForgotPassword.php @@ -14,7 +14,7 @@ class ForgotPassword extends Mailable /** * @var string */ - public $reset_url = ''; + public $url = ''; /** * Create a new message instance. @@ -24,7 +24,7 @@ class ForgotPassword extends Mailable */ public function __construct(string $url) { - $this->reset_url = $url; + $this->url = $url; } /** @@ -37,7 +37,7 @@ class ForgotPassword extends Mailable $site_name = option_localized('site_name'); return $this->from(config('mail.username'), $site_name) - ->subject(trans('auth.mail.title', ['sitename' => $site_name])) - ->view('auth.mail'); + ->subject(trans('auth.forgot.mail.title', ['sitename' => $site_name])) + ->view('mails.password-reset'); } } diff --git a/resources/lang/en/auth.yml b/resources/lang/en/auth.yml index 9592f77c..d3804e5b 100644 --- a/resources/lang/en/auth.yml +++ b/resources/lang/en/auth.yml @@ -29,15 +29,17 @@ forgot: close: Password resetting is not available now. frequent-mail: You click the send button too fast. Wait for 60 secs, guy. unregistered: The email address is not registered. - -mail: - title: Reset your password on :sitename success: Mail is sent. Will be expired in 1 hour, please check. failed: Fail to send mail, detailed message :msg message: You are receiving this email because this email address was used to reset your password on :sitename ignore: If you haven't signed up on our site, please ignore this email. No unsubscribing is required. reset: Reset your password notice: This mail is sending automatically, no reponses will be sent if you reply. + mail: + title: Reset your password on :sitename + message: You are receiving this email because we received a password reset request for your account on :sitename. + reset: "To reset your password, please visit: :url" + ignore: If you did not request a password reset, no further action is required. reset: title: Reset Password diff --git a/resources/lang/zh_CN/auth.yml b/resources/lang/zh_CN/auth.yml index df298e24..9472fa2e 100644 --- a/resources/lang/zh_CN/auth.yml +++ b/resources/lang/zh_CN/auth.yml @@ -29,15 +29,17 @@ forgot: close: 本站已关闭重置密码功能 frequent-mail: 你邮件发送得太频繁啦,过 60 秒后再点发送吧 unregistered: 该邮箱尚未注册 - -mail: - title: 重置您在 :sitename 上的账户密码 success: 邮件已发送,一小时内有效,请注意查收。 failed: 邮件发送失败,详细信息::msg message: 您收到这封邮件,是因为在 :sitename 的用户重置密码功能使用了您的地址。 ignore: 如果您并没有访问过我们的网站,或没有进行上述操作,请忽略这封邮件。 您不需要退订或进行其他进一步的操作。 reset: 重置密码 notice: 本邮件由系统自动发送,就算你回复了我们也不会回复你哦 + mail: + title: 重置您在 :sitename 上的账户密码 + message: 您收到这封邮件,是因为有人在 :sitename 的密码重置功能中使用了您的地址。 + reset: 点击此链接重置您的密码::url + ignore: 如果您并没有访问过我们的网站,或没有进行上述操作,请忽略这封邮件。 reset: title: 重置密码 diff --git a/resources/views/auth/mail.tpl b/resources/views/auth/mail.tpl deleted file mode 100644 index 425d5c03..00000000 --- a/resources/views/auth/mail.tpl +++ /dev/null @@ -1,26 +0,0 @@ -
- -
-
-
-

- {{ option_localized('site_name') }} -

-
{!! trans('auth.mail.message', ['sitename' => "".option_localized('site_name').""]) !!}

-
- @lang('auth.mail.ignore') -
-
- -
-
- * @lang('auth.mail.notice')
-
-
-
-
-
diff --git a/resources/views/mails/password-reset.blade.php b/resources/views/mails/password-reset.blade.php new file mode 100644 index 00000000..55418000 --- /dev/null +++ b/resources/views/mails/password-reset.blade.php @@ -0,0 +1,3 @@ +

{!! trans('auth.forgot.mail.message', ['sitename' => option_localized('site_name')]) !!}

+

{!! trans('auth.forgot.mail.reset', ['url' => $url]) !!}

+

{!! trans('auth.forgot.mail.ignore') !!}

diff --git a/tests/AuthControllerTest.php b/tests/AuthControllerTest.php index a27ee8a8..9e4b93a6 100644 --- a/tests/AuthControllerTest.php +++ b/tests/AuthControllerTest.php @@ -412,7 +412,7 @@ class AuthControllerTest extends TestCase 'captcha' => 'a' ])->assertJson([ 'errno' => 0, - 'msg' => trans('auth.mail.success') + 'msg' => trans('auth.forgot.success') ])->assertSessionHas('last_mail_time'); Mail::assertSent(ForgotPassword::class, function ($mail) use ($user) { return $mail->hasTo($user->email); @@ -429,7 +429,7 @@ class AuthControllerTest extends TestCase 'captcha' => 'a' ])->assertJson([ 'errno' => 2, - 'msg' => trans('auth.mail.failed', ['msg' => 'A fake exception.']) + 'msg' => trans('auth.forgot.failed', ['msg' => 'A fake exception.']) ]); // Addition: Mailable test @@ -437,8 +437,8 @@ class AuthControllerTest extends TestCase $mailable = new ForgotPassword('url'); $mailable->build(); $this->assertTrue($mailable->hasFrom(config('mail.username'), $site_name)); - $this->assertEquals(trans('auth.mail.title', ['sitename' => $site_name]), $mailable->subject); - $this->assertEquals('auth.mail', $mailable->view); + $this->assertEquals(trans('auth.forgot.mail.title', ['sitename' => $site_name]), $mailable->subject); + $this->assertEquals('mails.password-reset', $mailable->view); } public function testReset()