<commit_before><?php

require_once realpath(LIB_DIR.'/Module.php');

class LoginModule extends Module {
  protected $id = 'login';
  
  protected function initialize() {
        
  }

  protected function initializeForPage() {
    
    $url = $this->getArg('url', ''); //return url
    $this->assign('url', $url);
    $user = $this->getUser();

    switch ($this->page)
    {
        case 'logout':
            $this->page = 'message';
            if (!$this->session->isLoggedIn()) {
                $this->redirectTo('login');
            } else {
                $result = $this->session->logout($user);
                $this->assign('message', 'Logout Successful');
            }
        
            break;
            
        case 'login':
            if ($this->session->isLoggedIn()) {
                $this->redirectTo('index');
            }
            
            $login = $this->argVal($_POST, 'loginUser', '');
            $password = $this->argVal($_POST, 'loginPassword', '');
            $result = $this->session->login($login, $password, $user);

            switch ($result)
            {
                case AUTH_OK:
                    if ($url) {
                        header("Location: $url");
                        exit();
                    } 
                    $this->page = 'message';
                    $this->assign('message', 'Login Successful');
                    break;

                case AUTH_FAILED:
                case AUTH_USER_NOT_FOUND:
                    $this->page = 'index';
                    $this->assign('message', 'Login Failed. Please check your login and password');
                    break;

            }
            break;
        case 'index':
            if ($this->session->isLoggedIn()) {
                $user = $this->getUser();
                $this->page = 'message';
                $this->assign('message', "You are logged in as " . $user->getUserID());
                $this->assign('url', $this->buildURL('logout'));
                $this->assign('linkText', 'Click here to logout.');
            }<commit_msg>don't attempt to login with an empty userID<commit_after><?php

require_once realpath(LIB_DIR.'/Module.php');

class LoginModule extends Module {
  protected $id = 'login';
  
  protected function initialize() {
        
  }

  protected function initializeForPage() {
    
    $url = $this->getArg('url', ''); //return url
    $this->assign('url', $url);
    $user = $this->getUser();

    switch ($this->page)
    {
        case 'logout':
            $this->page = 'message';
            if (!$this->session->isLoggedIn()) {
                $this->redirectTo('login');
            } else {
                $result = $this->session->logout($user);
                $this->assign('message', 'Logout Successful');
            }
        
            break;
            
        case 'login':
            $login = $this->argVal($_POST, 'loginUser', '');

            if ($this->session->isLoggedIn() || empty($login)) {
                $this->redirectTo('index');
            }
            
            $password = $this->argVal($_POST, 'loginPassword', '');
            $result = $this->session->login($login, $password, $user);

            switch ($result)
            {
                case AUTH_OK:
                    if ($url) {
                        header("Location: $url");
                        exit();
                    } 
                    $this->page = 'message';
                    $this->assign('message', 'Login Successful');
                    break;

                case AUTH_FAILED:
                case AUTH_USER_NOT_FOUND:
                    $this->page = 'index';
                    $this->assign('message', 'Login Failed. Please check your login and password');
                    break;

            }
            break;
        case 'index':
            if ($this->session->isLoggedIn()) {
                $user = $this->getUser();
                $this->page = 'message';
                $this->assign('message', "You are logged in as " . $user->getUserID());
                $this->assign('url', $this->buildURL('logout'));
                $this->assign('linkText', 'Click here to logout.');
            }
{'fraction_non_alphanumeric': 0.15431807456347332, 'fraction_numerical': 0.0, 'mean_word_length': 1.3801235261089275, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '6532194', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1081, 'n_words': 226}