Ver código fonte

wesmiler 更新第5期更新代码合并

wesmiler 4 anos atrás
pai
commit
152042b838

+ 99 - 16
public/themes/admin_simpleboot3/admin/login.html

@@ -25,36 +25,69 @@
             }, 0);
         }
     </script>
+    <style>
+        .form-group .time {
+            cursor: pointer;
+            position: absolute;
+            right: 1px;
+            top: 1px;
+            width: 150px;
+            height: 32px;
+        }
+        .login-type {
+            color: #0b6cbc;
+            text-align: right;
+            margin-top: 10px;
+            float: right;
+            font-size: 16px;
+        }
+    </style>
 </head>
 <body>
 <div class="wrap">
     <div class="container">
         <div class="row">
             <div class="col-md-4 col-md-offset-4">
-                <h1 class="text-center">管理后台</h1>
+                <h1 class="text-center">管理后台 <a class="login-type"><span style="display: none;">账号登录</span><span>验证码登录</span></a></h1>
                 <form class="js-ajax-form" action="{:url('public/doLogin')}" method="post">
-                    <div class="form-group">
-                        <input type="text" id="input_username" class="form-control" name="username"
-                               placeholder="{:lang('USERNAME_OR_EMAIL')}" title="{:lang('USERNAME_OR_EMAIL')}"
-                               value="{:cookie('admin_username')}" data-rule-required="true" data-msg-required="">
-                    </div>
+                    <div id="type1" class="typeBox">
+                        <div class="form-group">
+                            <input type="text" id="input_username" class="form-control" name="username"
+                                   placeholder="{:lang('USERNAME_OR_EMAIL')}" title="{:lang('USERNAME_OR_EMAIL')}"
+                                   value="{:cookie('admin_username')}" data-rule-required="true" data-msg-required="">
+                        </div>
 
-                    <div class="form-group">
-                        <input type="password" id="input_password" class="form-control" name="password"
-                               placeholder="{:lang('PASSWORD')}" title="{:lang('PASSWORD')}" data-rule-required="true"
-                               data-msg-required="">
-                    </div>
+                        <div class="form-group">
+                            <input type="password" id="input_password" class="form-control" name="password"
+                                   placeholder="{:lang('PASSWORD')}" title="{:lang('PASSWORD')}" data-rule-required="true"
+                                   data-msg-required="">
+                        </div>
 
-                    <div class="form-group">
-                        <div style="position: relative;">
-                            <input type="text" name="captcha" placeholder="验证码" class="form-control captcha">
-                            <captcha height="32" width="150" font-size="18"
-                                     style="cursor: pointer;position:absolute;right:1px;top:1px;"/>
+                        <div class="form-group">
+                            <div style="position: relative;">
+                                <input type="text" name="captcha" placeholder="验证码" class="form-control captcha">
+                                <captcha height="32" width="150" font-size="18"
+                                         style="cursor: pointer;position:absolute;right:1px;top:1px;"/>
+                            </div>
                         </div>
                     </div>
+                    <div id="type2" class="typeBox" style="display: none;">
+                        <div class="form-group">
+                            <input type="text" id="mobile" class="form-control" name="username"
+                                   placeholder="{:lang('USERNAME_OR_EMAIL')}" title="{:lang('USERNAME_OR_EMAIL')}"
+                                   value="{:cookie('admin_username')}" data-rule-required="true" data-msg-required="">
+                        </div>
 
+                        <div class="form-group">
+                            <div style="position: relative;">
+                                <input type="text" name="captcha" placeholder="验证码" class="form-control captcha">
+                                <button type="button" class="time" onclick="getCode()">获取验证码</button>
+                            </div>
+                        </div>
+                    </div>
                     <div class="form-group">
                         <input type="hidden" name="redirect" value="">
+                        <input id="loginType" type="hidden" name="loginType" value="1">
                         <button class="btn btn-primary btn-block js-ajax-submit" type="submit" style="margin-left: 0px"
                                 data-loadingmsg="{:lang('LOADING')}">
                             {:lang('LOGIN')}
@@ -79,10 +112,60 @@
 <script src="__TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
 <script src="__STATIC__/js/wind.js"></script>
 <script src="__STATIC__/js/admin.js"></script>
