- Timestamp:
- 10/25/21 21:49:53 (3 years ago)
- Branches:
- develop, master
- Children:
- e756bd9
- Parents:
- 05e57e2
- Location:
- app
- Files:
-
- 3 added
- 1 deleted
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Auth/ForgotPasswordController.php
r05e57e2 r1c25bcf 3 3 namespace App\Http\Controllers\Auth; 4 4 5 use App\Helpers\Alert; 5 6 use App\Http\Requests\Auth\ForgotPasswordRequest; 6 7 use App\Models\User; … … 33 34 $user->notify(new ForgotPassword($user)); 34 35 35 $request->session()->flash("forgotInfo", "We have sent an email to your inbox.");36 Alert::flash( "We have sent an email to your inbox", "error"); 36 37 37 38 return redirect()->route("auth.forgotShow"); -
app/Http/Controllers/Auth/LoginController.php
r05e57e2 r1c25bcf 3 3 namespace App\Http\Controllers\Auth; 4 4 5 use App\Helpers\Alert; 5 6 use App\Http\Requests\Auth\LoginRequest; 6 7 use App\Models\User; 7 8 use App\Http\Controllers\Controller; 9 use App\Notifications\VerifyUser; 10 use App\Services\Hashid; 8 11 use Illuminate\Support\Facades\Hash; 12 use Illuminate\Support\Str; 9 13 10 14 class LoginController extends Controller 11 15 { 12 protected $redirectTo = '/ dashboard';16 protected $redirectTo = '/'; 13 17 14 18 public function __construct() … … 22 26 } 23 27 24 public function login(LoginRequest $request )28 public function login(LoginRequest $request, Hashid $hashid) 25 29 { 26 30 $user = User::whereUsername($request->username)->first(); 27 31 32 if (is_null($user)) { 33 Alert::flash("Please check your credentials", "error"); 34 return redirect()->route("auth.login"); 35 } 36 28 37 if (!$user->is_active) { 29 $request->session()->flash("isActiveError", "Your account is blocked or its not confirmed yet. Please contact with your system administrator or check your email.");30 return redirect()-> back();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"); 31 40 } 32 41 33 42 if (!Hash::check($request->password, $user->password)) { 34 $request->session()->flash("passwordError", "Your password is incorrect");35 return redirect()-> back()->withInput($request->input());43 Alert::flash("Your password is incorrect", "error"); 44 return redirect()->route("auth.login"); 36 45 } 37 46 38 if (auth()->attempt([ 39 "username" => $request->username, 40 "password" => $request->password, 41 "is_active" => true], $request->remember)) { 42 43 $user->is_online = true; 44 $user->save(); 45 46 return redirect()->intended('/dashboard'); 47 } 48 47 //$user->security_code = rand(10000, 99999); 49 48 if ($user->is_forgot_password) { 50 49 $user->is_forgot_password = false; 51 50 } 52 51 53 $request->session()->flash("loginError", "An error occurred while login. Please try again later."); 52 $user->security_code = 1234; 53 $user->verify_token = Str::uuid(); 54 $user->is_online = true; 55 $user->save(); 54 56 55 return redirect()->back()->withInput($request->input()); 57 $user->notify(new VerifyUser($user)); 58 59 return redirect()->route("verify-login.index", [ 60 "id" => $hashid->encode($user->id), 61 "token" => $user->verify_token 62 ]); 56 63 } 57 64 -
app/Http/Kernel.php
r05e57e2 r1c25bcf 71 71 'permission' => \App\Http\Middleware\CheckPermission::class, 72 72 'checkIsActive' => \App\Http\Middleware\CheckIsActive::class, 73 'CheckVerifyToken' => \App\Http\Middleware\CheckVerifyToken::class 73 74 ]; 74 75 } -
app/Models/User.php
r05e57e2 r1c25bcf 28 28 "password", 29 29 "avatar", 30 "role_id" 30 "role_id", 31 "security_code", 32 "verify_token" 31 33 ]; 32 34 … … 39 41 "password", 40 42 "remember_token", 41 "is_active" 43 "is_active", 44 "verify_token", 45 "security_code" 42 46 ]; 43 47 -
app/Notifications/VerifyUser.php
r05e57e2 r1c25bcf 3 3 namespace App\Notifications; 4 4 5 use App\Models\Company; 5 6 use App\Models\User; 7 use App\Services\Hashid; 6 8 use Illuminate\Bus\Queueable; 9 use Illuminate\Contracts\Queue\ShouldQueue; 10 use Illuminate\Notifications\Messages\MailMessage; 7 11 use Illuminate\Notifications\Notification; 8 use Illuminate\Notifications\Messages\MailMessage;9 12 10 class Verify NewEmail extends Notification13 class VerifyUser extends Notification implements ShouldQueue 11 14 { 12 15 use Queueable; 13 16 14 pr ivate$user;17 protected $user; 15 18 16 19 /** … … 27 30 * Get the notification's delivery channels. 28 31 * 29 * @param mixed$notifiable32 * @param mixed $notifiable 30 33 * @return array 31 34 */ … … 38 41 * Get the mail representation of the notification. 39 42 * 40 * @param mixed$notifiable43 * @param mixed $notifiable 41 44 * @return \Illuminate\Notifications\Messages\MailMessage 42 45 */ 43 46 public function toMail($notifiable) 44 47 { 48 $hashId = new Hashid(); 49 45 50 return (new MailMessage) 46 ->greeting(" Hello " . $this->user->name)47 ->line("To verify your new email click the button.")51 ->greeting("Login verification") 52 ->line("To verify click the button and enter your security code.") 48 53 ->line("Your security code is: " . $this->user->security_code) 49 ->action("Verify", url("/auth/verify/" . $this->user->id . "/" . $this->user->verify_token)); 54 ->action("Verify", route("verify-login.index", [ 55 "id" => $hashId->encode($this->user->id), 56 "token" => $this->user->verify_token 57 ])); 50 58 } 51 59 … … 53 61 * Get the array representation of the notification. 54 62 * 55 * @param mixed$notifiable63 * @param mixed $notifiable 56 64 * @return array 57 65 */ … … 62 70 ]; 63 71 } 72 73 64 74 }
Note:
See TracChangeset
for help on using the changeset viewer.