Commit 0a94fb81dd67d8e1c0f0a292ac095389a7b637cc

Authored by Андрей Ларионов
1 parent d2e30108c8
Exists in master

Админка - форма редактирования пароля и редактирование контроллера AdminController

Showing 10 changed files with 118 additions and 1 deletions Side-by-side Diff

app/Http/Controllers/AdminController.php
... ... @@ -2,7 +2,11 @@
2 2  
3 3 namespace App\Http\Controllers;
4 4  
  5 +use App\Models\User;
5 6 use Illuminate\Http\Request;
  7 +use Illuminate\Support\Facades\Auth;
  8 +use Illuminate\Support\Facades\Hash;
  9 +use Illuminate\Support\Facades\Validator;
6 10  
7 11 class AdminController extends Controller
8 12 {
... ... @@ -10,4 +14,43 @@ class AdminController extends Controller
10 14 public function index() {
11 15 return view('admin.index');
12 16 }
  17 +
  18 + // форма смены пароля
  19 + public function form_password() {
  20 + return view('admin.password');
  21 + }
  22 +
  23 + //валидация смены пароля
  24 + public function validate_password(Request $request) {
  25 +
  26 + $rules = [
  27 + 'old_password' => 'required|min:6', //|current_password:api',
  28 + 'password' => 'required|min:6|confirmed',
  29 + ];
  30 + $messages = [
  31 + 'required' => 'Укажите обязательное поле',
  32 + 'confirmed' => 'Пароли не совпадают'
  33 + ];
  34 +
  35 + $validator = Validator::make($request->all(), $rules, $messages);
  36 +
  37 + if (! Hash::check($request->old_password, $request->user()->password)) {
  38 + return back()->withErrors([
  39 + 'old_password' => ['Неверный предыдущий пароль']
  40 + ]);
  41 + }
  42 +
  43 + if ($validator->fails()) {
  44 + return redirect()->route('admin.form_password')
  45 + ->withErrors($validator);
  46 + } else {
  47 + $params = $request->all();
  48 + // устанавливаем новый пароль для пользователя
  49 + User::where('id', Auth::id())
  50 + ->update(['password' => Hash::make($request->password)]);
  51 + session()->flash('success', 'Успешно изменен пароль!');
  52 +
  53 + return redirect()->route('admin.form_password');
  54 + }
  55 + }
13 56 }
... ... @@ -40,6 +40,12 @@ return [
40 40 'driver' => 'session',
41 41 'provider' => 'users',
42 42 ],
  43 +
  44 + 'api' => [
  45 + 'driver' => 'passport',
  46 + 'provider' => 'users',
  47 + 'hash' => true,
  48 + ],
