From c2904d0c9277c6831f25cf2ca75da34c2c93776a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 26 Jun 2020 14:20:45 +0200 Subject: [PATCH 1/3] Require password update if not set when confirming email --- .../Controllers/Traits/VerifiesUserEmail.php | 48 +++++++++++++++---- resources/lang/en/texts.php | 1 + .../auth/confirmation_with_password.blade.php | 43 +++++++++++++++++ routes/web.php | 1 + 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php diff --git a/app/Http/Controllers/Traits/VerifiesUserEmail.php b/app/Http/Controllers/Traits/VerifiesUserEmail.php index 889d4dea5c55..5e34fc587e5d 100644 --- a/app/Http/Controllers/Traits/VerifiesUserEmail.php +++ b/app/Http/Controllers/Traits/VerifiesUserEmail.php @@ -15,6 +15,7 @@ namespace App\Http\Controllers\Traits; use App\Models\User; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; /** * Class VerifiesUserEmail @@ -30,20 +31,49 @@ trait VerifiesUserEmail */ public function confirm() { - if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->route('confirmation_code'))->first()) { - $user->email_verified_at = now(); - $user->confirmation_code = null; - $user->save(); + $user = User::where('confirmation_code', request()->confirmation_code)->first(); + + // if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->input('confirmation_code'))->first()) { - return $this->render('auth.confirmed', [ - 'root' => 'themes', - 'message' => ctrans('texts.security_confirmation'), - ]); + if (!$user) { + return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]); } + if (is_null($user->password) || empty($user->password)) { + return $this->render('auth.confirmation_with_password', ['root' => 'themes']); + } + + $user->email_verified_at = now(); + $user->confirmation_code = null; + $user->save(); + return $this->render('auth.confirmed', [ 'root' => 'themes', - 'message' => ctrans('texts.wrong_confirmation'), + 'message' => ctrans('texts.security_confirmation'), + ]); + } + + public function confirmWithPassword() + { + $user = User::where('confirmation_code', request()->confirmation_code)->first(); + + if (!$user) { + return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]); + } + + request()->validate([ + 'password' => ['required', 'min:6', 'confirmed'], + ]); + + $user->password = Hash::make(request()->password); + + $user->email_verified_at = now(); + $user->confirmation_code = null; + $user->save(); + + return $this->render('auth.confirmed', [ + 'root' => 'themes', + 'message' => ctrans('texts.security_confirmation'), ]); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 42c5f2bfaf78..172cf2b155ce 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3224,4 +3224,5 @@ return [ 'year_invalid' => 'Provided year is not valid.', 'if_you_need_help' => 'If you need help you can either post to our', + 'update_password_on_confirm' => 'After updating your password, your account will be confirmed.', ]; diff --git a/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php new file mode 100644 index 000000000000..ac96e616a75c --- /dev/null +++ b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php @@ -0,0 +1,43 @@ +@extends('portal.ninja2020.layout.clean') +@section('meta_title', ctrans('texts.set_password')) + +@section('body') +
+
+
+ Invoice Ninja logo +

{{ ctrans('texts.set_password') }}

+ {{ ctrans('texts.update_password_on_confirm') }} + +
+ @csrf +
+ + + @error('password') +
+ {{ $message }} +
+ @enderror +
+
+ + + @error('password_confirmation') +
+ {{ $message }} +
+ @enderror +
+
+ +
+
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index 08e26b71c171..b50df7e6e9b3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,4 +30,5 @@ Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('passw */ Route::group(['middleware' => ['url_db']], function () { Route::get('/user/confirm/{confirmation_code}', 'UserController@confirm'); + Route::post('/user/confirm/{confirmation_code}', 'UserController@confirmWithPassword'); }); \ No newline at end of file From 81b544a4d1b1f703de67305d0836bf8cc0abe842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 26 Jun 2020 14:22:29 +0200 Subject: [PATCH 2/3] Update labels --- .../themes/ninja2020/auth/confirmation_with_password.blade.php | 2 +- resources/views/themes/ninja2020/auth/passwords/reset.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php index ac96e616a75c..227b3824645d 100644 --- a/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php +++ b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php @@ -23,7 +23,7 @@ @enderror
- + diff --git a/resources/views/themes/ninja2020/auth/passwords/reset.blade.php b/resources/views/themes/ninja2020/auth/passwords/reset.blade.php index deaa68e6e9d9..f59686661e99 100644 --- a/resources/views/themes/ninja2020/auth/passwords/reset.blade.php +++ b/resources/views/themes/ninja2020/auth/passwords/reset.blade.php @@ -38,7 +38,7 @@ @enderror
- + From b0234fd69a645c9bd408f0e46b37cc26269854ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 26 Jun 2020 14:23:32 +0200 Subject: [PATCH 3/3] Update translation --- resources/lang/en/texts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 172cf2b155ce..2d55aa1dd634 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3224,5 +3224,5 @@ return [ 'year_invalid' => 'Provided year is not valid.', 'if_you_need_help' => 'If you need help you can either post to our', - 'update_password_on_confirm' => 'After updating your password, your account will be confirmed.', + 'update_password_on_confirm' => 'After updating password, your account will be confirmed.', ];