From c84db52439fd511a8a13a49ce2325b815f00dc7f 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, 24 May 2023 20:55:04 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=20=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=B0=20=D0=B8?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BE=D0=B4=D0=B0=D1=82=D0=B5=D0?= =?UTF-8?q?=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/AdminController.php | 113 +++++++ app/Http/Controllers/Admin/EmployersController.php | 5 + app/Http/Controllers/Admin/WorkersController.php | 5 + app/Models/User.php | 4 +- resources/views/admin/employer/edit.blade.php | 320 ++++++++++++++++++++ resources/views/admin/employer/index.blade.php | 6 +- resources/views/admin/password.blade.php | 58 ++++ resources/views/admin/profile.blade.php | 5 +- resources/views/admin/users/index.blade.php | 2 + resources/views/admin/users/index_ajax.blade.php | 2 + resources/views/admin/users/profile.blade.php | 106 +++++++ resources/views/admin/worker/index.blade.php | 8 +- resources/views/layout/admin.blade.php | 26 ++ routes/web.php | 21 +- 14 files changed, 672 insertions(+), 9 deletions(-) create mode 100644 resources/views/admin/employer/edit.blade.php create mode 100644 resources/views/admin/password.blade.php create mode 100644 resources/views/admin/users/profile.blade.php create mode 100644 resources/views/admin/worker/edit.blade.php diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 30daf91..ea33764 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -162,6 +162,55 @@ class AdminController extends Controller } } + //Страница профиль пользователя - форма + public function profile_user(User $user) { + $visible = false; + if($user->is_worker) { + $caption = "Карточка работника"; + if (isset($user->workers[0]->id)) { + $link = route('admin.worker-profile', ['worker' => $user->workers[0]->id]); + $visible = true; + } else { + $link = ""; + } + + } else { + $caption = "Карточка работодателя"; + if (isset($user->employers[0]->id)) { + + $link = route('admin.employer-profile', ['employer' => $user->employers[0]->id]); + $visible = true; + } else { + $link = ""; + } + } + + return view('admin.users.profile', compact('user', 'visible', 'link', 'caption')); + } + + //Страница профиль пользователя - сохранение формы + public function store_profile_user(User $user, Request $request) { + $rules = [ + 'name' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'email' => 'Это поле должно быть определено, как Email' + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.user-profile', ['user' => $user->id]) + ->withErrors($validator); + } else { + $user->update($request->all()); + return redirect()->route('admin.user-profile', ['user' => $user->id]) + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.user-profile', ['user' => $user->id]); + } + + // Страница профиль админа - форма public function profile() { $id = Auth::user()->id; $user = User::find($id); @@ -169,18 +218,82 @@ class AdminController extends Controller return view('admin.profile', compact('user')); } + // Страница профиль админа - сохранение формы public function store_profile(Request $request) { $id = Auth::user()->id; $user = User::find($id); + $rules = [ + 'name' => 'required|min:3', + 'email' => 'required|email|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + 'email' => 'Это поле должно быть определено, как Email' + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.profile') + ->withErrors($validator); + } else { + $user->update($request->all()); + return redirect()->route('admin.profile') + ->with('success', 'Данные были успешно сохранены'); + } return redirect()->route('admin.profile'); } + // Форма смены пароля администоратора + public function profile_password() { + $id = Auth::user()->id; + $user = User::find($id); + $username = $user->name; + + return view('admin.password', compact('username')); + } + + // Сохранение формы смены пароля администоратора + public function profile_password_new(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.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.password'); + } + } + + // Страница конфигурация сайта - форма public function config_form() { $config = Company::find(1); return view('admin.config', compact('config')); } + // Страница конфигурация сайта - сохранение формы public function store_config(CompanyRequest $request) { $config = Company::find(1); diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index 8305025..1ecb86a 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Employer; use App\Models\User; use Illuminate\Http\Request; @@ -22,4 +23,8 @@ class EmployersController extends Controller return view('admin.employer.index', compact('users')); } } + + public function form_update_employer(Employer $employer) { + return view('admin.employer.edit', compact('employer')); + } } diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php index afa5294..dcc857f 100644 --- a/app/Http/Controllers/Admin/WorkersController.php +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\User; +use App\Models\Worker; use Illuminate\Http\Request; class WorkersController extends Controller @@ -23,4 +24,8 @@ class WorkersController extends Controller return view('admin.worker.index', compact('users')); } } + + public function form_update_worker(Worker $worker) { + return view('admin.worker.edit'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 99e5e2c..6d5de93 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -59,7 +59,7 @@ class User extends Authenticatable * users - employers */ public function employers() { - return $this->hasMany(Employer::class); + return $this->hasMany(Employer::class, 'user_id'); } /* @@ -67,7 +67,7 @@ class User extends Authenticatable * users - workers */ public function workers() { - return $this->hasMany(Worker::class); + return $this->hasMany(Worker::class, 'user_id'); } /* diff --git a/resources/views/admin/employer/edit.blade.php b/resources/views/admin/employer/edit.blade.php new file mode 100644 index 0000000..d9305b2 --- /dev/null +++ b/resources/views/admin/employer/edit.blade.php @@ -0,0 +1,320 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование работодателя']) + +@section('content') +

