From 1c9f20dd80292507059606a2f7ed0d3304ef402c Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Thu, 26 Dec 2019 16:04:17 +0100 Subject: [PATCH] =?UTF-8?q?dodanie=20opcji=20zmiany=20has=C5=82a=20przez?= =?UTF-8?q?=20u=C5=BCytkownika?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ChangePasswordController.php | 40 +++++++++++++ app/Rules/ComparePasswords.php | 41 +++++++++++++ resources/views/changePassword.blade.php | 60 +++++++++++++++++++ resources/views/userProfile.blade.php | 9 +++ resources/views/userProfileEdit.blade.php | 1 + routes/web.php | 2 + 6 files changed, 153 insertions(+) create mode 100644 app/Http/Controllers/ChangePasswordController.php create mode 100644 app/Rules/ComparePasswords.php create mode 100644 resources/views/changePassword.blade.php diff --git a/app/Http/Controllers/ChangePasswordController.php b/app/Http/Controllers/ChangePasswordController.php new file mode 100644 index 0000000..cee1153 --- /dev/null +++ b/app/Http/Controllers/ChangePasswordController.php @@ -0,0 +1,40 @@ +middleware('auth'); + } + + public function create() + { + return view('changePassword'); + } + + + public function update(Request $request) + { + $request->validate([ + 'current_password' => new ComparePasswords, + 'password' => 'required|confirmed|min:6|different:current_password', + ], + [ + 'required' => 'Podaj nowe hasło.', + 'confirmed' => 'Nowe hasło się nie zgadza.', + 'min' => ':attribute musi mieć przynajmniej :min znaków.', + 'different' => 'Stare i nowe hasło nie mogą być identyczne.' + ]); + + User::find(auth()->user()->id)->update(['password'=> $request-> password]); + + return redirect()->to('/userprofile')->with('success','Hasło zostało zmienione'); + } +} \ No newline at end of file diff --git a/app/Rules/ComparePasswords.php b/app/Rules/ComparePasswords.php new file mode 100644 index 0000000..b697935 --- /dev/null +++ b/app/Rules/ComparePasswords.php @@ -0,0 +1,41 @@ +user()->password); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Obecne hasło jest niepoprawne.'; + } +} diff --git a/resources/views/changePassword.blade.php b/resources/views/changePassword.blade.php new file mode 100644 index 0000000..7128616 --- /dev/null +++ b/resources/views/changePassword.blade.php @@ -0,0 +1,60 @@ +@extends('layout.app') + +@section('left-menu') + @parent + +@stop + +@section('center-area') +@parent +
+
+
+
+
Zmiana hasła
+ +
+
+ @csrf +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+
+ +
+
+ @include('inc.formerrors') +
+
+
+
+
+
+@stop \ No newline at end of file diff --git a/resources/views/userProfile.blade.php b/resources/views/userProfile.blade.php index b7c0688..b956bdb 100644 --- a/resources/views/userProfile.blade.php +++ b/resources/views/userProfile.blade.php @@ -12,6 +12,15 @@ @parent @if( auth()->check()) + + @if (\Session::has('success')) +
+ +
+ @endif +

diff --git a/resources/views/userProfileEdit.blade.php b/resources/views/userProfileEdit.blade.php index 2d8e1af..013c0ba 100644 --- a/resources/views/userProfileEdit.blade.php +++ b/resources/views/userProfileEdit.blade.php @@ -3,6 +3,7 @@ @section('left-menu') @parent @stop diff --git a/routes/web.php b/routes/web.php index 81fd1ce..75444b4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -83,6 +83,8 @@ Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxReq Route::get('/userprofile', 'userProfileController@create'); Route::get('/userprofile/edit', 'userProfileController@editForm'); Route::post('/userprofile/edit', 'userProfileController@update'); +Route::get('/userprofile/passwordchange', 'ChangePasswordController@create'); +Route::post('/userprofile/passwordchange', 'ChangePasswordController@update');; Route::get('register/verify/{confirmationCode}', [