From d65c792256657c6d4e7dd352539d28a9fcdf608e 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: Tue, 7 Mar 2023 16:19:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BD=D0?= =?UTF-8?q?=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20=D0=BA=D0?= =?UTF-8?q?=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D1=8F=20=D0=B8=20=D1=81=D0?= =?UTF-8?q?=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D1=81=D0=B0?= =?UTF-8?q?=D0=B9=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .htaccess | 5 +++ app/Http/Controllers/AdminController.php | 13 +++++++ app/Http/Controllers/LoginController.php | 52 ++++++++++++++++++++++++++ app/Http/Controllers/MainController.php | 5 ++- app/Http/Controllers/RegisterController.php | 39 +++++++++++++++++++ resources/views/admin/index.blade.php | 7 ++++ resources/views/auth/login-copy.blade.php | 45 ++++++++++++++++++++++ resources/views/auth/login.blade.php | 45 ++++++++++++++++++++++ resources/views/auth/register-copy.blade.php | 52 ++++++++++++++++++++++++++ resources/views/auth/register.blade.php | 52 ++++++++++++++++++++++++++ resources/views/category_catalog.blade.php | 8 +++- resources/views/layout/site.blade.php | 22 +++++++++++ routes/web.php | 37 ++++++++++++++++++ 13 files changed, 378 insertions(+), 4 deletions(-) create mode 100644 .htaccess create mode 100644 app/Http/Controllers/AdminController.php create mode 100644 app/Http/Controllers/LoginController.php create mode 100644 app/Http/Controllers/RegisterController.php create mode 100644 resources/views/admin/index.blade.php create mode 100644 resources/views/auth/login-copy.blade.php create mode 100644 resources/views/auth/login.blade.php create mode 100644 resources/views/auth/register-copy.blade.php create mode 100644 resources/views/auth/register.blade.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..c5563e9 --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ + + RewriteEngine on + RewriteCond %{REQUEST_URI} !^public + RewriteRule ^(.*)$ public/$1 [L] + \ No newline at end of file diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php new file mode 100644 index 0000000..9b0ec4d --- /dev/null +++ b/app/Http/Controllers/AdminController.php @@ -0,0 +1,13 @@ +middleware('guest')->except('logout'); + } + + //Форма входа + public function login() { + return view('auth.login'); + } + + // Аутентификация + public function autenticate(Request $request) { + $request->validate([ + 'email' => 'required|string|email', + 'password' => 'required|string', + ]); + + $credentials = $request->only('email', 'password'); + + if (Auth::attempt($credentials, $request->has('remember'))) { + if (is_null(Auth::user()->email_verified_at)){ + Auth::logout(); + return redirect() + ->route('auth.vefiry-message') + ->withErrors('Адрес почты не подтвержден'); + } + + return redirect() + ->route('user.index') + ->with('success', 'Вы вошли в личный кабинет.'); + } + + return redirect() + ->route('auth.login') + ->withErrors('Неверный логин или пароль!'); + } + + // Выход + public function logout() { + Auth::logout(); + return redirect()->route('index') + ->with('success', 'Вы вышли из личного кабинета'); + } +} diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 413a8a5..544f704 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -190,7 +190,7 @@ class MainController extends Controller /* * Категории каталога Аренда/Продажа/Бизнес */ - public function Category($cat) { + public function Category($cat, Request $request) { switch ($cat) { case 'arenda': $title = "Аренда торговых помещениий"; @@ -211,7 +211,8 @@ class MainController extends Controller } $houses = House::with('areas')-> - where('format_house', '=', $format_house)->get(); + where('format_house', '=', $format_house)->paginate(4)->appends(request()->query()); + //->appends(request()->query()); return view('category_catalog', compact('title', 'houses')); } diff --git a/app/Http/Controllers/RegisterController.php b/app/Http/Controllers/RegisterController.php new file mode 100644 index 0000000..d505086 --- /dev/null +++ b/app/Http/Controllers/RegisterController.php @@ -0,0 +1,39 @@ +middleware('guest'); + } + + // Форма регистрации + public function register() { + return view('auth.register'); + } + + // Создание пользователя + public function create(Request $request) { + $request->validate([ + 'name' => 'required|string|max:255', + 'email' => 'required|string|email|max:255|unique:users', + 'password' => 'required|string|min:8|confirmed', + ]); + + User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'password' => Hash::make($request->password), + ]); + + return redirect() + ->route('auth.login') + ->with('success', 'Вы успешно зарегистрировались'); + } +} diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php new file mode 100644 index 0000000..e2c0f81 --- /dev/null +++ b/resources/views/admin/index.blade.php @@ -0,0 +1,7 @@ +@extends('layout.site', ['title' => 'Личный кабинет']) + +@section('content') +

