diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 9b0ec4d..a5d21a5 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,7 +2,11 @@ namespace App\Http\Controllers; +use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Validator; class AdminController extends Controller { @@ -10,4 +14,43 @@ class AdminController extends Controller public function index() { return view('admin.index'); } + + // форма смены пароля + public function form_password() { + return view('admin.password'); + } + + //валидация смены пароля + public function validate_password(Request $request) { + + $rules = [ + 'old_password' => 'required|min:6', //|current_password:api', + 'password' => 'required|min:6|confirmed', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'confirmed' => 'Пароли не совпадают' + ]; + + $validator = Validator::make($request->all(), $rules, $messages); + + if (! Hash::check($request->old_password, $request->user()->password)) { + return back()->withErrors([ + 'old_password' => ['Неверный предыдущий пароль'] + ]); + } + + if ($validator->fails()) { + return redirect()->route('admin.form_password') + ->withErrors($validator); + } else { + $params = $request->all(); + // устанавливаем новый пароль для пользователя + User::where('id', Auth::id()) + ->update(['password' => Hash::make($request->password)]); + session()->flash('success', 'Успешно изменен пароль!'); + + return redirect()->route('admin.form_password'); + } + } } diff --git a/config/auth.php b/config/auth.php index d8c6cee..99922ab 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,6 +40,12 @@ return [ 'driver' => 'session', 'provider' => 'users', ], + + 'api' => [ + 'driver' => 'passport', + 'provider' => 'users', + 'hash' => true, + ], ], /* diff --git a/public/images/favicon.png b/public/images/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..cbd456b80f2d7e47c0e5b86d2f0159b5e97da8a6 GIT binary patch literal 326 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkQ1FMR zi(^Q|oUIcLy_gdPT7_9W6+4a?FWJC5lT*TT^;E?Pm$)Ntz3Dj{CYJP6R3|9n1*6EC zqTU2?6?cvwCpn~(C)SsnOwBt^}YFZzA&4=>U{U$IsGjM zjVv9{zsTtjPl|D2)BABDNB;jTW5cjVcgl^waoZIX1iqGDep0l`&Dt<=_m_^+$K18E WMZW%(kMIYE0fVQjpUXO@geCx6Zhj~L literal 0 HcmV?d00001 diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php index 27d2008..ce3e5b4 100644 --- a/resources/views/admin/index.blade.php +++ b/resources/views/admin/index.blade.php @@ -26,6 +26,7 @@ + diff --git a/resources/views/admin/password.blade.php b/resources/views/admin/password.blade.php new file mode 100644 index 0000000..530d1d7 --- /dev/null +++ b/resources/views/admin/password.blade.php @@ -0,0 +1,48 @@ +@extends('layout.admin', ['title' => 'Смена пароля']) + +@section('content') +
+
+
+ +

Смена пароля

+
+
+
+
+
+ @csrf + +
+ @error('old_password') +
{{ $message }}

+ @enderror +

+ +
+ @error('password') +
{{ $message }}

+ @enderror +

+ +
+ @error('password_confirmation') +
{{ $message }}

+ @enderror +

+ + + +
+
+
+
+@endsection diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index de276ae..cfe876d 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -24,6 +24,13 @@ + +
+ + +