From 30775cbe647bb4ee11ef54112936ea717539ca4a Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Sat, 5 Nov 2016 00:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/User.php | 31 +++++++++++++++++++++++++-- application/config.php | 27 ----------------------- application/database.php | 4 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 5ba472e..a592d63 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -21,11 +21,38 @@ class User extends Base { return $this->error('缺少关键数据!'); } $password = $this->getPwdHash($password); - $isOk = Db::table('users')->where(['username' => $username, 'password' => $password])->count(); - if( !$isOk ){ + $userInfo = Db::table('user')->where(['username' => $username, 'password' => $password])->find(); + if( empty($userInfo) ){ $this->error('用户名或者密码错误!'); }else{ + if( $userInfo['status'] ){ + //保存用户信息和登录凭证 + S($userInfo['_id'], session_id(), C('ONLINE_TIME')); + session('uid', $userInfo['_id']); + + //获取跳转链接,做到从哪来到哪去 + $url = empty(session('loginFrom')) ? U('Index/index') : session('loginFrom'); + session('loginFrom', null); + + //更新用户数据 + $userData = D('UserData')->where(['uid' => $userInfo['_id']])->find(); + $data = []; + if( $userData ){ + $data['loginTimes'] = $userData['loginTimes'] + 1; + $data['lastLoginIp'] = get_client_ip(1); + $data['lastLoginTime'] = NOW_TIME; + D('UserData')->where(['uid' => $userInfo['_id']])->save($data); + }else{ + $data['loginTimes'] = 1; + $data['uid'] = $userInfo['_id']; + D('UserData')->add($data); + } + + $this->success('登录成功', $url); + }else{ + $this->error('用户已被封禁,请联系管理员'); + } } }else{ return $this->fetch(); diff --git a/application/config.php b/application/config.php index f44dcd3..fa0d8ea 100644 --- a/application/config.php +++ b/application/config.php @@ -15,33 +15,6 @@ return [ 'WEBSITE_DOMAIN' => 'http://www.7d-vision.com', //官方网址 'COMPANY_NAME' => '七维视觉科技有限公司', //公司名称 - - // +---------------------------------------------------------------------- - // | 数据库配置 - // +---------------------------------------------------------------------- - 'database' => [ - // 数据库类型 - 'type' => 'mysql', - // 服务器地址 - 'hostname' => '127.0.0.1', - // 数据库名 - 'database' => 'admin', - // 数据库用户名 - 'username' => 'root', - // 数据库密码 - 'password' => 'root', - // 数据库连接端口 - 'hostport' => '3306', - // 数据库连接参数 - 'params' => [], - // 数据库编码默认采用utf8 - 'charset' => 'utf8', - // 数据库表前缀 - 'prefix' => '', - // 数据库调试模式 - 'debug' => false, - ], - // +---------------------------------------------------------------------- // | 应用设置 // +---------------------------------------------------------------------- diff --git a/application/database.php b/application/database.php index 9079069..23f61df 100644 --- a/application/database.php +++ b/application/database.php @@ -15,11 +15,11 @@ return [ // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 - 'database' => '', + 'database' => 'admin', // 用户名 'username' => 'root', // 密码 - 'password' => '', + 'password' => 'root', // 端口 'hostport' => '', // 连接dsn