12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * Created by PhpStorm
- * User: 林志杰
- * Email: [email protected]
- * Time: 2020/1/2 12:58
- */
- namespace app\admin\controller;
- use app\BaseController;
- use app\common\model\mysql\AdminUser;
- use think\facade\View;
- class Login extends BaseController
- {
- public function index()
- {
- return View::fetch();
- }
- public function md5()
- {
- halt(session(config('admin.session_admin')));
- echo md5('admin_singwa_abc');
- }
- public function check()
- {
- if (!$this->request->isPost()) {
- return show(config('status.error'), '请求方式错误');
- }
- // 参数校验 1、原生方式 2、TP6 验证机制
- $username = $this->request->param('username', '', 'trim');
- $password = $this->request->param('password', '', 'trim');
- $captcha = $this->request->param('captcha', '', 'trim');
- if (empty($username) || empty($password) || empty($captcha)) {
- return show(config('status.error'), '参数不能为空');
- }
- // 验证码校验
- if (!captcha_check($captcha)) {
- // 验证码校验失败
- return show(config('status.error'), '验证码不正确');
- }
- try {
- $adminUserObj = new AdminUser();
- $adminUser = $adminUserObj->getAdminUserByUsername($username);
- if (empty($adminUser) || $adminUser->status != config('status.mysql.table_normal')) {
- return show(config('status.error'), '不存在该用户');
- }
- $adminUser = $adminUser->toArray();
- if ($adminUser['password'] !== md5($password . '_singwa_abc')) {
- return show(config('status.error'), '密码错误');
- }
- // 记录session
- session(config('admin.session_admin'), $adminUser);
- // 记录信息到mysql中
- $updateData = [
- 'last_login_time' => time(),
- 'last_login_ip' => request()->ip(),
- 'update_time' => time(),
- ];
- $res = $adminUserObj->updateById($adminUser['id'], $updateData);
- if (empty($res)) {
- return show(config('status.error'), '登陆失败');
- }
- } catch (\Exception $e) {
- // todo 记录日志 $e->getMessage()
- return show(config('status.error'), '内部异常,登陆失败');
- }
- return show(config('status.success'), '登陆成功');
- }
- }
|