Пример #1
0
 function __construct()
 {
     parent::__construct();
     $this->template_data['cdn_server'] = base_url();
     $this->load->driver('cache', array('adapter' => 'file'));
     $this->load->library(array('Member_current_user'));
     $this->load->helper(array('server'));
     $this->user = Member_Current_User::user();
     if ($this->user) {
         // 登录用户信息
         // $this->template_data['user'] = $this->user;
         $this->load->vars(array('user' => $this->user));
     } else {
         // 跳转到登录页面
         redirect(base_url() . 'admin.php?c=login');
     }
 }
Пример #2
0
 function index()
 {
     if (strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
         $this->load->helper(array('server'));
         $this->load->library(array('Member_current_user'));
         include_once FCPATH . 'resource/securimage/securimage.php';
         $securimage = new Securimage();
         if ($securimage->check($this->input->post('captcha_code')) === false) {
             json_response(array('success' => FALSE, 'msg' => 'Error Captcha code'));
         } else {
             $username = $this->input->post('username');
             $password = $this->input->post('password');
             if ($user = Member_Current_User::login($username, $password)) {
                 $this->output->set_output(json_encode(array('success' => TRUE, 'msg' => 'Login Success')));
             } else {
                 json_response(array('success' => FALSE, 'msg' => 'Login Error'));
             }
         }
     } else {
         $this->load->view('login');
     }
 }
Пример #3
0
 public static function login($username, $password)
 {
     self::$ci =& get_instance();
     self::$ci->load->helper(array('security'));
     self::$ci->db->where('username', $username);
     self::$ci->db->or_where('email', $username);
     $u = self::$ci->db->get('users')->row();
     if (isset($u) && count($u) > 0) {
         if ($u->status) {
             if (password_verify($password, $u->password)) {
                 $ip = self::$ci->input->ip_address();
                 $data = array('cur_login_time' => date('Y-m-d H:i:s'), 'cur_login_ip' => $ip, 'cur_login_area' => '', 'last_login_ip' => $u->cur_login_ip, 'last_login_area' => $u->cur_login_area, 'last_login_time' => $u->cur_login_time, 'login_times' => $u->login_times + 1);
                 self::$ci->db->where('id', $u->id);
                 self::$ci->db->update('users', $data);
                 self::$ci->session->set_userdata('member_userid', $u->id);
                 self::$ci->session->set_userdata('IsAuthorized', TRUE);
                 self::$ci->session->set_userdata('member_companyid', $u->company_id);
                 session_write_close();
                 self::$user = $u;
                 // return TRUE;
                 return $u;
             } else {
                 self::$ci->session->set_flashdata('perr', 'Error Password');
                 session_write_close();
                 return FALSE;
             }
         } else {
             self::$ci->session->set_flashdata('perr', 'User Status Disable');
             session_write_close();
             return FALSE;
         }
     } else {
         self::$ci->session->set_flashdata('perr', 'User Do not Exist');
         session_write_close();
         return FALSE;
     }
 }