From 6a962b0098a06283a7805c9d68d9fbc580abeffe 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: Mon, 25 Sep 2023 16:47:18 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0?= =?UTF-8?q?=B8=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8,=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0?= =?UTF-8?q?=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=B0=20=D0=B7=D0=B0=D0=B4=D0=B5=D1?= =?UTF-8?q?=80=D0=B6=D0=BA=D0=B8=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Auth/ForgotPasswordController.php | 44 +++++- app/Http/Controllers/Auth/LoginController.php | 2 +- app/Http/Controllers/Auth/RegisterController.php | 26 +++- .../Controllers/Auth/VerifyEmailController.php | 41 ++++++ app/Providers/RouteServiceProvider.php | 2 + composer.json | 5 +- composer.lock | 152 +++++++++++++++++++- config/app.php | 1 + resources/views/auth/login.blade.php | 2 +- resources/views/auth/passwords/confirm.blade.php | 2 +- resources/views/auth/passwords/email.blade.php | 2 +- resources/views/auth/passwords/reset.blade.php | 2 +- resources/views/auth/register.blade.php | 14 +- resources/views/auth/verify.blade.php | 2 +- resources/views/home.blade.php | 2 +- resources/views/layouts/app.blade.php | 37 +++-- resources/views/layouts/app2.blade.php | 80 +++++++++++ routes/web.php | 48 +++++++ storage/debugbar/.gitignore | 2 + 19 files changed, 432 insertions(+), 34 deletions(-) create mode 100644 app/Http/Controllers/Auth/VerifyEmailController.php create mode 100644 resources/views/layouts/app2.blade.php create mode 100644 storage/debugbar/.gitignore diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 465c39c..eefc765 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -4,6 +4,11 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; +use Illuminate\Http\Request; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Str; class ForgotPasswordController extends Controller { @@ -18,5 +23,42 @@ class ForgotPasswordController extends Controller | */ - use SendsPasswordResetEmails; + //use SendsPasswordResetEmails; + + public function __construct(){ + $this->middleware('guest'); + } + + public function form() { + return view('auth.forgot'); + } + + public function mail(Request $request) { + $request->validate([ + 'email' => 'required|email|exists:users', + ]); + + + $token = Str::random(60); + DB::table('password_resets')->insert( + ['email' => $request->email, + 'token' => $token, + 'created_at' => Carbon::now()] + ); + + //ссылка для сброса пароля + $link = route('auth.reset-form', + ['token' => $token, 'email' => $request->email] + ); + + Mail::send('email.reset-password', + ['link' => base64_encode($link)], + function($message) use ($request) { + $message->to($request->email); + $message->subject('Repair password'); + } + ); + + return back()->with('success', 'Ссылка для восстановления пароля отправлена на почту!'); + } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 817ec26..ed5b384 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -57,7 +57,7 @@ class LoginController extends Controller if (is_null(Auth::user()->email_verified_at)){ Auth::logout(); return redirect() - ->route('auth.vefiry') + ->route('login') ->withErrors('Адрес почты не подтвержден'); } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index b303d75..96a3442 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -5,9 +5,12 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; use App\Models\User; -use http\Env\Request; +use Illuminate\Http\Request; +use Illuminate\Auth\Events\Registered; use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Validator; class RegisterController extends Controller @@ -30,16 +33,29 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = RouteServiceProvider::LOGIN; /** * Create a new controller instance. * * @return void */ - public function __construct() + + public function register(Request $request) { - $this->middleware('guest'); + $this->validator($request->all())->validate(); + + event(new Registered($user = $this->create($request->all()))); + + //$this->Auth::guard()->login($user); + + if ($response = $this->registered($request, $user)) { + return $response; + } + + return $request->wantsJson() + ? new JsonResponse([], 201) + : redirect($this->redirectTo); } /** @@ -73,7 +89,7 @@ class RegisterController extends Controller } protected function registered(Request $request, $user) { - return redirect()->route('home') + return redirect()->route('login') ->with('success', 'Регистрация прошла успешно'); } } diff --git a/app/Http/Controllers/Auth/VerifyEmailController.php b/app/Http/Controllers/Auth/VerifyEmailController.php new file mode 100644 index 0000000..d5b07e6 --- /dev/null +++ b/app/Http/Controllers/Auth/VerifyEmailController.php @@ -0,0 +1,41 @@ +middleware('guest'); + } + + public function message() { + return view('auth.verify-message'); + } + + // Активация аккаунта после перехода по ссылке + public function verify($token, $id) { + //удаляем пользователей, которые не подтвердили почту + $expire = Carbon::now()->subMinute(60); + User::whereNull('email_verified_at')->where('created_at', '<', $expire)->delete(); + //пробуем найти пользователя по идентификатору + $user = User::find($id); + $condition = $user && md5($user->email . $user->name) === $token; + if (!$condition) { + return redirect() + ->route('auth.register') + ->withErrors('Ссылка для проверки адреса почты устарела'); + } + + //если же все проверки пройдены, активируем аккаунт + $user->update(['email_verified_at' => Carbon::now()]); + // назначаем роль для нового пользователя + //$user->assignRoles('user'); + return redirect() + ->route('auth.login') + ->with('success', 'Вы успешно подтвердили свой адрес почты'); + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index ea87f2e..843dd92 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -19,6 +19,8 @@ class RouteServiceProvider extends ServiceProvider */ public const HOME = '/home'; + public const LOGIN = '/login'; + /** * Define your route model bindings, pattern filters, and other route configuration. * diff --git a/composer.json b/composer.json index 5593579..7b34e17 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,11 @@ "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7", - "laravel/ui": "^4.2", - "ext-http": "*" + "laravel/ui": "^4.2" + }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.9", "fakerphp/faker": "^1.9.1", "laravel/pint": "^1.0", "laravel/sail": "^1.0.1", diff --git a/composer.lock b/composer.lock index 9b2eb4f..282228a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8f2edd1901e6d484b1afa0894c1e2244", + "content-hash": "20183a94ace5a057147d8f922629489d", "packages": [ { "name": "akaunting/laravel-money", @@ -6568,6 +6568,90 @@ ], "packages-dev": [ { + "name": "barryvdh/laravel-debugbar", + "version": "v3.9.2", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "bfd0131c146973cab164e50f5cdd8a67cc60cab1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/bfd0131c146973cab164e50f5cdd8a67cc60cab1", + "reference": "bfd0131c146973cab164e50f5cdd8a67cc60cab1", + "shasum": "" + }, + "require": { + "illuminate/routing": "^9|^10", + "illuminate/session": "^9|^10", + "illuminate/support": "^9|^10", + "maximebf/debugbar": "^1.18.2", + "php": "^8.0", + "symfony/finder": "^6" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench-dusk": "^5|^6|^7|^8", + "phpunit/phpunit": "^8.5.30|^9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.8-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-debugbar/issues", + "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.9.2" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2023-08-25T18:43:57+00:00" + }, + { "name": "doctrine/instantiator", "version": "1.5.0", "source": { @@ -6959,6 +7043,72 @@ "time": "2023-05-04T14:52:56+00:00" }, { + "name": "maximebf/debugbar", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30f65f18f7ac086255a77a079f8e0dcdd35e828e", + "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e", + "shasum": "" + }, + "require": { + "php": "^7.1|^8", + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^4|^5|^6" + }, + "require-dev": { + "phpunit/phpunit": ">=7.5.20 <10.0", + "twig/twig": "^1.38|^2.7|^3.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "support": { + "issues": "https://github.com/maximebf/php-debugbar/issues", + "source": "https://github.com/maximebf/php-debugbar/tree/v1.19.0" + }, + "time": "2023-09-19T19:53:10+00:00" + }, + { "name": "mockery/mockery", "version": "1.5.1", "source": { diff --git a/config/app.php b/config/app.php index 63f3b5c..d6aa8e3 100644 --- a/config/app.php +++ b/config/app.php @@ -195,6 +195,7 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, App\Providers\MyServiceProvider::class, + Barryvdh\Debugbar\ServiceProvider::class, ], /* diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index ea9ac94..79d0029 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Авторизация']) @section('content')
diff --git a/resources/views/auth/passwords/confirm.blade.php b/resources/views/auth/passwords/confirm.blade.php index f8c8e61..bd5fd89 100644 --- a/resources/views/auth/passwords/confirm.blade.php +++ b/resources/views/auth/passwords/confirm.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Потверждение пароля']) @section('content')
diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index d1ac783..04be9ab 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Сброс пароля']) @section('content')
diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index dccf6c6..2c034b2 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Обновление пароля']) @section('content')
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 12cad1a..2ab5406 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,18 +1,18 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Регистрация']) @section('content')
-
{{ __('Register') }}
+
@csrf
- +
@@ -26,7 +26,7 @@
- +
@@ -40,7 +40,7 @@
- +
@@ -54,7 +54,7 @@
- +
@@ -64,7 +64,7 @@
diff --git a/resources/views/auth/verify.blade.php b/resources/views/auth/verify.blade.php index b557675..59d297d 100644 --- a/resources/views/auth/verify.blade.php +++ b/resources/views/auth/verify.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Верификация']) @section('content')
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 1f34466..67c8340 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('layouts.app', ['title' => 'Личный кабинет']) @section('content')
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index a30c2d4..aaa4bbf 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -7,25 +7,18 @@ - {{ config('app.name', 'Laravel') }} - - - - - - - + {{ $title }} -
+
+ @if ($message = Session::get('success')) + + @endif + + @if ($errors->any()) + + @endif + @yield('content')
diff --git a/resources/views/layouts/app2.blade.php b/resources/views/layouts/app2.blade.php new file mode 100644 index 0000000..59f5c72 --- /dev/null +++ b/resources/views/layouts/app2.blade.php @@ -0,0 +1,80 @@ + + + + + + + + + + Ларавел + + + + + + + + + +
+ + +
+ @yield('content') +
+
+ + diff --git a/routes/web.php b/routes/web.php index 25f34b2..cd60e48 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Admin\InfoBloksController; use App\Http\Controllers\Admin\JobTitlesController; use App\Http\Controllers\Admin\UsersController; use App\Http\Controllers\Admin\WorkersController; +use App\Http\Controllers\Auth\ForgotPasswordController; use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\RegisterController; use App\Http\Controllers\CKEditorController; @@ -41,6 +42,53 @@ Route::get('/', [MainController::class, 'index'])->name('index'); //Роуты авторизации, регистрации, восстановления, аутентификации Auth::routes(['verify' => true]); + +// роуты регистрации, авторизации, восстановления пароля, верификации почты +/*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, 'authenticate'])->name('auth'); + + //выход + Route::get('logout', [LoginController::class, 'logout'])->name('logout'); + + //форма ввода адреса почты + Route::get('forgot-password', [ForgotPasswordController::class, 'form'])->name('forgot-form'); + + //письмо на почту + Route::post('forgot-password', [ForgotPasswordController::class, 'mail'])->name('forgot-mail'); + + //форма восстановления пароля + Route::get('reset-password/token/{token}/email/{email}', + [ResetPasswordController::class, 'form'] + )->name('reset-form'); + + //восстановление пароля + Route::post('reset-password', + [ResetPasswordController::class, 'reset'] + )->name('reset-password'); + + //сообщение о необходимости проверки адреса почты + Route::get('verify-message', [VerifyEmailController::class, 'message'])->name('verify-message'); + + //подтверждение адреса почты нового пользователя + Route::get('verify-email/token/{token}/id/{id}', [VerifyEmailController::class, 'verify']) + ->where('token', '[a-f0-9]{32}') + ->where('id', '[0-9]+') + ->name('verify-email'); +});*/ + //Личный кабинет пользователя Route::get('/home', [HomeController::class, 'index'])->name('home'); diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore -- 1.7.10.4