Blame view
app/Http/Controllers/Auth/RegisterController.php
2.61 KB
02a1ed535 Первый коммит Rek... |
1 2 3 4 5 6 7 |
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; use App\Models\User; |
6a962b009 Система авторизац... |
8 9 |
use Illuminate\Http\Request; use Illuminate\Auth\Events\Registered; |
02a1ed535 Первый коммит Rek... |
10 |
use Illuminate\Foundation\Auth\RegistersUsers; |
6a962b009 Система авторизац... |
11 |
use Illuminate\Http\JsonResponse; |
02a1ed535 Первый коммит Rek... |
12 |
use Illuminate\Support\Facades\Hash; |
6a962b009 Система авторизац... |
13 |
use Illuminate\Support\Facades\Mail; |
02a1ed535 Первый коммит Rek... |
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
use Illuminate\Support\Facades\Validator; class RegisterController extends Controller { /* |-------------------------------------------------------------------------- | Register Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users as well as their | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | */ use RegistersUsers; /** * Where to redirect users after registration. * * @var string */ |
6a962b009 Система авторизац... |
36 |
protected $redirectTo = RouteServiceProvider::LOGIN; |
02a1ed535 Первый коммит Rek... |
37 38 39 40 41 42 |
/** * Create a new controller instance. * * @return void */ |
6a962b009 Система авторизац... |
43 44 |
public function register(Request $request) |
02a1ed535 Первый коммит Rek... |
45 |
{ |
6a962b009 Система авторизац... |
46 47 48 49 50 51 52 53 54 55 56 57 58 |
$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); |
02a1ed535 Первый коммит Rek... |
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
} /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return \App\Models\User */ protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); } protected function registered(Request $request, $user) { |
6a962b009 Система авторизац... |
92 |
return redirect()->route('login') |
02a1ed535 Первый коммит Rek... |
93 94 95 |
->with('success', 'Регистрация прошла успешно'); } } |