Explorar o código

验证码登录

seimin hai 1 ano
pai
achega
75e233d416

+ 3 - 2
assets/css/login.css

@@ -2,7 +2,8 @@
2 2
 .wt_login{
3 3
     background: #fff;
4 4
     text-align: center!important; 
5
-    width: 480px!important; 
5
+    width: 480px!important;
6
+    height: 470px!important;
6 7
     box-shadow: 0px 0px 5px 5px #ddd;
7 8
     border-radius: 8px;
8 9
 }
@@ -31,7 +32,7 @@
31 32
     
32 33
 }
33 34
 .wt_login_cantent p input{
34
-    width: 400px!important;
35
+    width: 400px;
35 36
     height: 52px;
36 37
     border-radius: 8px!important; 
37 38
 }

+ 32 - 0
assets/js/controllers/loginCtrl.js

@@ -135,6 +135,14 @@ app.controller('LoginCtrl', ['$rootScope', '$scope', '$state', '$translate', '$l
135 135
             });
136 136
             return tmpAES.toString();
137 137
         }
138
+        // 验证码
139
+        $scope.verificationCodeImg = '';
140
+        // 获取验证码
141
+        $scope.getVerificationCodeImg = function(){
142
+            var fileURL = api_login.getVerificationCodeImg().getRequestedUrl();
143
+            $scope.verificationCodeImg = fileURL;
144
+        }
145
+        $scope.getVerificationCodeImg();
138 146
         //登录
139 147
         $scope.handleLoginClick = function (e) {
140 148
             // api_login.getLicense({}).then(function(res){
@@ -146,6 +154,24 @@ app.controller('LoginCtrl', ['$rootScope', '$scope', '$state', '$translate', '$l
146 154
                 ssoStr = location.search.replace('?', '').split('&')[0].split('=')[1];
147 155
                 ssoStr = Base64.decode(decodeURIComponent(ssoStr));
148 156
                 ssoJson = JSON.parse(ssoStr);
157
+            }else if(!$scope.loginForm.username || !$scope.loginForm.username.trim()){
158
+                SweetAlert.swal({
159
+                    title: "请输入用户名",
160
+                    type: "error"
161
+                })
162
+                return;
163
+            }else if(!$scope.loginForm.password || !$scope.loginForm.password.trim()){
164
+                SweetAlert.swal({
165
+                    title: "请输入密码",
166
+                    type: "error"
167
+                })
168
+                return;
169
+            }else if(!$scope.loginForm.captcha || !$scope.loginForm.captcha.trim()){
170
+                SweetAlert.swal({
171
+                    title: "请输入验证码",
172
+                    type: "error"
173
+                })
174
+                return;
149 175
             }
150 176
             var postData = $scope.isSSo ? { username: ssoJson.a, password: ssoJson.u, t: false } : $scope.loginForm;
151 177
             postData = {
@@ -174,6 +200,12 @@ app.controller('LoginCtrl', ['$rootScope', '$scope', '$state', '$translate', '$l
174 200
                         } else {
175 201
                             $scope.licensePassShow = true
176 202
                         }
203
+                    }else if(resp.state == 403){
204
+                        SweetAlert.swal({
205
+                            title: "验证码错误",
206
+                            type: "error"
207
+                        })
208
+                        $scope.getVerificationCodeImg();
177 209
                     } else {
178 210
                         api_login.getLicense({}).then(function (res) {
179 211
                             console.log(res);

+ 3 - 0
assets/js/main.js

@@ -512,6 +512,9 @@ app.factory('api_report_data', ['UserRestangular', function (UserRestangular) {
512 512
 app.factory('api_login', ['UserRestangular', function (UserRestangular) {
513 513
     var loginService = UserRestangular.all("auth");
514 514
     return {
515
+        getVerificationCodeImg: function () {
516
+            return loginService.one('getCaptcha?' + Date.now(), {}, {'responseType':'arraybuffer'});
517
+        },
515 518
         onlineCount: function (data) {
516 519
             return loginService.customPOST(data, 'onlineCount', {});
517 520
         },

+ 4 - 0
assets/views/login_login.html

@@ -112,6 +112,10 @@
112 112
                 <p>
113 113
                     <input ng-model="loginForm.password" type="password" placeholder='请输入密码' style="font-size:14px;color:#435063; " autocomplete />
114 114
                 </p>
115
+                <p>
116
+                    <input ng-model="loginForm.captcha" type="text" placeholder='请输入验证码' style="font-size:14px;color:#435063;width: 300px;" autocomplete />
117
+                    <img style="width: 100px;" ng-src="{{verificationCodeImg}}" ng-click="getVerificationCodeImg()">
118
+                </p>
115 119
                 <!-- 记住密码 wt -->
116 120
                 <!-- <p class="wt_checkbox">
117 121
                     <input type="checkbox" class="remember" ng-model="rememberID" ng-change="remember()">