1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- /**
- * Class 登录类
- */
- class Index extends Public_Controller {
- function __construct(){
- parent::__construct();
- $this->load->helper(array('form','date'));
- $this->load->model("user_model");
- }
- /**
- * 登录页面
- */
- public function login(){
- if($this->session->user_id){
- redirect(base_url()."main/index");
- }
- $this->display("index/login.html");
- }
- /**
- * 检查登录
- */
- public function check_login(){
- if($this->input->post()){
- $message = "";
- $username = $this->input->post("username");
- $password = $this->input->post("password");
- if($username != "" && $password !="") {
- $user = $this->user_model->get_user_with_username_password($username, hash_hmac('sha256',$password,$this->config->item('secret_key')));
- if (count($user) >= 1) {
- if ($user[0]['status'] == "20") {
- $message = "该帐号未验证,请验证后再登录!";
- } elseif ($user[0]['status'] == "30") {
- $message = "该帐号已锁定,请联系管理员!";
- } elseif ($user[0]['status'] == "40") {
- $message = "该帐号已停用,请联系管理员!";
- } else {
- $rand = substr(md5(microtime()), rand(0, 26), 5);
- $session_data = array("user_id" => (string)$user[0]["user_id"], "current_key" => $rand, "username" => $user[0]['username'], "user_type" => $user[0]['user_type']);
- $user[0]['last_login_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
- $this->user_model->update_user($user[0]);
- $this->session->set_userdata($session_data);
- }
- } else {
- $message = "帐号名或密码错误,请重试!";
- }
- }else{
- $message = "用户名或密码不能为空!";
- }
- if($message != "") {
- $this->response(array("msg" => $message));
- }else{
- $this->response(array("url" => "main/index"));
- }
- } else{
- $message = "参数错误,请重试!";
- $this->response(array("msg"=>$message));
- }
- }
- /**
- * 登出
- */
- public function logout(){
- if($this->session->user_id){
- $this->session->unset_userdata(array("user_id","current_key","username","user_type","from"));
- }
- redirect("login");
- }
- }
|