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

Last change on this file since 322 was 321, checked in by dungnv, 11 years ago
File size: 2.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                        $this->load->view ( 'home');
28                        if (isset($_POST['submit'])){
29                                $this->signin();
30                        }
31                }
32        }
33       
34        public function test()
35        {
36                if (isset($_POST['submit'])){
37                        $this->signin();
38                }
39        }
40       
41        public function signin()
42        {
43                $username = $this->input->post('username', TRUE);
44                $password = $this->input->post('password', TRUE);
45                $token = md5($username.self::TOKENPW);
46                $this->load->model(array('user_model'));
47                $data = $this->user_model->checkLogin('violet', $token, $username, $password);
48                echo $data;
49                $arr_users = explode("&", $data);
50                $str_status = "";
51                $str_fullname = "";
52                $fullname = "";
53                for ($i=0; $i<count($arr_users); $i++)
54                {
55                        if (strpos($arr_users[$i], 'status=') !== false)
56                        {
57                                $str_status = $arr_users[$i];
58                        }
59                        if (strpos($arr_users[$i], 'fullname=') !== false)
60                        {
61                                $str_fullname = $arr_users[$i];
62                        }
63                }
64                $arr_status = explode("=", $str_status);
65                if ($str_fullname != ""){
66                        $arr_fullname = explode("=", $str_fullname);
67                        $fullname = $arr_fullname[1];
68                }
69                $status = (int)$arr_status[1];
70                switch($status)
71                {
72                        case 0:
73                                $userdata = array('username' => $username, "logined_in" => TRUE);
74                                $this->session->set_userdata('userInfo', $userdata);
75                                redirect('/frontend/lecture');
76                                break;
77                        case 1:
78                                echo "Thiếu thông tin đăng nhập !";
79                                break;
80                        case 2:
81                        case 3:
82                                echo "Sai username hoặc password !";
83                                break;
84                        case 4:
85                                echo "Tài khoản chưa được Activated";
86                                break;
87                        case 10:
88                                echo "Sai Token";
89                                break;
90                        default:
91                                break;
92                }
93        }
94       
95        public function signout()
96        {
97               
98        }
99
100}
101
102/* End of file home.php */
103/* Location: ./application/modules/frontend/controllers/home.php */
Note: See TracBrowser for help on using the repository browser.