123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\admin\controller;
- use think\Controller;
- use think\Request;
- use app\admin\model\SysUser as UserModel;
- class Login extends Controller
- {
- protected $user_model;
- public function __construct(Request $request = null)
- {
- parent::__construct($request);
- $this->user_model = new UserModel();
- }
- public function index()
- {
- if (session('?username')) {
- $this->success('您已登入', 'admin/index/index');
- } else {
- return $this->fetch();
- }
- }
- public function dologin(Request $request = null)
- {
- if ($request->isPOST()) {
-
-
- $username = trim(input('post.username'));
- $password = trim(input('post.password'));
- $verify = trim(input('post.verify'));
- if (!$username || !$password || !$verify) {
- $this->error('用户名/密码/验证码不能为空');
- }
- if (!captcha_check($verify)) {
- $this->error('验证码不正确', '/admin/login');
- }
- $info = $this->user_model->getLogInfo($username);
- if (!$info || md5($password) != $info->password) {
- $this->error('用户名/密码不正确', '/admin/login');
- }
- $time = time();
- $ip = $request->ip();
- $result = $this->user_model->save(['login_time' => $time, 'login_ip' => $ip], ['id' => $info->id]);
- if ($result === false) {
- $this->error('登陆失败,请稍后重试', '/admin/login');
- }
-
-
- $browser = browser_info();
- @$result = model('login_note')->save([
- 'userid'=>$info['id'],
- 'time'=>$time,
- 'ip'=>$ip,
- 'browser'=>$browser
- ]);
-
- session('uid', $info->id);
- session('username', $info->username);
- session('role_id', $info->role_id);
- session('last_time', $info->login_time);
- session('last_ip', $info->login_ip);
- $this->success('登入成功', 'admin/index/index');
- } else {
- if (session('?user_name')) {
- $this->success('您已登入', 'admin/index/index');
- } else {
- return $this->fetch();
- }
- }
- }
-
- * 登出
- */
- public function logout()
- {
- session(null);
- return $this->fetch('index');
- }
-
- * admin/login/makecaptcha
- */
- }
|