1 | <?php
|
---|
2 | if (! defined ( 'BASEPATH' ))
|
---|
3 | exit ( 'No direct script access allowed' );
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Home Class
|
---|
7 | * @todo Control main actions
|
---|
8 | * @see index()
|
---|
9 | * @see singin()
|
---|
10 | * @see signout()
|
---|
11 | *
|
---|
12 | * @author dzungnv02
|
---|
13 | *
|
---|
14 | */
|
---|
15 | class Home extends MX_Controller {
|
---|
16 | const TOKENPW = 'violet';
|
---|
17 | public function __construct() {
|
---|
18 | parent::__construct ();
|
---|
19 | $this->load->helper ( 'cookie' );
|
---|
20 | $this->load->helper('language');
|
---|
21 | $this->lang->load('messages', 'message');
|
---|
22 | }
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * function index
|
---|
26 | * @todo checked is sign-in then redirect to lecture page else redirect to sign-in page
|
---|
27 | */
|
---|
28 | public function index() {
|
---|
29 | $user_info = $this->session->userdata ( 'userInfo' );
|
---|
30 | if ($user_info) {
|
---|
31 | redirect ( '/frontend/lecture' );
|
---|
32 | } else {
|
---|
33 | $cookie_name = "siteCookie";
|
---|
34 | if (isset ( $_COOKIE [$cookie_name] )) {
|
---|
35 | $arr_user = parse_str ( $_COOKIE [$cookie_name] );
|
---|
36 | $user_info = array (
|
---|
37 | 'username' => $arr_user ['username'],
|
---|
38 | 'user' => $arr_user ['user'],
|
---|
39 | 'us_id' => $arr_user ['us_id'],
|
---|
40 | 'is_viettel' => $arr_user ['is_viettel'],
|
---|
41 | 'logined_in' => TRUE
|
---|
42 | );
|
---|
43 | $this->session->set_userdata ( 'userInfo', $user_info );
|
---|
44 | redirect ( '/frontend/lecture' );
|
---|
45 | } else {
|
---|
46 | $this->load->view ( 'home' );
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * function signin
|
---|
53 | * @todo Execute sign-in action
|
---|
54 | */
|
---|
55 | public function signin() {
|
---|
56 | $username = $this->input->post ( 'username', TRUE );
|
---|
57 | $password = $this->input->post ( 'password', TRUE );
|
---|
58 | $autologin = ($this->input->post ( 'remember_me' ) == 'on') ? 1 : 0;
|
---|
59 | $src = 'SBG';
|
---|
60 | $token = md5 ( $username . self::TOKENPW );
|
---|
61 | $this->load->model ( array (
|
---|
62 | 'user_model'
|
---|
63 | ) );
|
---|
64 | $result = $this->user_model->checkLogin ( $src, $token, $username, $password );
|
---|
65 | if ($result['success'] == -1)
|
---|
66 | {
|
---|
67 | $this->session->set_flashdata ( 'login_api_error', TRUE );
|
---|
68 | redirect ( '/frontend/home' );
|
---|
69 |
|
---|
70 | }else if ($result['success'] == 0)
|
---|
71 | {
|
---|
72 | $this->session->set_flashdata ( 'login_error', TRUE );
|
---|
73 | redirect ( '/frontend/home' );
|
---|
74 | }else{
|
---|
75 | parse_str ( $result['data'] );
|
---|
76 | $is_viettel = $this->is_viettel ( $phone );
|
---|
77 |
|
---|
78 | if ($autologin == 1) {
|
---|
79 | $cookie_name = 'siteCookie';
|
---|
80 | // $cookie_time = 7200;
|
---|
81 | $cookie_time = 3600 * 24 * 30;
|
---|
82 | setcookie ( $cookie_name, 'username=' . $username . '&user=' . $result['data'] . '&us_id=' . $id, time () + $cookie_time );
|
---|
83 | }
|
---|
84 |
|
---|
85 | $userdata = array (
|
---|
86 | 'username' => $username,
|
---|
87 | 'user' => $result['data'],
|
---|
88 | 'us_id' => $id,
|
---|
89 | 'logined_in' => TRUE,
|
---|
90 | 'is_viettel' => $is_viettel
|
---|
91 | );
|
---|
92 | $this->session->set_userdata ( 'userInfo', $userdata );
|
---|
93 | redirect ( '/frontend/lecture' );
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * funtion signout
|
---|
99 | * @todo Execute signout action
|
---|
100 | */
|
---|
101 | public function signout() {
|
---|
102 | //$this->session->sess_destroy ();
|
---|
103 | // unset($this->session->userdata);
|
---|
104 | $this->session->unset_userdata('userInfo');
|
---|
105 | $cookie_name = "siteCookie";
|
---|
106 | setcookie ( $cookie_name, 'username=' . "", time () - 3600 );
|
---|
107 | redirect ( '/frontend/home' );
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * function is_viettel
|
---|
112 | * @param string $number
|
---|
113 | * @return 1:true;0:false
|
---|
114 | * @todo checked the phone number is viettel subscriber
|
---|
115 | */
|
---|
116 | private function is_viettel($number) {
|
---|
117 | $viettel = array (
|
---|
118 | '096',
|
---|
119 | '097',
|
---|
120 | '098',
|
---|
121 | '0163',
|
---|
122 | '0164',
|
---|
123 | '0165',
|
---|
124 | '0166',
|
---|
125 | '0167',
|
---|
126 | '0168',
|
---|
127 | '0169'
|
---|
128 | );
|
---|
129 | foreach ( $viettel as $num ) {
|
---|
130 | if (strpos ( $number, $num ) === 0) {
|
---|
131 | return 1;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | return 0;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public function test(){
|
---|
138 | $aryMatch = array();
|
---|
139 | $phoneNumber = '987133325';
|
---|
140 | $regex = '/^[1,9][0-9]{8,9}$/';
|
---|
141 | if (preg_match('/^[1,9]([0-9]{8,9})$/', $phoneNumber, $aryMatch)){
|
---|
142 | $phoneNumber = "0".$phoneNumber;
|
---|
143 | echo $phoneNumber;
|
---|
144 | }else{
|
---|
145 | echo "Not match";
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | /* End of file home.php */
|
---|
151 | /* Location: ./application/modules/frontend/controllers/home.php */ |
---|