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')