class Account extends CI_Controller
{
public function __construct()
{
parent::__construct();
// 加载模块
$this->load->model('Account_model');
$this->load->library('session');
}
/**
* 登录逻辑
*/
public function login()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
// 执行模块里登录函数,返回用户信息的关联数组或false
$query = $this->Account_model->login($username, $password);
if ($query) {
// 使用session类设置指定键值对
$this->session->set_userdata($query);
$res = [
'code' => 200,
'msg' => [
'text' => "登录成功",
'username' => $username,
'level' => $query['level']
]
];
} else {
$res = [
'code' => 204,
'msg' => [
'text' => "登录失败"
]
];
}
$this->_ajax_output($res);
}
}