Личный кабинет

+

Добрый день {{ auth()->user()->name }}!

+

Это личный кабинет пользователя сайта.

+@endsection diff --git a/resources/views/auth/login-copy.blade.php b/resources/views/auth/login-copy.blade.php new file mode 100644 index 0000000..a29a20a --- /dev/null +++ b/resources/views/auth/login-copy.blade.php @@ -0,0 +1,45 @@ +@extends('layout.site', ['title' => 'Вход в личный кабинет']) + +@section('content') +
+
+
+ + + +
+
+
+@endsection diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php new file mode 100644 index 0000000..de276ae --- /dev/null +++ b/resources/views/auth/login.blade.php @@ -0,0 +1,45 @@ +@extends('layout.site', ['title' => 'Вход в личный кабинет']) + +@section('content') +
+
+
+ + + +
+
+
+@endsection diff --git a/resources/views/auth/register-copy.blade.php b/resources/views/auth/register-copy.blade.php new file mode 100644 index 0000000..80f3017 --- /dev/null +++ b/resources/views/auth/register-copy.blade.php @@ -0,0 +1,52 @@ +@extends('layout.site', ['title' => 'Регистрация']) + +@section('content') +
+
+
+ + +
+
+
+@endsection diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php new file mode 100644 index 0000000..d511064 --- /dev/null +++ b/resources/views/auth/register.blade.php @@ -0,0 +1,52 @@ +@extends('layout.site', ['title' => 'Регистрация']) + +@section('content') +
+
+
+ + +
+
+
+@endsection diff --git a/resources/views/category_catalog.blade.php b/resources/views/category_catalog.blade.php index 7c3a3e6..726c221 100644 --- a/resources/views/category_catalog.blade.php +++ b/resources/views/category_catalog.blade.php @@ -569,7 +569,10 @@ --> diff --git a/resources/views/layout/site.blade.php b/resources/views/layout/site.blade.php index cd6f5ce..4184110 100644 --- a/resources/views/layout/site.blade.php +++ b/resources/views/layout/site.blade.php @@ -79,6 +79,28 @@
+ @if ($message = Session::get('success')) + + @endif + + @if ($errors->any()) + + @endif + @yield('filter') diff --git a/routes/web.php b/routes/web.php index 180d7ec..d2c8df6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,11 @@ name('category'); + + +Route::group([ + 'as' => 'auth.', // имя маршрута, например auth.index + 'prefix' => 'auth', // префикс маршрута, например auth/index +], function () { +// Форма регистрации + Route::get('register', [RegisterController::class, 'register'])->name('register'); + +// Создание пользователя + Route::post('register', [RegisterController::class, 'create'])->name('create'); +//Форма входа + Route::get('login', [LoginController::class, 'login'])->name('login'); + +// аутентификация + Route::post('login', [LoginController::class, 'autenticate'])->name('auth'); + +// выход + Route::get('logout', [LoginController::class, 'logout'])->name('logout'); +}); + +/* + * Личный кабинет пользователя + */ +Route::group([ + 'as' => 'user.', // имя маршрута, например user.index + 'prefix' => 'user', // префикс маршрута, например user/index + //'namespace' => 'User', // пространство имен контроллеров + 'middleware' => ['auth'] // один или несколько посредников +], function () { + // главная страница + Route::get('index', [AdminController::class, 'index'])->name('index'); +}); -- 1.7.10.4