[310] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
[293] | 2 | /**
|
---|
| 3 | * Home Class
|
---|
| 4 | *
|
---|
| 5 | * @author dzungnv02
|
---|
| 6 | *
|
---|
| 7 | */
|
---|
| 8 |
|
---|
[305] | 9 | class Home extends MX_Controller
|
---|
[293] | 10 | {
|
---|
| 11 |
|
---|
[314] | 12 | const TOKENPW = 'violet';
|
---|
| 13 |
|
---|
[293] | 14 | public function __construct()
|
---|
| 15 | {
|
---|
| 16 | parent::__construct();
|
---|
[314] | 17 | $this->load->helper('cookie');
|
---|
[293] | 18 | }
|
---|
| 19 |
|
---|
| 20 | public function index()
|
---|
| 21 | {
|
---|
[314] | 22 | $user_info = $this->session->userdata('userInfo');
|
---|
| 23 | if ($user_info)
|
---|
| 24 | {
|
---|
[317] | 25 | redirect('/frontend/lecture');
|
---|
[314] | 26 | }else{
|
---|
[326] | 27 | $cookie_name = "siteCookie";
|
---|
| 28 | if(isset($_COOKIE[$cookie_name])){
|
---|
| 29 | $arr_user = parse_str($_COOKIE[$cookie_name]);
|
---|
| 30 | $user_info = array( 'username' => $arr_user['username'], "logined_in" => TRUE);
|
---|
| 31 | $this->session->set_userdata('userInfo', $user_info);
|
---|
| 32 | redirect('/frontend/lecture');
|
---|
| 33 | }else{
|
---|
| 34 | $this->load->view ( 'home');
|
---|
[314] | 35 | }
|
---|
| 36 | }
|
---|
[311] | 37 | }
|
---|
| 38 |
|
---|
| 39 | public function test()
|
---|
| 40 | {
|
---|
[310] | 41 | if (isset($_POST['submit'])){
|
---|
| 42 | $this->signin();
|
---|
| 43 | }
|
---|
[293] | 44 | }
|
---|
| 45 |
|
---|
| 46 | public function signin()
|
---|
| 47 | {
|
---|
[310] | 48 | $username = $this->input->post('username', TRUE);
|
---|
| 49 | $password = $this->input->post('password', TRUE);
|
---|
[326] | 50 | $autologin = ($this->input->post('remember_me') == 'on') ? 1 : 0;
|
---|
[314] | 51 | $token = md5($username.self::TOKENPW);
|
---|
[305] | 52 | $this->load->model(array('user_model'));
|
---|
[310] | 53 | $data = $this->user_model->checkLogin('violet', $token, $username, $password);
|
---|
[326] | 54 | if ($data == null)
|
---|
[314] | 55 | {
|
---|
[326] | 56 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 57 | redirect('/frontend/home');
|
---|
| 58 | }else{
|
---|
| 59 | $arr_users = explode("&", $data);
|
---|
| 60 | $str_status = "";
|
---|
| 61 | $str_fullname = "";
|
---|
| 62 | $fullname = "";
|
---|
| 63 | for ($i=0; $i<count($arr_users); $i++)
|
---|
[314] | 64 | {
|
---|
[326] | 65 | if (strpos($arr_users[$i], 'status=') !== false)
|
---|
| 66 | {
|
---|
| 67 | $str_status = $arr_users[$i];
|
---|
| 68 | }
|
---|
| 69 | if (strpos($arr_users[$i], 'fullname=') !== false)
|
---|
| 70 | {
|
---|
| 71 | $str_fullname = $arr_users[$i];
|
---|
| 72 | }
|
---|
[314] | 73 | }
|
---|
[326] | 74 | $arr_status = explode("=", $str_status);
|
---|
| 75 | if ($str_fullname != ""){
|
---|
| 76 | $arr_fullname = explode("=", $str_fullname);
|
---|
| 77 | $fullname = $arr_fullname[1];
|
---|
| 78 | }
|
---|
| 79 | $status = (int)$arr_status[1];
|
---|
| 80 | switch($status)
|
---|
[314] | 81 | {
|
---|
[326] | 82 | case 0:
|
---|
| 83 | if($autologin == 1){
|
---|
| 84 | $cookie_name = 'siteCookie';
|
---|
| 85 | //$cookie_time = 7200;
|
---|
| 86 | $cookie_time = 3600*24*30;
|
---|
| 87 | setcookie($cookie_name, 'username='.$username, time() + $cookie_time);
|
---|
| 88 | }
|
---|
| 89 | $userdata = array('username' => $username, "logined_in" => TRUE);
|
---|
| 90 | $this->session->set_userdata('userInfo', $userdata);
|
---|
| 91 | redirect('/frontend/lecture');
|
---|
| 92 | break;
|
---|
| 93 | case 1:
|
---|
| 94 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 95 | redirect('/frontend/home');
|
---|
| 96 | break;
|
---|
| 97 | case 2:
|
---|
| 98 | case 3:
|
---|
| 99 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 100 | redirect('/frontend/home');
|
---|
| 101 | break;
|
---|
| 102 | case 4:
|
---|
| 103 | redirect('/frontend/home');
|
---|
| 104 | break;
|
---|
| 105 | case 10:
|
---|
| 106 | $this->session->set_flashdata('login_error_token', TRUE);
|
---|
| 107 | redirect('/frontend/home');
|
---|
| 108 | break;
|
---|
| 109 | default:
|
---|
| 110 | break;
|
---|
[314] | 111 | }
|
---|
| 112 | }
|
---|
[293] | 113 | }
|
---|
| 114 |
|
---|
| 115 | public function signout()
|
---|
| 116 | {
|
---|
[326] | 117 | $this->session->sess_destroy();
|
---|
| 118 | //unset($this->session->userdata);
|
---|
| 119 | $cookie_name = "siteCookie";
|
---|
| 120 | setcookie($cookie_name, 'username='."", time() - 3600);
|
---|
| 121 | redirect('/frontend/home');
|
---|
[293] | 122 | }
|
---|
| 123 |
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /* End of file home.php */
|
---|
| 127 | /* Location: ./application/modules/frontend/controllers/home.php */ |
---|