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

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