[503] | 1 | <?php
|
---|
[556] | 2 | if (! defined ( 'BASEPATH' ))
|
---|
| 3 | exit ( 'No direct script access allowed' );
|
---|
[503] | 4 |
|
---|
[293] | 5 | /**
|
---|
| 6 | * Home Class
|
---|
[884] | 7 | * @todo Control main actions
|
---|
| 8 | * @see index()
|
---|
| 9 | * @see singin()
|
---|
| 10 | * @see signout()
|
---|
[556] | 11 | *
|
---|
[293] | 12 | * @author dzungnv02
|
---|
[556] | 13 | *
|
---|
[293] | 14 | */
|
---|
[503] | 15 | class Home extends MX_Controller {
|
---|
[556] | 16 | const TOKENPW = 'violet';
|
---|
| 17 | public function __construct() {
|
---|
| 18 | parent::__construct ();
|
---|
| 19 | $this->load->helper ( 'cookie' );
|
---|
[636] | 20 | $this->load->helper('language');
|
---|
| 21 | $this->lang->load('messages', 'message');
|
---|
[556] | 22 | }
|
---|
| 23 |
|
---|
[884] | 24 | /**
|
---|
| 25 | * function index
|
---|
| 26 | * @todo checked is sign-in then redirect to lecture page else redirect to sign-in page
|
---|
| 27 | */
|
---|
[556] | 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'],
|
---|
[671] | 40 | 'is_viettel' => $arr_user ['is_viettel'],
|
---|
[556] | 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 |
|
---|
[884] | 51 | /**
|
---|
| 52 | * function signin
|
---|
| 53 | * @todo Execute sign-in action
|
---|
| 54 | */
|
---|
[556] | 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;
|
---|
[540] | 59 | $src = 'SBG';
|
---|
[556] | 60 | $token = md5 ( $username . self::TOKENPW );
|
---|
| 61 | $this->load->model ( array (
|
---|
| 62 | 'user_model'
|
---|
| 63 | ) );
|
---|
[633] | 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 | {
|
---|
[556] | 72 | $this->session->set_flashdata ( 'login_error', TRUE );
|
---|
| 73 | redirect ( '/frontend/home' );
|
---|
[633] | 74 | }else{
|
---|
| 75 | parse_str ( $result['data'] );
|
---|
[556] | 76 | $is_viettel = $this->is_viettel ( $phone );
|
---|
[707] | 77 |
|
---|
[633] | 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 );
|
---|
[556] | 83 | }
|
---|
[707] | 84 |
|
---|
[633] | 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' );
|
---|
[556] | 94 | }
|
---|
| 95 | }
|
---|
[540] | 96 |
|
---|
[884] | 97 | /**
|
---|
| 98 | * funtion signout
|
---|
| 99 | * @todo Execute signout action
|
---|
| 100 | */
|
---|
[556] | 101 | public function signout() {
|
---|
[707] | 102 | //$this->session->sess_destroy ();
|
---|
[556] | 103 | // unset($this->session->userdata);
|
---|
[707] | 104 | $this->session->unset_userdata('userInfo');
|
---|
[556] | 105 | $cookie_name = "siteCookie";
|
---|
| 106 | setcookie ( $cookie_name, 'username=' . "", time () - 3600 );
|
---|
| 107 | redirect ( '/frontend/home' );
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[884] | 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) {
|
---|
[556] | 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) {
|
---|
[671] | 131 | return 1;
|
---|
[556] | 132 | }
|
---|
| 133 | }
|
---|
[671] | 134 | return 0;
|
---|
[556] | 135 | }
|
---|
[838] | 136 |
|
---|
| 137 | public function test(){
|
---|
[883] | 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";
|
---|
[838] | 146 | }
|
---|
| 147 | }
|
---|
[293] | 148 | }
|
---|
| 149 |
|
---|
| 150 | /* End of file home.php */
|
---|
| 151 | /* Location: ./application/modules/frontend/controllers/home.php */ |
---|