application/Controllers/ViewControllers/User.php
/**
     * Send request for forgotten password
     * Allow after 10 minutes of resetting password
     * Send mail with reset id 
     * Add reset token to database
     * 
     * @route
     */
Send request for forgotten password
Allow after 10 minutes of resetting password
Send mail with reset id
Add reset token to database

@route
Send request for forgotten password Allow after 10 minutes of resetting password Send mail with reset id Add reset token to database @route
public function forgotPassword(): void {
        $data = [
            'error' => '',
            'email' => ""
        ];
        if(Server::checkPostReq(['email'])) {
            $email = $_POST['email'];
            $data['email'] = $email;
            $lastIssued = strtotime($this->userModel->checkResetPasswordRequestTime($email));
            if(!$this->userModel->ifEmailExists($email)) {
                $data['error'] = "Email not found";
            }   else if(time() - $lastIssued < 600) {
                $data['error'] = "Please wait 10 minutes to reset password";
            }
            if(Str::emptyStrings([$data['error']])) {
                $newToken = Utils::randToken();
                $linkTag = "<a href='".URLROOT."/user/reset-password/$newToken"."'>Reset</a>";
                $body = "Reset Password Link is: $linkTag. Please ignore this mail if it wasnt you";
                $mailStatus = $this->mailModel->sendMail($email, 'Reset Password', $body);
                if($this->userModel->insertNewPasswordToken($email, $newToken) && $mailStatus) {
                    $this->userModel->deleteOldPasswordTokens($email, $newToken);
                    Session::flash('forgot_password', 'Check Email (and spam) to Reset Password');
                    Server::redirect('user/login');
                }   else {
                    $data['error'] = "Error Encountered";
                }
            }
        }
        $this->view('user/forgot-password', $data);
    }
public function forgotPassword ( ) : void { $ data = [ 'error' => '' , 'email' => " " ] ; if ( Server :: checkPostReq ( [ 'email' ] ) ) { $ email = $ _POST [ 'email' ] ; $ data [ 'email' ] = $ email ; $ lastIssued = strtotime ( $ this -> userModel -> checkResetPasswordRequestTime ( $ email ) ) ; if ( ! $ this -> userModel -> ifEmailExists ( $ email ) ) { $ data [ 'error' ] = " Email not found " ; } else if ( time ( ) - $ lastIssued < 600 ) { $ data [ 'error' ] = " Please wait 10 minutes to reset password " ; } if ( Str :: emptyStrings ( [ $ data [ 'error' ] ] ) ) { $ newToken = Utils :: randToken ( ) ; $ linkTag = " <a href=' " . URLROOT . " /user/reset-password/ $ newToken " . " '>Reset</a> " ; $ body = " Reset Password Link is:  $ linkTag . Please ignore this mail if it wasnt you " ; $ mailStatus = $ this -> mailModel -> sendMail ( $ email , 'Reset Password' , $ body ) ; if ( $ this -> userModel -> insertNewPasswordToken ( $ email , $ newToken ) && $ mailStatus ) { $ this -> userModel -> deleteOldPasswordTokens ( $ email , $ newToken ) ; Session :: flash ( 'forgot_password' , 'Check Email (and spam) to Reset Password' ) ; Server :: redirect ( 'user/login' ) ; } else { $ data [ 'error' ] = " Error Encountered " ; } } } $ this -> view ( 'user/forgot-password' , $ data ) ; }
Send request for forgotten password
 Allow after 10 minutes of resetting password
 Send mail with reset id
 Add reset token to database
Send request for forgotten password Allow after 10 minutes of resetting password Send mail with reset id Add reset token to database