95 lines
3.1 KiB
PHP
Executable File
95 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
use think\Session;
|
|
use app\common\controller\BaseController as Base;
|
|
|
|
class Passport extends Base {
|
|
|
|
public function index() {
|
|
if (is_session_login('user')) {
|
|
return $this->redirect(url('/admin/index/index'));
|
|
}
|
|
$this->view->engine->layout(false);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 用户登录
|
|
* @param string $username 用户名
|
|
* @param string $password 密码
|
|
* @param string $verify 验证码
|
|
*/
|
|
public function login() {
|
|
if (is_session_login('user')) {
|
|
return $this->redirect(url('/admin/index/index'));
|
|
}
|
|
// $this->request->isPost() || $this->error(Lang::get('illegal request')); //判断是否ajax登录
|
|
$data = $this->request->post();
|
|
|
|
$this->verify_check($data['captcha'], 'authcode') || $this->json(-1, '验证码有误');
|
|
// $validaterule = [
|
|
// //'captcha|验证码' => 'captcha:authcode',
|
|
// //管理员登陆字段验证
|
|
// 'admin_username|' . Lang::get('user name') => 'require|min:2',
|
|
// 'admin_password|' . Lang::get('user password') => 'require|min:6',
|
|
// ];
|
|
|
|
// // 数据验证
|
|
// $valid_result = $this->validate($data, $validaterule);
|
|
// if (true !== $valid_result) {
|
|
// // 验证失败 输出错误信息
|
|
// return $this->error($valid_result);
|
|
// }
|
|
|
|
|
|
// $validate = new Validate($validaterule);
|
|
// $res = $validate->check($data);
|
|
// if (!$res) {
|
|
// // 验证失败 输出错误信息
|
|
// $this->error($validate->getError());
|
|
// }
|
|
$result = Loader::model('User')->login($data['admin_username'], $data['admin_password']);
|
|
// tiaoshi($result);die;
|
|
$result['status'] !== true && $this->json(-2, $result['msg']); //登录失败
|
|
|
|
return $result['id'] ? $this->json(200, '登录成功') : $this->json(-3, Lang::get('unknown error'));
|
|
}
|
|
|
|
/**
|
|
* 退出登录
|
|
*/
|
|
public function logout() {
|
|
if (!is_session_login('user')) {
|
|
return $this->redirect(url('/signin'));
|
|
}
|
|
$content = '用户' . Session::get('user_auth.username') . '(' . Session::get('user_auth.id') . ')退出登录时间:' . date('Y-m-d H:i:s');
|
|
action_log('退出登录', $content, Session::get('user_auth.id'));
|
|
//Loader::model('User')->logout();
|
|
Session::delete('user_auth', null);
|
|
Session::delete('user_auth_sign', null);
|
|
return $this->success(Lang::get('success'), url('/signin'));
|
|
}
|
|
|
|
public function register() {
|
|
if (is_session_login('user')) {
|
|
return $this->redirect(url('/admin/index/index'));
|
|
}
|
|
$this->view->engine->layout(false);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function forgetpwd() {
|
|
if (is_session_login('user')) {
|
|
return $this->redirect(url('/admin/index/index'));
|
|
}
|
|
$this->view->engine->layout(false);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
}
|