Blame view

app/Http/Controllers/Auth/LoginController.php 2.36 KB
02a1ed535   Андрей Ларионов   Первый коммит Rek...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  <?php
  
  namespace App\Http\Controllers\Auth;
  
  use App\Http\Controllers\Controller;
  use App\Providers\RouteServiceProvider;
  use Illuminate\Foundation\Auth\AuthenticatesUsers;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Auth;
  
  class LoginController extends Controller
  {
      /*
      |--------------------------------------------------------------------------
      | Login Controller
      |--------------------------------------------------------------------------
      |
      | This controller handles authenticating users for the application and
      | redirecting them to your home screen. The controller uses a trait
      | to conveniently provide its functionality to your applications.
      |
      */
  
      use AuthenticatesUsers;
  
      /**
       * Where to redirect users after login.
       *
       * @var string
       */
      protected $redirectTo = RouteServiceProvider::HOME;
  
      /**
       * Create a new controller instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this->middleware('guest')->except('logout');
      }
  
      public function showLoginForm()
      {
          return view('auth.login');
      }
  
      public function login(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()
6a962b009   Андрей Ларионов   Система авторизац...
60
                      ->route('login')
02a1ed535   Андрей Ларионов   Первый коммит Rek...
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
                      ->withErrors('Адрес почты не подтвержден');
              }
  
              return redirect()
                  ->route('home')
                  ->with('success', 'Вы вошли в личный кабинет.');
          }
  
          return redirect()
              ->route('login')
              ->withErrors('Неверный логин или пароль!');
      }
  
      protected function authenticated(Request $request, $user) {
          return redirect()->route('home')
              ->with('success', 'Вы успешно вошли в кабинет');
      }
  
      protected function loggedOut(Request $request) {
          return redirect()->route('login')
              ->with('success', 'Вы успешно вышли из кабинета');
      }
  
  
  }