123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- /**
- * lemocms
- * ============================================================================
- * 版权所有 2018-2027 lemocms,并保留所有权利。
- * 网站地址: https://www.lemocms.com
- * ----------------------------------------------------------------------------
- * 采用最新Thinkphp6实现
- * ============================================================================
- * Author: yuege
- * Date: 2019/8/2
- */
- namespace app\admin\controller;
- use app\admin\model\Admin;
- use app\admin\model\AuthGroup;
- use app\BaseController;
- use app\common\controller\Backend;
- use app\common\controller\Base;
- use lemo\helper\SignHelper;
- use think\facade\Session;
- use think\facade\View;
- use think\facade\Request;
- use think\captcha\facade\Captcha;
- class Login extends Base {
- /*
- * 登录
- */
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- }
- public function index(){
- if (!Request::isPost()) {
- $admin= Session::get('admin');
- $admin_sign= Session::get('admin_sign') == SignHelper::authSign($admin) ? $admin['id'] : 0;
- // 签名验证
- if ($admin && $admin_sign) {
-
- redirect('index/index');
- }
- return View::fetch();
- } else {
- $username = Request::post('username', '', 'lemo\helper\StringHelper::filterWords');
- $password = Request::post('password', '', 'lemo\helper\StringHelper::filterWords');
- $captcha = Request::post('captcha', '', 'lemo\helper\StringHelper::filterWords');
- $rememberMe = Request::post('rememberMe');
- // 用户信息验证
- try {
- if(!captcha_check($captcha)){
- throw new \Exception(lang('captcha error'));
- }
- $res = self::checkLogin($username, $password,$rememberMe);
- } catch (\Exception $e) {
- $this->error(lang('login fail').":{$e->getMessage()}");
- }
- $this->success(lang('login success').'...', '/admin/index');
- }
- }
- /*
- * 验证码
- *
- */
- public function verify()
- {
- return Captcha::create();
- }
- /**
- * 根据用户名密码,验证用户是否能成功登陆
- * @param string $user
- * @param string $pwd
- * @throws \Exception
- * @return mixed
- */
- public static function checkLogin($user, $password,$rememberMe) {
- try{
- $where['username'] = strip_tags(trim($user));
- $password = strip_tags(trim($password));
- $info = Admin::where($where)->find();
- // if (!$info){
- // $info = Admin::where($where)->find();
- // }
- if(!$info){
- throw new \Exception(lang('please check username or password'));
- }
- if($info['status']==0){
- throw new \Exception(lang('account is disabled'));
- }
- if(!password_verify($password,$info['password'])){
- throw new \Exception(lang('please check username or password'));
- }
- if(!$info['group_id']){
- $info['group_id'] = 1;
- }
- Session::set('quanxian', $info["project_status"]);
- Session::set('adminid', $info["id"]);
- Session::set('project', $info["project"]);
- $rules = AuthGroup::where('id',$info['group_id'])
- ->value('rules');
- $info['rules'] = $rules ;
- if(!$info['username']){
- $info['username'] = $info['username'];
- }
- unset($info['password']);
- if($rememberMe){
- Session::set('admin', $info,7*24*3600);
- Session::set('admin_sign', SignHelper::authSign($info),7*24*3600);
- }else{
- Session::set('admin', $info);
- Session::set('admin_sign', SignHelper::authSign($info));
- }
- }catch (\Exception $e) {
- throw new \Exception($e->getMessage());
- }
- return true;
- }
- }
|