application/Controllers/ViewControllers/User.php
/**
     * Reset Password of user
     * Check if token is still valid
     * Reset password in database
     * Send email specifying reset details for verification
     * 
     * @param string $token 
     * @route
     */
Reset Password of user
Check if token is still valid
Reset password in database
Send email specifying reset details for verification

@param string $token
@route
Reset Password of user Check if token is still valid Reset password in database Send email specifying reset details for verification @param string $token @route
public function resetPassword(string $token): void {
        $data = array(
            "password" => '',
            'confirm_password' => '',
            'password_err' => '',
            'confirm_password_err' => '',
            'token' => $token,
            'error' => ''
        );
        $email = $this->userModel->getEmailByPasswordToken($token);
        if(!$email) {
            $data['error'] = "Token Not Found. Try Again";
        } else if(!$this->userModel->isPasswordTokenValid($token)) {
            $data['error'] = "Token Expired. Try Again";
        }
        if(Server::checkPostReq(['password', 'confirm_password'])) {
            $password = $_POST['password'];
            $confirmPassword = $_POST['confirm_password'];
            $data['password'] = $password;
            $data['confirm_password'] = $confirmPassword;
            if(!Str::isValidPassword($password)) {
                $data['password_err'] = "Enter Valid Password";
            }
            if($password !== $confirmPassword) {
                $data['confirm_password_err'] = "Passwords do not match";
            }
            if(Str::emptyStrings([$data['password_err'], $data['confirm_password_err']])) {
                $password = password_hash($password, PASSWORD_DEFAULT);
                $data['confirm_password_err'] = "Error Encountered";
                if($this->userModel->updatePasswordByToken($token, $password)) {
                    $ipDetails = "Unable to determine user information";
                    $userDetails = $_SERVER['HTTP_USER_AGENT'] ?? "";
                    if(filter_var($_SERVER["REMOTE_ADDR"], FILTER_VALIDATE_IP)) 
                        $ipDetails = $this->userModel->ipDetails($_SERVER['REMOTE_ADDR']);
                    $body = "
                        Password was recently reset for your account for email address $email. 
                        <br> 
                        <h2>Activity Details</h2>
                        <b>$userDetails</b>
                        <pre>$ipDetails</pre>
                        If you dont recognize this: Please 
                        <a href='".URLROOT."/user/forgot-password'>Reset Password</a>
                    ";
                    $mailStatus = $this->mailModel->sendMail($email, 'Password Reset for '.SITENAME, $body);
                    if($mailStatus) {
                        Session::flash('password_reset', 'Password Reset. Login');
                        Server::redirect('user/login');
                    }
                }
            }
        }
        $this->view('user/reset-password', $data);
    }
public function resetPassword ( string $ token ) : void { $ data = array ( " password " => '' , 'confirm_password' => '' , 'password_err' => '' , 'confirm_password_err' => '' , 'token' => $ token , 'error' => '' ) ; $ email = $ this -> userModel -> getEmailByPasswordToken ( $ token ) ; if ( ! $ email ) { $ data [ 'error' ] = " Token Not Found. Try Again " ; } else if ( ! $ this -> userModel -> isPasswordTokenValid ( $ token ) ) { $ data [ 'error' ] = " Token Expired. Try Again " ; } if ( Server :: checkPostReq ( [ 'password' , 'confirm_password' ] ) ) { $ password = $ _POST [ 'password' ] ; $ confirmPassword = $ _POST [ 'confirm_password' ] ; $ data [ 'password' ] = $ password ; $ data [ 'confirm_password' ] = $ confirmPassword ; if ( ! Str :: isValidPassword ( $ password ) ) { $ data [ 'password_err' ] = " Enter Valid Password " ; } if ( $ password !== $ confirmPassword ) { $ data [ 'confirm_password_err' ] = " Passwords do not match " ; } if ( Str :: emptyStrings ( [ $ data [ 'password_err' ] , $ data [ 'confirm_password_err' ] ] ) ) { $ password = password_hash ( $ password , PASSWORD_DEFAULT ) ; $ data [ 'confirm_password_err' ] = " Error Encountered " ; if ( $ this -> userModel -> updatePasswordByToken ( $ token , $ password ) ) { $ ipDetails = " Unable to determine user information " ; $ userDetails = $ _SERVER [ 'HTTP_USER_AGENT' ] ?? " " ; if ( filter_var ( $ _SERVER [ " REMOTE_ADDR " ] , FILTER_VALIDATE_IP ) ) $ ipDetails = $ this -> userModel -> ipDetails ( $ _SERVER [ 'REMOTE_ADDR' ] ) ; $ body = " 
                        Password was recently reset for your account for email address  $ email . 
                        <br> 
                        <h2>Activity Details</h2>
                        <b> $ userDetails </b>
                        <pre> $ ipDetails </pre>
                        If you dont recognize this: Please 
                        <a href=' " . URLROOT . " /user/forgot-password'>Reset Password</a>
                     " ; $ mailStatus = $ this -> mailModel -> sendMail ( $ email , 'Password Reset for ' . SITENAME , $ body ) ; if ( $ mailStatus ) { Session :: flash ( 'password_reset' , 'Password Reset. Login' ) ; Server :: redirect ( 'user/login' ) ; } } } } $ this -> view ( 'user/reset-password' , $ data ) ; }
Reset Password of user
 Check if token is still valid
 Reset password in database
 Send email specifying reset details for verification
Reset Password of user Check if token is still valid Reset password in database Send email specifying reset details for verification