+<script src="__STATIC__/js/layer/layer.js"></script>
 <script>
     (function () {
         document.getElementById('input_username').focus();
+
+        $(".login-type span").click(function(){
+            var index = $(this).index()+1;
+            $("#loginType").val(index);
+            $(".typeBox").hide();
+            $("#type"+index).show();
+            console.log(index)
+            $(this).hide().siblings('span').show();
+        })
+
     })();
+
+    function getCode(){
+        var mobile = $("#mobile").val();
+        if(mobile=='' || mobile == null || mobile.length < 8){
+            layer.msg('请填写手机号');
+            return false;
+        }
+
+        if(time<60){
+            layer.msg('请不要频繁操作');
+            return false;
+        }
+
+        timeLock();
+        $.post("/admin/public/verifyCode", {mobile: mobile}, function(res){
+            if (res.code == 1) {
+                layer.msg(res.msg)
+            } else {
+                layer.msg(res.msg)
+            }
+        },'json')
+
+    }
+
+    var time = 60;
+    var timerId = null;
+    function timeLock(){
+       clearInterval(timerId);
+       timerId = setInterval(function(){
+            time--;
+            if(time<=0){
+                time = 60;
+                clearInterval(timerId);
+                $(".time").text('获取验证码');
+            }else{
+                $(".time").text(time+'s');
+            }
+        },1000)
+    }
 </script>
 </body>
 </html>

+ 87 - 47
vendor/thinkcmf/cmf-app/src/admin/controller/PublicController.php

@@ -10,6 +10,8 @@
 // +----------------------------------------------------------------------
 namespace app\admin\controller;
 
+use app\weixin\service\Sms;
+use app\weixin\validate\MemberValidate;
 use cmf\controller\AdminBaseController;
 use think\Db;
 
@@ -23,7 +25,7 @@ class PublicController extends AdminBaseController
      * 后台登陆界面
      */
     public function login()
