<commit_before><?php

    class login extends module {
        
        public $allowedMethods = array(
            'logout'=>array('type'=>'get'), 
            'email'=>array('type'=>'post'), 
            'password'=>array('type'=>'post')
        );
        
        public function constructModule() {

            $settings = new settings();
            $this->page->addToTemplate("loginSuffix", $settings->loadSetting("loginSuffix"));
            $this->page->addToTemplate("loginPostfix", $settings->loadSetting("loginPostfix"));

            $usersOnline = $this->db->prepare("
                SELECT COUNT(*) as 'count' FROM users
            ");
            $usersOnline->execute();
            $users = $this->db->prepare("
                SELECT COUNT(*) as 'count' FROM userTimers WHERE UT_desc = 'laston' AND UT_time > ".(time()-900)."
            ");
            $users->execute();

            $this->page->addToTemplate("usersOnline", number_format($usersOnline->fetch(PDO::FETCH_ASSOC)["count"]));
            $this->page->addToTemplate("users", number_format($users->fetch(PDO::FETCH_ASSOC)["count"]));
            
            $this->html .= $this->page->buildElement('loginForm', array("text" => (isset($this->loginError)?$this->loginError:'')));
            
        }
        
        public function method_logout() {
            
            $this->loginError = $this->page->buildElement('info', array("text" => 'You have been logged out!'));
        
        }
        
        public function method_login() {
                
            $userExists = @$this->db->prepare("
                SELECT * FROM users WHERE U_email = :email ORDER BY U_id DESC LIMIT 0, 1
            ");
            $userExists->bindParam(":email", $this->methodData->email);
            $userExists->execute();
            $userExists = $userExists->fetch(PDO::FETCH_ASSOC);

            
            if (isset($userExists["U_id"])) {
                $user = new User($userExists["U_id"]);
                if ($user->info->U_password == $user->encrypt($user->info->U_id . $this->methodData->password)) {
                    $_SESSION['userID'] = $user->info->U_id;
                    header("Location:?page=" . $this->page->landingPage);
                } else {
                    $this->loginError = $this->page->buildElement('error', array("text" => 'You have entered a wrong password!'));;
                }
            } else {
                $this->loginError = $this->page->buildElement('error', array("text" => 'Invalid username!'));	
            }
            
        }
        
    }

?>
<commit_msg>made login errors generic<commit_after><?php

    class login extends module {
        
        public $allowedMethods = array(
            'logout'=>array('type'=>'get'), 
            'email'=>array('type'=>'post'), 
            'password'=>array('type'=>'post')
        );
        
        public function constructModule() {

            $settings = new settings();
            $this->page->addToTemplate("loginSuffix", $settings->loadSetting("loginSuffix"));
            $this->page->addToTemplate("loginPostfix", $settings->loadSetting("loginPostfix"));

            $usersOnline = $this->db->prepare("
                SELECT COUNT(*) as 'count' FROM users
            ");
            $usersOnline->execute();
            $users = $this->db->prepare("
                SELECT COUNT(*) as 'count' FROM userTimers WHERE UT_desc = 'laston' AND UT_time > ".(time()-900)."
            ");
            $users->execute();

            $this->page->addToTemplate("usersOnline", number_format($usersOnline->fetch(PDO::FETCH_ASSOC)["count"]));
            $this->page->addToTemplate("users", number_format($users->fetch(PDO::FETCH_ASSOC)["count"]));
            
            $this->html .= $this->page->buildElement('loginForm', array("text" => (isset($this->loginError)?$this->loginError:'')));
            
        }
        
        public function method_logout() {
            
            $this->loginError = $this->page->buildElement('info', array("text" => 'You have been logged out!'));
        
        }
        
        public function method_login() {
                
            $userExists = @$this->db->prepare("
                SELECT * FROM users WHERE U_email = :email ORDER BY U_id DESC LIMIT 0, 1
            ");
            $userExists->bindParam(":email", $this->methodData->email);
            $userExists->execute();
            $userExists = $userExists->fetch(PDO::FETCH_ASSOC);

            
            if (isset($userExists["U_id"])) {
                $user = new User($userExists["U_id"]);
                if ($user->info->U_password == $user->encrypt($user->info->U_id . $this->methodData->password)) {
                    $_SESSION['userID'] = $user->info->U_id;
                    header("Location:?page=" . $this->page->landingPage);
                } else {
                    $this->loginError = $this->page->buildElement('error', array("text" => 'You have entered a wrong email/password!'));;
                }
            } else {
                $this->loginError = $this->page->buildElement('error', array("text" => 'You have entered a wrong email/password!'));	
            }
            
        }
        
    }

?>

{'fraction_non_alphanumeric': 0.16992224540109993, 'fraction_numerical': 0.0018964536317087046, 'mean_word_length': 1.8851203501094091, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1197257', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1403, 'n_words': 239}