Changeset 1c25bcf for app


Ignore:
Timestamp:
10/25/21 21:49:53 (3 years ago)
Author:
Berat Kjufliju <kufliju@…>
Branches:
develop, master
Children:
e756bd9
Parents:
05e57e2
Message:

added 2fa, bug fixes, edited blades

Location:
app
Files:
3 added
1 deleted
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Auth/ForgotPasswordController.php

    r05e57e2 r1c25bcf  
    33namespace App\Http\Controllers\Auth;
    44
     5use App\Helpers\Alert;
    56use App\Http\Requests\Auth\ForgotPasswordRequest;
    67use App\Models\User;
     
    3334        $user->notify(new ForgotPassword($user));
    3435
    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");
    3637
    3738        return redirect()->route("auth.forgotShow");
  • app/Http/Controllers/Auth/LoginController.php

    r05e57e2 r1c25bcf  
    33namespace App\Http\Controllers\Auth;
    44
     5use App\Helpers\Alert;
    56use App\Http\Requests\Auth\LoginRequest;
    67use App\Models\User;
    78use App\Http\Controllers\Controller;
     9use App\Notifications\VerifyUser;
     10use App\Services\Hashid;
    811use Illuminate\Support\Facades\Hash;
     12use Illuminate\Support\Str;
    913
    1014class LoginController extends Controller
    1115{
    12     protected $redirectTo = '/dashboard';
     16    protected $redirectTo = '/';
    1317
    1418    public function __construct()
     
    2226    }
    2327
    24     public function login(LoginRequest $request)
     28    public function login(LoginRequest $request, Hashid $hashid)
    2529    {
    2630        $user = User::whereUsername($request->username)->first();
    2731
     32        if (is_null($user)) {
     33            Alert::flash("Please check your credentials", "error");
     34            return redirect()->route("auth.login");
     35        }
     36
    2837        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");
    3140        }
    3241
    3342        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");
    3645        }
    3746
    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);
    4948        if ($user->is_forgot_password) {
    5049            $user->is_forgot_password = false;
    5150        }
    5251
    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();
    5456
    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            ]);
    5663    }
    5764
  • app/Http/Kernel.php

    r05e57e2 r1c25bcf  
    7171        'permission' => \App\Http\Middleware\CheckPermission::class,
    7272        'checkIsActive' => \App\Http\Middleware\CheckIsActive::class,
     73        'CheckVerifyToken' => \App\Http\Middleware\CheckVerifyToken::class
    7374    ];
    7475}
  • app/Models/User.php

    r05e57e2 r1c25bcf  
    2828        "password",
    2929        "avatar",
    30         "role_id"
     30        "role_id",
     31        "security_code",
     32        "verify_token"
    3133    ];
    3234
     
    3941        "password",
    4042        "remember_token",
    41         "is_active"
     43        "is_active",
     44        "verify_token",
     45        "security_code"
    4246    ];
    4347
  • app/Notifications/VerifyUser.php

    r05e57e2 r1c25bcf  
    33namespace App\Notifications;
    44
     5use App\Models\Company;
    56use App\Models\User;
     7use App\Services\Hashid;
    68use Illuminate\Bus\Queueable;
     9use Illuminate\Contracts\Queue\ShouldQueue;
     10use Illuminate\Notifications\Messages\MailMessage;
    711use Illuminate\Notifications\Notification;
    8 use Illuminate\Notifications\Messages\MailMessage;
    912
    10 class VerifyNewEmail extends Notification
     13class VerifyUser extends Notification implements ShouldQueue
    1114{
    1215    use Queueable;
    1316
    14     private $user;
     17    protected $user;
    1518
    1619    /**
     
    2730     * Get the notification's delivery channels.
    2831     *
    29      * @param  mixed $notifiable
     32     * @param mixed $notifiable
    3033     * @return array
    3134     */
     
    3841     * Get the mail representation of the notification.
    3942     *
    40      * @param  mixed $notifiable
     43     * @param mixed $notifiable
    4144     * @return \Illuminate\Notifications\Messages\MailMessage
    4245     */
    4346    public function toMail($notifiable)
    4447    {
     48        $hashId = new Hashid();
     49
    4550        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.")
    4853            ->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            ]));
    5058    }
    5159
     
    5361     * Get the array representation of the notification.
    5462     *
    55      * @param  mixed $notifiable
     63     * @param mixed $notifiable
    5664     * @return array
    5765     */
     
    6270        ];
    6371    }
     72
     73
    6474}
Note: See TracChangeset for help on using the changeset viewer.