From 0a94fb81dd67d8e1c0f0a292ac095389a7b637cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Wed, 22 Mar 2023 20:11:53 +0700 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0=20-=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1?= =?UTF-8?q?=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D1=8F=20=D0=B8=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0?= =?UTF-8?q?=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0=20Admin?= =?UTF-8?q?Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AdminController.php | 43 ++++++++++++++++++++++ config/auth.php | 6 ++++ public/images/favicon.png | Bin 0 -> 326 bytes resources/views/admin/index.blade.php | 1 + resources/views/admin/password.blade.php | 48 +++++++++++++++++++++++++ resources/views/auth/login.blade.php | 7 ++++ resources/views/catalogs/house_mini.blade.php | 3 ++ resources/views/layout/admin.blade.php | 5 ++- resources/views/layout/site.blade.php | 1 + routes/web.php | 5 +++ 10 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 public/images/favicon.png create mode 100644 resources/views/admin/password.blade.php 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 @@ + +
+ + +