+ Работодатель-пользователь: "{{$employer->users->name_man}} ({{$employer->user_id}})" +

+
+ @csrf +
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+
+
+ + + + + + + + + +@endsection diff --git a/resources/views/admin/employer/index.blade.php b/resources/views/admin/employer/index.blade.php index b0154d3..9cb5f91 100644 --- a/resources/views/admin/employer/index.blade.php +++ b/resources/views/admin/employer/index.blade.php @@ -88,10 +88,14 @@ {{ $user->created_at }} - Изменить + @if ($user->id > 1) + Изменить + @endif + @if ($user->id > 1) is_ban) ? "checked" : "" }}/> + @endif @endforeach diff --git a/resources/views/admin/password.blade.php b/resources/views/admin/password.blade.php new file mode 100644 index 0000000..cabf635 --- /dev/null +++ b/resources/views/admin/password.blade.php @@ -0,0 +1,58 @@ +@extends('layout.admin', ['title' => 'Админка - Смена пароля']) + +@section('content') +

+ Вы в системе, как {{ $username }} +

+
+ @csrf +
+
+ +
+ +
+ +
+
+ +
+
+
+
+@endsection diff --git a/resources/views/admin/profile.blade.php b/resources/views/admin/profile.blade.php index 6175179..e1794a1 100644 --- a/resources/views/admin/profile.blade.php +++ b/resources/views/admin/profile.blade.php @@ -5,6 +5,7 @@ Личные данные
+ @csrf
diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index eb261e5..d887df4 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -127,7 +127,9 @@ @endif + @if ($user->id > 1) is_ban) ? "checked" : "" }}/> + @endif is_new) ? "checked" : "" }}/> diff --git a/resources/views/admin/users/index_ajax.blade.php b/resources/views/admin/users/index_ajax.blade.php index 8e70e27..e957eac 100644 --- a/resources/views/admin/users/index_ajax.blade.php +++ b/resources/views/admin/users/index_ajax.blade.php @@ -40,7 +40,9 @@ @endif + @if ($user->id > 1) is_ban) ? "checked" : "" }}/> + @endif is_new) ? "checked" : "" }}/> diff --git a/resources/views/admin/users/profile.blade.php b/resources/views/admin/users/profile.blade.php new file mode 100644 index 0000000..20c35de --- /dev/null +++ b/resources/views/admin/users/profile.blade.php @@ -0,0 +1,106 @@ +@extends('layout.admin', ['title' => 'Админка - Профиль '.$user->name]) + +@section('content') +

+ Личные данные пользователя "{{$user->name}} ({{$user->id}})" +

+ + @csrf +
+
+ + + +
+ +
+ +
+ +
+ + + +
+
+ +
+
+ @if ($visible==true) + + {{ $caption }} + + @endif +
+
+
+
+@endsection diff --git a/resources/views/admin/worker/edit.blade.php b/resources/views/admin/worker/edit.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/admin/worker/index.blade.php b/resources/views/admin/worker/index.blade.php index 5fa74b2..403a9ed 100644 --- a/resources/views/admin/worker/index.blade.php +++ b/resources/views/admin/worker/index.blade.php @@ -95,10 +95,14 @@ {{ $user->created_at }} - Изменить + @if ($user->id > 1) + Изменить + @endif - is_ban) ? "checked" : "" }}/> + @if ($user->id > 1) + is_ban) ? "checked" : "" }}/> + @endif @endforeach diff --git a/resources/views/layout/admin.blade.php b/resources/views/layout/admin.blade.php index 9e04338..c291e05 100644 --- a/resources/views/layout/admin.blade.php +++ b/resources/views/layout/admin.blade.php @@ -913,6 +913,32 @@ Список админов → + @if ($message = Session::get('success')) +
+ +
+ @endif + + @if ($errors->any()) +
+ +
+ @endif + @yield('content')