43 49 ],
44 50  
45 51 /*
public/images/favicon.png

326 Bytes

resources/views/admin/index.blade.php
... ... @@ -26,6 +26,7 @@
26 26 <li class="breadcrumbs__item"><a class="breadcrumbs__link" href="{{ route('admin.formatarea.index') }}">Форматы недвижимости</a></li>
27 27 <li class="breadcrumbs__item"><a class="breadcrumbs__link" href="{{ route('admin.message.index') }}">Сообщения</a></li>
28 28 <li class="breadcrumbs__item"><a class="breadcrumbs__link" href="{{ route('admin.houses.index') }}">Офисы</a></li>
  29 + <li class="breadcrumbs__item"><a class="breadcrumbs__link" href="{{ route('admin.form_password') }}">Пароль</a></li>
29 30 </ul>
30 31 </div>
31 32 </div>
resources/views/admin/password.blade.php
... ... @@ -0,0 +1,48 @@
  1 +@extends('layout.admin', ['title' => 'Смена пароля'])
  2 +
  3 +@section('content')
  4 + <section class="favorites">
  5 + <div class="favorites-top">
  6 + <div class="container">
  7 + <div class="breadcrumbs">
  8 + <ul class="breadcrumbs__list">
  9 + <li class="breadcrumbs__item"><a class="breadcrumbs__link" href="{{ route('user.index') }}">Главная</a></li>
  10 + <li class="breadcrumbs__item"><span class="breadcrumbs__link">Смена пароля </span></li>
  11 + </ul>
  12 + </div>
  13 + <h1 class="favorites__title title-main">Смена пароля</h1>
  14 + </div>
  15 + </div>
  16 + <div class="favorites-cnt">
  17 + <div class="container">
  18 + <form method="post" action="{{ route('admin.validate_password')}}" style="width:100%">
  19 + @csrf
  20 +
  21 + <label for="old_password">Старый пароль: <span class="req">*</span></label><br>
  22 + @error('old_password')
  23 + <div class="alert alert-danger">{{ $message }}</div><br>
  24 + @enderror
  25 + <input type="text" class="form-control_ txt" name="old_password" placeholder="Старый пароль"
  26 + required maxlength="100" style="width: 80%" value=""><br><br>
  27 +
  28 + <label for="new_password">Новый пароль: <span class="req">*</span></label><br>
  29 + @error('password')
  30 + <div class="alert alert-danger">{{ $message }}</div><br>
  31 + @enderror
  32 + <input type="password" class="form-control_ txt" name="password" placeholder="Новый пароль"
  33 + required maxlength="100" style="width: 80%" value=""><br><br>
  34 +
  35 + <label for="new_password2">Новый пароль (еще раз): <span class="req">*</span></label><br>
  36 + @error('password_confirmation')
  37 + <div class="alert alert-danger">{{ $message }}</div><br>
  38 + @enderror
  39 + <input type="password" class="form-control_ txt" name="password_confirmation" placeholder="Новый пароль (еще раз)"
  40 + required maxlength="100" style="width: 80%" value=""><br><br>
  41 +
  42 + <button type="submit" class="btn hero-search__btn btn--main">Сохранить</button>
  43 +
  44 + </form>
  45 + </div>
  46 + </div>
  47 + </section>
  48 +@endsection
resources/views/auth/login.blade.php
... ... @@ -24,6 +24,13 @@
24 24 <input type="text" class="form-control" name="password" placeholder="Ваш пароль"
25 25 required maxlength="255" value="">
26 26 </label>
  27 +
  28 + <div class="form-group form-check">
  29 + <input type="checkbox" class="form-check-input" name="remember" id="remember">
  30 + <label class="form-check-label" for="remember">
  31 + Запомнить меня
  32 + </label>
  33 + </div>
27 34 </div>
28 35 <div class="footer-feedback__col">
29 36  
resources/views/catalogs/house_mini.blade.php
... ... @@ -42,6 +42,9 @@
42 42 case 'Арендованные':
43 43 $comment = "<span>в месяц</span>";
44 44 break;
  45 + default:
  46 + $comment = "<span>в месяц</span>";
  47 + break;
45 48 }
46 49 ?>
47 50 <div class="card__price"><span>{{ $house->price }} ₽ </span><? echo $comment; ?>
resources/views/layout/admin.blade.php
... ... @@ -90,7 +90,8 @@
90 90 <li class="nav__item"><a class="nav__link" href="{{ route('admin.formatarea.index') }}">Форматы</a></li>
91 91 <li class="nav__item"><a class="nav__link" href="{{ route('admin.message.index') }}">Сообщения</a></li>
92 92 <li class="nav__item"><a class="nav__link" href="{{ route('admin.houses.index') }}">Офисы</a></li>
93   -
  93 + <li class="nav__item"><a class="nav__link" href="{{ route('admin.form_password') }}">Пароль</a></li>
  94 + <li class="nav__item"><a class="nav__link btn_ hero-search__btn_ btn--main_" href="{{ route('auth.logout') }}">Выйти</a></li>
94 95 </ul>
95 96 </nav>
96 97 <div class="header__buttons"><a class="header__btn-phone" href="#" data-btn="feedback">
... ... @@ -120,6 +121,8 @@
120 121 <li class="menu__item"><a class="menu__link" href="{{ route('admin.formatarea.index') }}">Форматы недвижимости</a></li>
121 122 <li class="menu__item"><a class="menu__link" href="{{ route('admin.message.index') }}">Сообщения</a></li>
122 123 <li class="menu__item"><a class="menu__link" href="{{ route('admin.houses.index') }}">Офисы</a></li>
  124 + <li class="menu__item"><a class="menu__link" href="{{ route('admin.form_password') }}">Пароль</a></li>
  125 + <li class="menu__item"><a class="btn hero-search__btn btn--main" href="{{ route('auth.logout') }}">Выйти</a></li>
123 126 </ul>
124 127 </nav>
125 128 <div class="menu__contacts"><a class="menu__contact" href="mailto:info@renttorg.ru">E-MAIL<span>info@renttorg.ru</span></a><a class="menu__contact" href="tel:+79290127262">ТЕЛЕФОН<span>+7 (929) 012-72-62</span></a></div>
resources/views/layout/site.blade.php
... ... @@ -5,6 +5,7 @@
5 5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 7 <title>{{$title}}</title>
  8 + <link rel="shortcut icon" href="{{ asset('images/favicon.png')}}" type="image/x-icon">
8 9 <link rel="preload" href="{{ asset('fonts/Manrope-ExtraLight.woff2') }}" as="font" type="font/woff2" crossorigin>
9 10 <link rel="preload" href="{{ asset('fonts/Manrope-Light.woff2" as="font') }}" type="font/woff2" crossorigin>
10 11 <link rel="preload" href="{{ asset('fonts/Manrope-Regular.woff2') }}" as="font" type="font/woff2" crossorigin>
... ... @@ -205,4 +205,9 @@ Route::group([
205 205 // удаление дополнительной картинки офиса
206 206 Route::get('houses/{house}/del/{id}/images', [HousesController::class, 'del_images'])->name('del.images.houses');
207 207  
  208 + //Форма смены пароля пользователя
  209 + Route::get('user/password', [AdminController::class, 'form_password'])->name('form_password');
  210 +
  211 + //Смена пароля пользователя
  212 + Route::post('user/password', [AdminController::class, 'validate_password'])->name('validate_password');
208 213 });