source: pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php @ 326

Last change on this file since 326 was 326, checked in by namnd, 11 years ago
File size: 3.2 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Home Class
4 *
5 * @author dzungnv02
6 *
7 */
8
9class Home extends MX_Controller
10{
11       
12        const TOKENPW = 'violet';
13       
14        public function __construct()
15        {
16                parent::__construct();
17                $this->load->helper('cookie');
18        }
19
20        public function index()
21        {
22                $user_info = $this->session->userdata('userInfo');
23                if ($user_info)
24                {
25                        redirect('/frontend/lecture');
26                }else{
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');
35                        }
36                }
37        }
38       
39        public function test()
40        {
41                if (isset($_POST['submit'])){
42                        $this->signin();
43                }
44        }
45       
46        public function signin()
47        {
48                $username = $this->input->post('username', TRUE);
49                $password = $this->input->post('password', TRUE);
50                $autologin = ($this->input->post('remember_me') == 'on') ? 1 : 0;
51                $token = md5($username.self::TOKENPW);
52                $this->load->model(array('user_model'));
53                $data = $this->user_model->checkLogin('violet', $token, $username, $password);
54                if ($data == null)
55                {
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++)
64                        {
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                                }
73                        }
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)
81                        {
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;
111                        }
112                }
113        }
114       
115        public function signout()
116        {
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');
122        }
123
124}
125
126/* End of file home.php */
127/* Location: ./application/modules/frontend/controllers/home.php */
Note: See TracBrowser for help on using the repository browser.