/var/www/hkosl.com/ifapc/html_20210817/IFAPC2021/application/controllers/Judge.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require_once APPPATH 'core/MY_Controller_2.php';

class 
Judge extends MY_Controller_2
{
    public function 
__construct()
    {
        
parent::__construct();
    }

    public function 
logout()
    {
        unset(
$_SESSION['judge_id']);
        
redirect(front_url('score'));
    }

    public function 
index()
    {
        if (
check_judge_login()) {
            
redirect(front_url('score'));
        }

        if (empty(
$_POST['login_id']) && empty($_POST['login_pw'])) {
            
$this->load->view('main/judge_login');
            return;
        }

        if (
Judge_login_log_model::check_if_lock()) {
            
$_SESSION['error_msg'] = __('You have failed to log in many times, please try again after 10 minutes.');
            
redirect(front_url('judge'));
        }
        
$judge_login Judge_login_log_model::create();

        
$judge_login_data["ip_address"] = get_client_ip();
        
$judge_login_data["user_agent"] = $_SERVER['HTTP_USER_AGENT'];
        
$judge_login_data["session_id"] = session_id();

        
$judge_login->update($judge_login_data);

        
$this->validate_massages['validate_login'] = __('Your account or password is incorrect');

        
$this->form_validation->set_rules('login_id'__('Login ID'), 'callback_validate_login'$this->validate_massages);

        if (
$this->form_validation->run() == false || !empty($_SESSION['error_msg'])) {
            
$this->load->view('main/judge_login');
            return;
        } else {
            
$judge_login->update(['is_success' => 1]);
            
redirect(front_url('score'));
        }
    }

    public function 
validate_login($str)
    {

        if (
count($judge Judge_model::get_data_by_field_with_value(['login_id' => $str])) && $this->encryption->decrypt($judge[0]->login_pw) == set_value('login_pw')) {
            
$_SESSION['judge_id'] = $judge[0]->id;
            return 
true;
        }
        return 
false;
    }

}