-    { 
+    {
         $loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
         if (empty($loginAllowed)) {
             return redirect(cmf_get_root() . "/admin");
@@ -84,71 +86,109 @@ class PublicController extends AdminBaseController
         if (empty($captcha)) {
             $this->error(lang('CAPTCHA_REQUIRED'));
         }
-        //验证码
-        if (!cmf_captcha_check($captcha)) {
-            $this->error(lang('CAPTCHA_NOT_RIGHT'));
-        }
 
         $name = $this->request->param("username");
-        if (empty($name)) {
-            $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
-        }
-        $pass = $this->request->param("password");
-        if (empty($pass)) {
-            $this->error(lang('PASSWORD_REQUIRED'));
-        }
-        if (strpos($name, "@") > 0) {//邮箱登陆
-            $where['user_email'] = $name;
+        $loginType = input('loginType', 1);
+        if ($loginType == 1) {
+
+            //验证码
+            if (!cmf_captcha_check($captcha)) {
+                $this->error(lang('CAPTCHA_NOT_RIGHT'));
+            }
+
+            if (empty($name)) {
+                $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
+            }
+            $pass = $this->request->param("password");
+            if (empty($pass)) {
+                $this->error(lang('PASSWORD_REQUIRED'));
+            }
+            if (strpos($name, "@") > 0) {//邮箱登陆
+                $where['user_email'] = $name;
+            } else {
+                $where['user_login'] = $name;
+            }
         } else {
-            $where['user_login'] = $name;
+            $result = Sms::checkCode($name, $captcha,'admin');
+            if ($result !== true) {
+                $this->error(lang($result));
+            }
+
+            if (empty($name)) {
+                $this->error('请填写正确格式手机号码');
+            }
+
+            $where['mobile'] = $name;
+
         }
 
+
         $result = Db::name('user')->where($where)->find();
         if (!empty($result) && ($result['user_type'] == 1 || $result['user_type'] == 3)) {
 
             // 登录IP来源验证
             $ip = get_client_ip();
-            if($result['check_ip']){
+            if ($result['check_ip']) {
                 $blackList = explode(',', $result['check_ip']);
-                if($blackList && !in_array($ip, $blackList)){
-                    $this->error(lang('USER_IP_LIMIT'), '',$ip);
+                if ($blackList && !in_array($ip, $blackList)) {
+                    $this->error(lang('USER_IP_LIMIT'), '', $ip);
                 }
-            }else if($result['user_type'] != 3){
+            } else if ($result['user_type'] != 3) {
                 $blackList = config('app.ipBlackList');
-                if($blackList && !preg_match($blackList, $ip)){
-                    $this->error(lang('USER_IP_LIMIT'), '',$ip);
+                if ($blackList && !preg_match($blackList, $ip)) {
+                    $this->error(lang('USER_IP_LIMIT'), '', $ip);
                 }
             }
-            
-            if (cmf_compare_password($pass, $result['user_pass'])) {
-                $groups = Db::name('RoleUser')
-                    ->alias("a")
-                    ->join('__ROLE__ b', 'a.role_id =b.id')
-                    ->where(["user_id" => $result["id"], "status" => 1])
-                    ->value("role_id");
-                if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
-                    $this->error(lang('USE_DISABLED'));
-                }
-                //登入成功页面跳转
-                session('ADMIN_ID', $result["id"]);
-                session('name', $result["user_login"]);
-                session('ADMIN_TYPE', $result["user_type"]);
-                $result['last_login_ip']   = get_client_ip(0, true);
-                $result['last_login_time'] = time();
-                $token                     = cmf_generate_user_token($result["id"], 'web');
-                if (!empty($token)) {
-                    session('token', $token);
-                }
-                Db::name('user')->update($result);
-                cookie("admin_username", $name, 3600 * 24 * 30);
-                session("__LOGIN_BY_CMF_ADMIN_PW__", null);
-                $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
-            } else {
+
+            if ($loginType == 1 && !cmf_compare_password($pass, $result['user_pass'])) {
                 $this->error(lang('PASSWORD_NOT_RIGHT'));
             }
+
+            $groups = Db::name('RoleUser')
+                ->alias("a")
+                ->join('__ROLE__ b', 'a.role_id =b.id')
+                ->where(["user_id" => $result["id"], "status" => 1])
+                ->value("role_id");
+            if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
+                $this->error(lang('USE_DISABLED'));
+            }
+            //登入成功页面跳转
+            session('ADMIN_ID', $result["id"]);
+            session('name', $result["user_login"]);
+            session('ADMIN_TYPE', $result["user_type"]);
+            $result['last_login_ip'] = get_client_ip(0, true);
+            $result['last_login_time'] = time();
+            $token = cmf_generate_user_token($result["id"], 'web');
+            if (!empty($token)) {
+                session('token', $token);
+            }
+            Db::name('user')->update($result);
+            cookie("admin_username", $name, 3600 * 24 * 30);
+            session("__LOGIN_BY_CMF_ADMIN_PW__", null);
+            $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
         } else {
-            $this->error(lang('USERNAME_NOT_EXIST'));
+            $this->error(lang('ACCOUNT_NOT_EXIST'));
+        }
+    }
+
+    /**
+     * 获取验证码
+     */
+    public function verifyCode()
+    {
+        $mobile = input('mobile','');
+        $validate = new MemberValidate();
+        if (!$validate->scene('code')->check(input())) {
+            $this->error($validate->getError());
+        }
+
+        // 发送处理
+        $result = Sms::sendCode($mobile, ['tpName' => 'code'], 'admin');
+        if (!is_array($result)) {
+            $this->error(is_numeric($result) ? $result : 1009);
         }
+
+        $this->success('验证码发送成功');
     }
 
     /**

+ 1 - 0
vendor/thinkcmf/cmf/src/lang/zh-cn.php

@@ -32,6 +32,7 @@ return [
     'CAPTCHA_REQUIRED'         => "验证码不能为空!",
     'CAPTCHA_NOT_RIGHT'        => "验证码错误!",
     'USERNAME_NOT_EXIST'       => "用户名不存在!",
+    'ACCOUNT_NOT_EXIST'        => "登录账号不存在!",
     'USERNAME_OR_EMAIL_EMPTY'  => "用户名或邮箱不能为空!",
     'ENTER_VERIFY_CODE'        => '请输入验证码',
     'HOME'                     => '首页',