基于 thinkphp5.1 实现的海豚后台登录源码分析
一、 首先来到登录代码处,部分代码截图,大家有兴趣可以自己去看源码
登录处开始
public function signin()
{
if ($this->request->isPost()) {
// 获取post数据
$data = $this->request->post();
$rememberme = isset($data['remember-me']) ? true : false;
// 登录钩子, 做一些登录前动作, 这里暂时没有实现
$hook_result = Hook::listen('signin', $data);
if (!empty($hook_result) && true !== $hook_result[0]) {
$this->error($hook_result[0]);
}
// 验证数据
$result = $this->validate($data, 'User.signin');
if(true !== $result){
// 验证失败 输出错误信息
$this->error($result);
}
// 验证码
if (config('captcha_signin')) {
$captcha = $this->request->post('captcha', '');
$captcha == '' && $this->error('请输入验证码');
if(!captcha_check($captcha, '')){
//验证失败
$this->error('验证码错误或失效');
};
}
// 登录
$UserModel = new UserModel模型分析; // 进去模型逻辑
$uid = $UserModel->login($data['username'], $data['password'], $rememberme);
if ($uid) {
// 记录行为
action_log('user_signin', 'admin_user', $uid, $uid);
$this->jumpUrl();
} else {
<