source: app/Http/Controllers/Auth/LoginController.php@ e756bd9

develop
Last change on this file since e756bd9 was 1c25bcf, checked in by Berat Kjufliju <kufliju@…>, 3 years ago

added 2fa, bug fixes, edited blades

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[7304c7f]1<?php
2
3namespace App\Http\Controllers\Auth;
4
[1c25bcf]5use App\Helpers\Alert;
[7304c7f]6use App\Http\Requests\Auth\LoginRequest;
7use App\Models\User;
8use App\Http\Controllers\Controller;
[1c25bcf]9use App\Notifications\VerifyUser;
10use App\Services\Hashid;
[7304c7f]11use Illuminate\Support\Facades\Hash;
[1c25bcf]12use Illuminate\Support\Str;
[7304c7f]13
14class LoginController extends Controller
15{
[1c25bcf]16 protected $redirectTo = '/';
[7304c7f]17
18 public function __construct()
19 {
20 $this->middleware("guest")->except('logout');
21 }
22
23 public function showLogin()
24 {
25 return view("auth.login");
26 }
27
[1c25bcf]28 public function login(LoginRequest $request, Hashid $hashid)
[7304c7f]29 {
30 $user = User::whereUsername($request->username)->first();
31
[1c25bcf]32 if (is_null($user)) {
33 Alert::flash("Please check your credentials", "error");
34 return redirect()->route("auth.login");
[7304c7f]35 }
36
[1c25bcf]37 if (!$user->is_active) {
38 Alert::flash("Your account is blocked or its not confirmed yet. Please contact with your system administrator or check your email.", "error");
39 return redirect()->route("auth.login");
[7304c7f]40 }
41
[1c25bcf]42 if (!Hash::check($request->password, $user->password)) {
43 Alert::flash("Your password is incorrect", "error");
44 return redirect()->route("auth.login");
[7304c7f]45 }
46
[1c25bcf]47 //$user->security_code = rand(10000, 99999);
[7304c7f]48 if ($user->is_forgot_password) {
49 $user->is_forgot_password = false;
50 }
51
[1c25bcf]52 $user->security_code = 1234;
53 $user->verify_token = Str::uuid();
54 $user->is_online = true;
55 $user->save();
56
57 $user->notify(new VerifyUser($user));
[7304c7f]58
[1c25bcf]59 return redirect()->route("verify-login.index", [
60 "id" => $hashid->encode($user->id),
61 "token" => $user->verify_token
62 ]);
[7304c7f]63 }
64
65 public function logout()
66 {
67
68 $user = auth()->user();
69 $user->is_online = false;
70 $user->save();
71
72 auth()->logout();
73
74 return redirect("/auth/login");
75 }
76}
Note: See TracBrowser for help on using the repository browser.