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

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