application/Controllers/ViewControllers/User.php
/**
     * Login view for guest user
     * verify email/username and password
     * Check if account has been verified by email 
     * Set login cookie for browser
     * Set session and redirect to home
     * 
     * @route
     */
Login view for guest user
verify email/username and password
Check if account has been verified by email
Set login cookie for browser
Set session and redirect to home

@route
Login view for guest user verify email / username and password Check if account has been verified by email Set login cookie for browser Set session and redirect to home @route
public function login(): void {
        $data = [
            'email_or_username_err' => '',
            'password_err' => '',
            'email_or_username' => '',
            'password' => ''
        ];
        if(Server::checkPostReq(["email_or_username", "password"])) {
            $data['email_or_username'] = $_POST['email_or_username'];
            $data['password'] = $_POST['password'];
            if(empty($data['email_or_username'])) {
                $data['email_or_username_err'] = "Please Fill Login Details";
            }   else if(!$this->userModel->ifUsernameExists($data['email_or_username']) &&
                        !$this->userModel->ifEmailExists($data['email_or_username'])) {
                $data['email_or_username_err'] = "User not Found";
            }
            if(empty($data['password'])) $data['password_err'] = "Please Enter Password";
            if(Str::emptyStrings([$data['email_or_username_err'], $data['password_err']])) {
                if($this->userModel->isVerifiedUser($data['email_or_username'])) {
                    $verify = $this->userModel->verifyUser($data['email_or_username'], $data['password']);
                    if(!$verify) {
                        $data['password_err'] = "Incorrect Password";
                    }  else {
                        Session::sessionSet([
                            "username" => $verify->username,
                            "uniq_id" => $verify->uniq_id,
                            "display_name" => $verify->display_name,
                            "user_id" => $verify->id,
                            "about" => $verify->about,
                            "email" => $verify->email,
                            "display_name" => $verify->display_name,
                            'profile_img' => $verify->profile_img
                        ]);
                        $loginToken = Utils::randToken();
                        Cookie::createCookie('login_token', $loginToken, 30*24*60*60);
                        $this->userModel->insertLoginToken($verify->id, $loginToken);
                        Server::redirect("home/");
                    }
                }   else {
                    $append = filter_var($data['email_or_username'], FILTER_VALIDATE_EMAIL) 
                              ? '?email='.$data['email_or_username']  : '';
                    $data['email_or_username_err'] = 
                    "User is not verified. 
                    <a class='link-primary text-decoration-none'
                    href='".URLROOT."/user/resend-verification$append'>Resend Email</a>"; 
                }
            }
        }
        $this->view('user/login', $data);
    }
public function login ( ) : void { $ data = [ 'email_or_username_err' => '' , 'password_err' => '' , 'email_or_username' => '' , 'password' => '' ] ; if ( Server :: checkPostReq ( [ " email_or_username " , " password " ] ) ) { $ data [ 'email_or_username' ] = $ _POST [ 'email_or_username' ] ; $ data [ 'password' ] = $ _POST [ 'password' ] ; if ( empty ( $ data [ 'email_or_username' ] ) ) { $ data [ 'email_or_username_err' ] = " Please Fill Login Details " ; } else if ( ! $ this -> userModel -> ifUsernameExists ( $ data [ 'email_or_username' ] ) && ! $ this -> userModel -> ifEmailExists ( $ data [ 'email_or_username' ] ) ) { $ data [ 'email_or_username_err' ] = " User not Found " ; } if ( empty ( $ data [ 'password' ] ) ) $ data [ 'password_err' ] = " Please Enter Password " ; if ( Str :: emptyStrings ( [ $ data [ 'email_or_username_err' ] , $ data [ 'password_err' ] ] ) ) { if ( $ this -> userModel -> isVerifiedUser ( $ data [ 'email_or_username' ] ) ) { $ verify = $ this -> userModel -> verifyUser ( $ data [ 'email_or_username' ] , $ data [ 'password' ] ) ; if ( ! $ verify ) { $ data [ 'password_err' ] = " Incorrect Password " ; } else { Session :: sessionSet ( [ " username " => $ verify -> username , " uniq_id " => $ verify -> uniq_id , " display_name " => $ verify -> display_name , " user_id " => $ verify -> id , " about " => $ verify -> about , " email " => $ verify -> email , " display_name " => $ verify -> display_name , 'profile_img' => $ verify -> profile_img ] ) ; $ loginToken = Utils :: randToken ( ) ; Cookie :: createCookie ( 'login_token' , $ loginToken , 30 * 24 * 60 * 60 ) ; $ this -> userModel -> insertLoginToken ( $ verify -> id , $ loginToken ) ; Server :: redirect ( " home/ " ) ; } } else { $ append = filter_var ( $ data [ 'email_or_username' ] , FILTER_VALIDATE_EMAIL ) ? '?email=' . $ data [ 'email_or_username' ] : '' ; $ data [ 'email_or_username_err' ] = " User is not verified. 
                    <a class='link-primary text-decoration-none'
                    href=' " . URLROOT . " /user/resend-verification $ append '>Resend Email</a> " ; } } } $ this -> view ( 'user/login' , $ data ) ; }
Login view for guest user
 verify email/username and password
 Check if account has been verified by email
 Set login cookie for browser
 Set session and redirect to home
Login view for guest user verify email / username and password Check if account has been verified by email Set login cookie for browser Set session and redirect to home
// Correct Login // Set Session // Unverified user