From 38d322389b289ae12b07a88ae4ef5d8fed10069d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 14 Nov 2017 22:34:56 +0200 Subject: [PATCH] Fix client reset password --- .../ClientAuth/ResetPasswordController.php | 5 +++-- app/Http/routes.php | 2 +- app/Models/Contact.php | 6 ++++++ app/Models/User.php | 6 ++++++ app/Ninja/Mailers/ContactMailer.php | 15 +++++++++++++++ app/Ninja/Mailers/UserMailer.php | 15 +++++++++++++++ resources/lang/en/texts.php | 1 + .../views/clientauth/passwords/reset.blade.php | 1 + ...d.blade.php => client_password_html.blade.php} | 0 .../views/emails/client_password_text.blade.php | 10 ++++++++++ ...password.blade.php => password_html.blade.php} | 0 resources/views/emails/password_text.blade.php | 8 ++++++++ 12 files changed, 66 insertions(+), 3 deletions(-) rename resources/views/emails/{client_password.blade.php => client_password_html.blade.php} (100%) create mode 100644 resources/views/emails/client_password_text.blade.php rename resources/views/emails/{password.blade.php => password_html.blade.php} (100%) create mode 100644 resources/views/emails/password_text.blade.php diff --git a/app/Http/Controllers/ClientAuth/ResetPasswordController.php b/app/Http/Controllers/ClientAuth/ResetPasswordController.php index 6a53f42a33..511c10cfa9 100644 --- a/app/Http/Controllers/ClientAuth/ResetPasswordController.php +++ b/app/Http/Controllers/ClientAuth/ResetPasswordController.php @@ -6,6 +6,7 @@ use Password; use Config; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; +use Illuminate\Http\Request; class ResetPasswordController extends Controller { @@ -48,13 +49,13 @@ class ResetPasswordController extends Controller protected function guard() { - return auth()->guard('clients'); + return auth()->guard('client'); } public function showResetForm(Request $request, $token = null) { return view('clientauth.passwords.reset')->with( - ['token' => $token, 'email' => $request->email] + ['token' => $token] ); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 728ce8fe61..bec7a83eec 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -104,7 +104,7 @@ Route::get('/client/login', ['as' => 'login', 'uses' => 'ClientAuth\LoginControl Route::get('/client/logout', ['as' => 'logout', 'uses' => 'ClientAuth\LoginController@getLogout']); Route::get('/client/session_expired', ['as' => 'logout', 'uses' => 'ClientAuth\LoginController@getSessionExpired']); Route::get('/client/recover_password', ['as' => 'forgot', 'uses' => 'ClientAuth\ForgotPasswordController@showLinkRequestForm']); -Route::get('/client/password/reset/{token}', ['as' => 'forgot', 'uses' => 'Auth\ResetPasswordController@showResetForm']); +Route::get('/client/password/reset/{token}', ['as' => 'forgot', 'uses' => 'ClientAuth\ResetPasswordController@showResetForm']); Route::group(['middleware' => ['lookup:contact']], function () { Route::post('/client/login', ['as' => 'login', 'uses' => 'ClientAuth\LoginController@login']); diff --git a/app/Models/Contact.php b/app/Models/Contact.php index e651671e5e..799f8e8e80 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -183,6 +183,12 @@ class Contact extends EntityModel implements AuthenticatableContract, CanResetPa return "{$url}/client/dashboard/{$this->contact_key}"; } + + public function sendPasswordResetNotification($token) + { + //$this->notify(new ResetPasswordNotification($token)); + app('App\Ninja\Mailers\ContactMailer')->sendPasswordReset($this, $token); + } } Contact::creating(function ($contact) diff --git a/app/Models/User.php b/app/Models/User.php index 19bd048eb2..321d71f304 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -421,6 +421,12 @@ class User extends Authenticatable { return $this->account->company->accounts->sortBy('id')->first(); } + + public function sendPasswordResetNotification($token) + { + //$this->notify(new ResetPasswordNotification($token)); + app('App\Ninja\Mailers\UserMailer')->sendPasswordReset($this, $token); + } } User::created(function ($user) diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 5507ef2ccf..6647f56d5e 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -327,4 +327,19 @@ class ContactMailer extends Mailer $this->sendTo($email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); } + + public function sendPasswordReset($contact, $token) + { + if (! $contact->email) { + return; + } + + $subject = trans('texts.your_password_reset_link'); + $view = 'client_password'; + $data = [ + 'token' => $token, + ]; + + $this->sendTo($contact->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); + } } diff --git a/app/Ninja/Mailers/UserMailer.php b/app/Ninja/Mailers/UserMailer.php index bc464525e4..c2f9fd37b4 100644 --- a/app/Ninja/Mailers/UserMailer.php +++ b/app/Ninja/Mailers/UserMailer.php @@ -154,4 +154,19 @@ class UserMailer extends Mailer $this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); } + + public function sendPasswordReset($user, $token) + { + if (! $user->email) { + return; + } + + $subject = trans('texts.your_password_reset_link'); + $view = 'password'; + $data = [ + 'token' => $token, + ]; + + $this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); + } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 2f1d5be30a..315cbc5678 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2521,6 +2521,7 @@ $LANG = array( 'self_host_login' => 'Self-Host Login', 'set_self_hoat_url' => 'Self-Host URL', 'local_storage_required' => 'Error: local storage is not available.', + 'your_password_reset_link' => 'Your Password Reset Link', ); diff --git a/resources/views/clientauth/passwords/reset.blade.php b/resources/views/clientauth/passwords/reset.blade.php index 62f7336eea..8261983a51 100644 --- a/resources/views/clientauth/passwords/reset.blade.php +++ b/resources/views/clientauth/passwords/reset.blade.php @@ -35,6 +35,7 @@
+ {!! Former::text('email')->placeholder(trans('texts.email'))->raw() !!} {!! Former::password('password')->placeholder(trans('texts.password'))->raw() !!} {!! Former::password('password_confirmation')->placeholder(trans('texts.confirm_password'))->raw() !!}
diff --git a/resources/views/emails/client_password.blade.php b/resources/views/emails/client_password_html.blade.php similarity index 100% rename from resources/views/emails/client_password.blade.php rename to resources/views/emails/client_password_html.blade.php diff --git a/resources/views/emails/client_password_text.blade.php b/resources/views/emails/client_password_text.blade.php new file mode 100644 index 0000000000..178ed24c12 --- /dev/null +++ b/resources/views/emails/client_password_text.blade.php @@ -0,0 +1,10 @@ +{{ trans('texts.reset_password') }} + +{!! URL::to(SITE_URL . "/client/password/reset/{$token}") !!} + +@if (Utils::isNinja() || ! Utils::isWhiteLabel()) + {{ trans('texts.email_signature') }}
+ {{ trans('texts.email_from') }} +@endif + +{{ trans('texts.reset_password_footer', ['email' => env('CONTACT_EMAIL', CONTACT_EMAIL)]) }} diff --git a/resources/views/emails/password.blade.php b/resources/views/emails/password_html.blade.php similarity index 100% rename from resources/views/emails/password.blade.php rename to resources/views/emails/password_html.blade.php diff --git a/resources/views/emails/password_text.blade.php b/resources/views/emails/password_text.blade.php new file mode 100644 index 0000000000..15f449af8f --- /dev/null +++ b/resources/views/emails/password_text.blade.php @@ -0,0 +1,8 @@ +{{ trans('texts.reset_password') }} + +{!! URL::to(SITE_URL . "/password/reset/{$token}") !!} + +{{ trans('texts.email_signature') }} +{{ trans('texts.email_from') }} + +{{ trans('texts.reset_password_footer', ['email' => env('CONTACT_EMAIL', CONTACT_EMAIL)]) }}