Showing
5 changed files
with
87 additions
and
2 deletions
@@ -13,6 +13,7 @@ const sign = global.yoho.sign; | @@ -13,6 +13,7 @@ const sign = global.yoho.sign; | ||
13 | const cookie = global.yoho.cookie; | 13 | const cookie = global.yoho.cookie; |
14 | const RegService = require('../models/reg-service'); | 14 | const RegService = require('../models/reg-service'); |
15 | const AuthHelper = require('../models/auth-helper'); | 15 | const AuthHelper = require('../models/auth-helper'); |
16 | +const captchaService = require('../models/captcha-service'); | ||
16 | 17 | ||
17 | let index = (req, res) => { | 18 | let index = (req, res) => { |
18 | // 设置注册有效时间30分钟, 防机器刷 | 19 | // 设置注册有效时间30分钟, 防机器刷 |
@@ -28,6 +29,7 @@ let index = (req, res) => { | @@ -28,6 +29,7 @@ let index = (req, res) => { | ||
28 | page: 'reg', | 29 | page: 'reg', |
29 | title: '注册', | 30 | title: '注册', |
30 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line | 31 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line |
32 | + captchaUrl: helpers.urlFormat('/passport/reg/captcha.png', {t: Date.now()}), | ||
31 | headerText: '注册', // 头部信息 | 33 | headerText: '注册', // 头部信息 |
32 | isPassportPage: true, // 模板中模块标识 | 34 | isPassportPage: true, // 模板中模块标识 |
33 | areaCode: '+86', // 默认的区号 | 35 | areaCode: '+86', // 默认的区号 |
@@ -269,6 +271,20 @@ let setPassword = (req, res, next) => { | @@ -269,6 +271,20 @@ let setPassword = (req, res, next) => { | ||
269 | }).catch(next); | 271 | }).catch(next); |
270 | }; | 272 | }; |
271 | 273 | ||
274 | +/** | ||
275 | + * 生成 校验码 | ||
276 | + */ | ||
277 | +const genCaptcha = (req, res) => { | ||
278 | + let captcha = captchaService.generateCaptcha(90, 52, 4); | ||
279 | + | ||
280 | + req.session.regCaptch = captcha.token; | ||
281 | + | ||
282 | + res.type('png') | ||
283 | + .set('Cache-Control', 'no-cache') | ||
284 | + .status(200) | ||
285 | + .end(captcha.image); | ||
286 | +}; | ||
287 | + | ||
272 | module.exports = { | 288 | module.exports = { |
273 | index, | 289 | index, |
274 | verifyMobile, | 290 | verifyMobile, |
@@ -276,5 +292,6 @@ module.exports = { | @@ -276,5 +292,6 @@ module.exports = { | ||
276 | sendCode, | 292 | sendCode, |
277 | verifyCode, | 293 | verifyCode, |
278 | password: passwordAction, | 294 | password: passwordAction, |
279 | - setPassword | 295 | + setPassword, |
296 | + genCaptcha | ||
280 | }; | 297 | }; |
@@ -84,6 +84,7 @@ router.post('/passport/bind/changeMobile', bind.changeMobile); | @@ -84,6 +84,7 @@ router.post('/passport/bind/changeMobile', bind.changeMobile); | ||
84 | * 注册 | 84 | * 注册 |
85 | */ | 85 | */ |
86 | router.get('/passport/reg/index', reg.index); | 86 | router.get('/passport/reg/index', reg.index); |
87 | +router.get('/passport/reg/captcha.png', reg.genCaptcha); | ||
87 | router.post('/passport/reg/verifymobile', reg.verifyMobile); | 88 | router.post('/passport/reg/verifymobile', reg.verifyMobile); |
88 | router.get('/passport/reg/code', reg.code); | 89 | router.get('/passport/reg/code', reg.code); |
89 | router.post('/passport/reg/sendcode', reg.sendCode); | 90 | router.post('/passport/reg/sendcode', reg.sendCode); |
@@ -6,7 +6,16 @@ | @@ -6,7 +6,16 @@ | ||
6 | <span id="area-code" class="area-code">{{areaCode}}</span> | 6 | <span id="area-code" class="area-code">{{areaCode}}</span> |
7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> | 7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> |
8 | </div> | 8 | </div> |
9 | + <!-- 验证码: start--> | ||
10 | + <div class="passport-captcha row"> | ||
11 | + <input type="text" placeholder="验证码"> | ||
12 | + <div class="passport-captcha-img"> | ||
13 | + <img class="passport-captcha-png" src="{{captchaUrl}}"> | ||
14 | + <button class="passport-captcha-refresh" type="button">换一张</button> | ||
15 | + </div> | ||
16 | + </div> | ||
17 | + <!-- 验证码: end--> | ||
9 | <span id="btn-next" class="btn btn-next disable row">下一步</span> | 18 | <span id="btn-next" class="btn btn-next disable row">下一步</span> |
10 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> | 19 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> |
11 | </div> | 20 | </div> |
12 | -</div> | 21 | +</div> |
public/scss/passport/_passport-captcha.css
0 → 100644
1 | +/* 验证码 css | ||
2 | +----------------------------------- | ||
3 | +结构: | ||
4 | +div.passport-captch | ||
5 | + input | ||
6 | + div | ||
7 | + img | ||
8 | + button | ||
9 | + | ||
10 | +emmet: | ||
11 | +div.passport-captch>input+div>img+button | ||
12 | + | ||
13 | +*/ | ||
14 | + | ||
15 | +.passport-captcha { | ||
16 | + text-align: left; | ||
17 | + | ||
18 | + input { | ||
19 | + display: inline-block; | ||
20 | + width: 50%; | ||
21 | + position: relative; | ||
22 | + padding-left: 15px; | ||
23 | + height: 52PX; | ||
24 | + font-size: 20PX; | ||
25 | + background-color: #575757; | ||
26 | + border: 1px solid #606060; | ||
27 | + border-radius: 5PX; | ||
28 | + color: #fff; | ||
29 | + } | ||
30 | +} | ||
31 | + | ||
32 | +.passport-captcha-img { | ||
33 | + width: 50%; | ||
34 | + float: right; | ||
35 | + text-align: right; | ||
36 | + | ||
37 | + img { | ||
38 | + display: inline-block; | ||
39 | + margin-right: 30px; | ||
40 | + background-color: #fff; | ||
41 | + height: 52PX; | ||
42 | + width: 90PX; | ||
43 | + vertical-align: bottom; | ||
44 | + } | ||
45 | +} | ||
46 | + | ||
47 | +.passport-captcha-refresh { | ||
48 | + display: inline-block; | ||
49 | + text-decoration: underline; | ||
50 | + font-size: 18px; | ||
51 | + color: #ff1901; | ||
52 | + background-color: transparent; | ||
53 | + padding: 0; | ||
54 | + margin: 0; | ||
55 | + border: 0; | ||
56 | + outline: 0; | ||
57 | +} |
-
Please register or login to post a comment