Showing
8 changed files
with
170 additions
and
26 deletions
@@ -6,12 +6,34 @@ module.exports=function(app) { | @@ -6,12 +6,34 @@ module.exports=function(app) { | ||
6 | app.get("/logout","common.Login",function (req) { | 6 | app.get("/logout","common.Login",function (req) { |
7 | delete req.session.user; | 7 | delete req.session.user; |
8 | }); | 8 | }); |
9 | + | ||
10 | + app.get("/login/captcha", "common_geeCaptcha", function(data, req, res) { | ||
11 | + if (data.code === 500) { | ||
12 | + return; | ||
13 | + } | ||
14 | + | ||
15 | + if (!data.success) { | ||
16 | + req.session.fallback = true; | ||
17 | + return res.json({ | ||
18 | + code: 501, | ||
19 | + data: data | ||
20 | + }); | ||
21 | + } else { | ||
22 | + // 正常模式 | ||
23 | + req.session.fallback = false; | ||
24 | + return res.send({ | ||
25 | + code: 200, | ||
26 | + data: data | ||
27 | + }); | ||
28 | + } | ||
29 | + }); | ||
9 | 30 | ||
10 | app.post("/login", "common_login", function (login, req, res){ | 31 | app.post("/login", "common_login", function (login, req, res){ |
11 | if (login.code == 200) { | 32 | if (login.code == 200) { |
12 | if (req.session.gray) { | 33 | if (req.session.gray) { |
13 | // 登录成功后,将phpsession保存下来 | 34 | // 登录成功后,将phpsession保存下来 |
14 | var gray_cookie = req.session.gray.replace(/[\[|\]]/g, '').split(';'); | 35 | var gray_cookie = req.session.gray.replace(/[\[|\]]/g, '').split(';'); |
36 | + | ||
15 | gray_cookie.forEach(function (n) { | 37 | gray_cookie.forEach(function (n) { |
16 | console.log(n); | 38 | console.log(n); |
17 | var item = n.split("="); | 39 | var item = n.split("="); |
1 | var request = require('request'); | 1 | var request = require('request'); |
2 | var _ = require('lodash'); | 2 | var _ = require('lodash'); |
3 | var fs = require('fs'); | 3 | var fs = require('fs'); |
4 | +var Geetest = require('gt3-sdk'); | ||
4 | 5 | ||
5 | var Iaccount = global.Register.system; | 6 | var Iaccount = global.Register.system; |
7 | +var pcGeetest = new Geetest({ | ||
8 | + geetest_id: '4bf7f911856073c1347247667790e7c4', | ||
9 | + geetest_key: '8d41283971d071216f1cef3d190d6b44' | ||
10 | +}); | ||
6 | 11 | ||
7 | var Utils = { | 12 | var Utils = { |
8 | createrMenus: function (data) { | 13 | createrMenus: function (data) { |
@@ -76,30 +81,73 @@ module.exports = { | @@ -76,30 +81,73 @@ module.exports = { | ||
76 | var userInfo = {},result = { code: 400, message: "登录失败" },isSuccess=false; | 81 | var userInfo = {},result = { code: 400, message: "登录失败" },isSuccess=false; |
77 | var user = req.body.user||req.query.user; | 82 | var user = req.body.user||req.query.user; |
78 | var password = req.body.password||req.query.password; | 83 | var password = req.body.password||req.query.password; |
84 | + var captcha = req.body.captcha || req.query.captcha; | ||
85 | + var verifyCode = captcha.split(','); | ||
79 | var errcallback = function (err) { | 86 | var errcallback = function (err) { |
80 | return callback(null, result); | 87 | return callback(null, result); |
81 | } | 88 | } |
82 | - common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) { | ||
83 | - var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"]; | ||
84 | - userInfo = { auth: userData, uid: userData.pid, name: userData.truename, role: userData.roleName, right: {},shopList:[],brands:[]}; | ||
85 | - if(userData.data_authority&&userData.data_authority.brand&&userData.data_authority.brand.list){ | ||
86 | - userInfo.brands=userData.data_authority.brand.is_all?"0":Object.keys(userData.data_authority.brand.list); | ||
87 | - } | ||
88 | - allRes.data.forEach(function (data) { | ||
89 | - if (data.platform_id == Iaccount.WEBSITE) { | ||
90 | - userInfo.right[data.path] = true; | ||
91 | - } | 89 | + |
90 | + if (!captcha) { | ||
91 | + return callback(null, { | ||
92 | + message: '图形验证失败', | ||
93 | + code: 405 | ||
92 | }); | 94 | }); |
93 | - common.getResourceByPid(userData.pid, userData.role_id).done(function (getRRes) { | ||
94 | - userInfo.menu = Utils.createrMenus(getRRes.data); | ||
95 | - req.session.user = userInfo; | ||
96 | - if (cookie && cookie.length > 0) { | ||
97 | - req.session.gray = cookie[0]; | ||
98 | - result = { code: 200, message: "登录成功" ,data:req.session.user}; | ||
99 | - } | ||
100 | - return callback(null, result); | ||
101 | - },errcallback); | ||
102 | - }, errcallback); | 95 | + } |
96 | + | ||
97 | + pcGeetest.validate(req.session.fallback, { | ||
98 | + geetest_challenge: verifyCode[0], | ||
99 | + geetest_validate: verifyCode[1], | ||
100 | + geetest_seccode: verifyCode[2] | ||
101 | + }, function(err, success) { | ||
102 | + if (err) { | ||
103 | + return callback(null, { | ||
104 | + message: '网络失败', | ||
105 | + code: 405 | ||
106 | + }); | ||
107 | + } else if (!success) { | ||
108 | + return callback(null, { | ||
109 | + message: '图形验证失败', | ||
110 | + code: 405 | ||
111 | + }); | ||
112 | + } else { | ||
113 | + common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) { | ||
114 | + var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"]; | ||
115 | + userInfo = { auth: userData, uid: userData.pid, name: userData.truename, role: userData.roleName, right: {},shopList:[],brands:[]}; | ||
116 | + if(userData.data_authority&&userData.data_authority.brand&&userData.data_authority.brand.list){ | ||
117 | + userInfo.brands=userData.data_authority.brand.is_all?"0":Object.keys(userData.data_authority.brand.list); | ||
118 | + } | ||
119 | + allRes.data.forEach(function (data) { | ||
120 | + if (data.platform_id == Iaccount.WEBSITE) { | ||
121 | + userInfo.right[data.path] = true; | ||
122 | + } | ||
123 | + }); | ||
124 | + | ||
125 | + common.getResourceByPid(userData.pid, userData.role_id).done(function (getRRes) { | ||
126 | + userInfo.menu = Utils.createrMenus(getRRes.data); | ||
127 | + req.session.user = userInfo; | ||
128 | + if (cookie && cookie.length > 0) { | ||
129 | + req.session.gray = cookie[0]; | ||
130 | + result = { code: 200, message: "登录成功" ,data:req.session.user}; | ||
131 | + } | ||
132 | + return callback(null, result); | ||
133 | + },errcallback); | ||
134 | + }, errcallback); | ||
135 | + } | ||
136 | + }); | ||
137 | + }, | ||
138 | + geeCaptcha: function(req, callback, common) { | ||
139 | + return pcGeetest.register({ | ||
140 | + client_type: 'web' | ||
141 | + }, function(err, data) { | ||
142 | + if (err) { | ||
143 | + return callback(null, { | ||
144 | + code: 500, | ||
145 | + message: "极验证注册失败" | ||
146 | + }); | ||
147 | + } | ||
148 | + | ||
149 | + callback(null, data); | ||
150 | + }); | ||
103 | }, | 151 | }, |
104 | isUsedMenuAuth:{ | 152 | isUsedMenuAuth:{ |
105 | title:'检查有没有权限', | 153 | title:'检查有没有权限', |
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | <div class="panel-body"> | 13 | <div class="panel-body"> |
14 | <h3 class="text-center mb5">Yoho!Buy运营平台</h3> | 14 | <h3 class="text-center mb5">Yoho!Buy运营平台</h3> |
15 | <div class="mb30"></div> | 15 | <div class="mb30"></div> |
16 | - <form action="/login" method="post"> | 16 | + <form action="/login" method="post" id="loginForm"> |
17 | <div class="input-group mb15"> | 17 | <div class="input-group mb15"> |
18 | <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> | 18 | <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> |
19 | <input type="text" name="user" id="user" class="form-control" placeholder="用户名" autocomplete="off" > | 19 | <input type="text" name="user" id="user" class="form-control" placeholder="用户名" autocomplete="off" > |
@@ -24,15 +24,19 @@ | @@ -24,15 +24,19 @@ | ||
24 | <input type="password" name="password" id="password" class="form-control" placeholder="密码" autocomplete="off" > | 24 | <input type="password" name="password" id="password" class="form-control" placeholder="密码" autocomplete="off" > |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | - <div class="clearfix"> | 27 | + <input type="hidden" id="captcha" name="captcha"> |
28 | + <div id="img-check-main"></div> | ||
29 | + | ||
30 | + <!-- <div class="clearfix"> | ||
28 | <div class="pull-right"> | 31 | <div class="pull-right"> |
29 | <button type="submit" class="btn btn-success">登录<i class="fa fa-angle-right ml5"></i></button> | 32 | <button type="submit" class="btn btn-success">登录<i class="fa fa-angle-right ml5"></i></button> |
30 | </div> | 33 | </div> |
31 | - </div> | 34 | + </div> --> |
32 | </form> | 35 | </form> |
33 | 36 | ||
34 | </div> | 37 | </div> |
35 | </div> | 38 | </div> |
36 | </section> | 39 | </section> |
40 | +<script src="http://static.geetest.com/static/tools/gt.js"></script> | ||
37 | </body> | 41 | </body> |
38 | </html> | 42 | </html> |
code/package-lock.json
0 → 100644
This diff could not be displayed because it is too large.
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | "connect-multiparty": "^2.0.0", | 15 | "connect-multiparty": "^2.0.0", |
16 | "connect-redis": "^3.0.2", | 16 | "connect-redis": "^3.0.2", |
17 | "cookie-parser": "^1.4.1", | 17 | "cookie-parser": "^1.4.1", |
18 | - "dev": "^0.1.3", | ||
19 | "express": "^4.13.4", | 18 | "express": "^4.13.4", |
20 | "express-session": "^1.13.0", | 19 | "express-session": "^1.13.0", |
21 | "glob": "^7.0.3", | 20 | "glob": "^7.0.3", |
@@ -34,9 +33,11 @@ | @@ -34,9 +33,11 @@ | ||
34 | "babel-plugin-transform-runtime": "^6.9.0", | 33 | "babel-plugin-transform-runtime": "^6.9.0", |
35 | "babel-preset-es2015": "^6.9.0", | 34 | "babel-preset-es2015": "^6.9.0", |
36 | "babel-runtime": "^6.9.0", | 35 | "babel-runtime": "^6.9.0", |
36 | + "crypto-js": "^3.1.9-1", | ||
37 | "css-loader": "^0.23.1", | 37 | "css-loader": "^0.23.1", |
38 | "extract-text-webpack-plugin": "^1.0.1", | 38 | "extract-text-webpack-plugin": "^1.0.1", |
39 | "file-loader": "^0.8.5", | 39 | "file-loader": "^0.8.5", |
40 | + "gt3-sdk": "^2.0.0", | ||
40 | "gulp": "^3.9.1", | 41 | "gulp": "^3.9.1", |
41 | "gulp-autoprefixer": "^3.1.0", | 42 | "gulp-autoprefixer": "^3.1.0", |
42 | "gulp-clean": "^0.3.2", | 43 | "gulp-clean": "^0.3.2", |
@@ -62,4 +63,4 @@ | @@ -62,4 +63,4 @@ | ||
62 | "vue-style-loader": "^1.0.0", | 63 | "vue-style-loader": "^1.0.0", |
63 | "webpack": "^1.13.0" | 64 | "webpack": "^1.13.0" |
64 | } | 65 | } |
65 | -} | ||
66 | +} |
1 | let href = window.location.href + ''; | 1 | let href = window.location.href + ''; |
2 | +let $ = require('jquery'); | ||
3 | +let $captcha = $('#captcha'); | ||
4 | + | ||
2 | if(href) { | 5 | if(href) { |
3 | let index = href.indexOf('?code'); | 6 | let index = href.indexOf('?code'); |
4 | if(index > 0) { | 7 | if(index > 0) { |
@@ -8,6 +11,68 @@ if(href) { | @@ -8,6 +11,68 @@ if(href) { | ||
8 | alert("用户名或者密码错误,请确认!"); | 11 | alert("用户名或者密码错误,请确认!"); |
9 | } | 12 | } |
10 | 13 | ||
14 | + if(code === 405) { | ||
15 | + alert('图形验证失败'); | ||
16 | + } | ||
17 | + | ||
11 | window.location.href = "/login"; | 18 | window.location.href = "/login"; |
12 | } | 19 | } |
13 | -} | ||
20 | +} | ||
21 | + | ||
22 | +var captcha = { | ||
23 | + init: function() { | ||
24 | + var that = this; | ||
25 | + | ||
26 | + $.ajax({ | ||
27 | + type: 'GET', | ||
28 | + dataType: 'json', | ||
29 | + url: 'login/captcha', | ||
30 | + success: function (result) { | ||
31 | + if (result.code === 500) { | ||
32 | + alert('验证码加载异常'); | ||
33 | + window.location.reload(true); | ||
34 | + return; | ||
35 | + } | ||
36 | + initGeetest && initGeetest({ // eslint-disable-line | ||
37 | + gt: result.data.gt, | ||
38 | + challenge: result.data.challenge, | ||
39 | + width: '100%', | ||
40 | + product: 'float', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效 | ||
41 | + new_captcha: result.data.new_captcha, | ||
42 | + offline: !result.data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注 | ||
43 | + }, that.initCallback); | ||
44 | + }, | ||
45 | + error: function (rs) { | ||
46 | + console.log(rs) | ||
47 | + } | ||
48 | + }); | ||
49 | + }, | ||
50 | + initCallback: function(captchaObj) { | ||
51 | + captchaObj.onSuccess(function() { | ||
52 | + var validate = captchaObj.getValidate(); | ||
53 | + | ||
54 | + var result = [ | ||
55 | + validate.geetest_challenge, | ||
56 | + validate.geetest_validate, | ||
57 | + validate.geetest_seccode | ||
58 | + ]; | ||
59 | + | ||
60 | + $captcha.val(result.join(',')); | ||
61 | + $('#loginForm').submit(); | ||
62 | + }); | ||
63 | + | ||
64 | + captchaObj.onError(function() { | ||
65 | + $captcha.val(''); | ||
66 | + }); | ||
67 | + | ||
68 | + captchaObj.onClose(function() { | ||
69 | + $captcha.val(''); | ||
70 | + }); | ||
71 | + | ||
72 | + captchaObj.appendTo(document.getElementById('img-check-main')); | ||
73 | + } | ||
74 | +} | ||
75 | + | ||
76 | +$(function() { | ||
77 | + captcha.init(); | ||
78 | +}); |
code/yarn.lock
0 → 100644
This diff could not be displayed because it is too large.
-
Please register or login to post a comment