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