Showing
1 changed file
with
19 additions
and
19 deletions
@@ -15,7 +15,7 @@ const RegService = require('../models/reg-service'); | @@ -15,7 +15,7 @@ const RegService = require('../models/reg-service'); | ||
15 | const AuthHelper = require('../models/auth-helper'); | 15 | const AuthHelper = require('../models/auth-helper'); |
16 | 16 | ||
17 | let index = (req, res) => { | 17 | let index = (req, res) => { |
18 | - // 设置注册有效时间30分钟, 防机器刷 | 18 | + // 设置注册有效时间30分钟, 防机器刷 |
19 | req.session._REG_EXPIRE = Date.now() + 1800000; | 19 | req.session._REG_EXPIRE = Date.now() + 1800000; |
20 | 20 | ||
21 | let refer = req.query.refer; | 21 | let refer = req.query.refer; |
@@ -43,13 +43,13 @@ let verifyMobile = (req, res, next) => { | @@ -43,13 +43,13 @@ let verifyMobile = (req, res, next) => { | ||
43 | let mobile = +req.body.phoneNum; | 43 | let mobile = +req.body.phoneNum; |
44 | let area = +(req.body.areaCode || 86); | 44 | let area = +(req.body.areaCode || 86); |
45 | 45 | ||
46 | - /* 判断参数是否合法 */ | 46 | + // 判断参数是否合法 |
47 | if (!_.isNumber(mobile) || !_.isNumber(area)) { | 47 | if (!_.isNumber(mobile) || !_.isNumber(area)) { |
48 | data.message = '手机号错误'; | 48 | data.message = '手机号错误'; |
49 | return res.json(data); | 49 | return res.json(data); |
50 | } | 50 | } |
51 | 51 | ||
52 | - /* 设置注册有效时间30分钟, 防机器刷 */ | 52 | + // 设置注册有效时间30分钟, 防机器刷 |
53 | let expire = req.session._REG_EXPIRE; | 53 | let expire = req.session._REG_EXPIRE; |
54 | 54 | ||
55 | if (!expire || expire < Date.now()) { | 55 | if (!expire || expire < Date.now()) { |
@@ -57,13 +57,13 @@ let verifyMobile = (req, res, next) => { | @@ -57,13 +57,13 @@ let verifyMobile = (req, res, next) => { | ||
57 | return res.json(data); | 57 | return res.json(data); |
58 | } | 58 | } |
59 | 59 | ||
60 | - /* 向手机发送注册验证码 */ | 60 | + // 向手机发送注册验证码 |
61 | RegService.sendCodeToMobile(area, mobile).then((result) => { | 61 | RegService.sendCodeToMobile(area, mobile).then((result) => { |
62 | if (!result.code) { | 62 | if (!result.code) { |
63 | return res.json(data); | 63 | return res.json(data); |
64 | } | 64 | } |
65 | 65 | ||
66 | - /* 返回跳转到验证页面的链接 */ | 66 | + // 返回跳转到验证页面的链接 |
67 | if (result.code === 200) { | 67 | if (result.code === 200) { |
68 | let token = sign.makeToken(mobile); | 68 | let token = sign.makeToken(mobile); |
69 | 69 | ||
@@ -82,7 +82,7 @@ let codeAction = (req, res, next) => { | @@ -82,7 +82,7 @@ let codeAction = (req, res, next) => { | ||
82 | let mobile = +req.query.phoneNum; | 82 | let mobile = +req.query.phoneNum; |
83 | let area = +(req.query.areaCode || 86); | 83 | let area = +(req.query.areaCode || 86); |
84 | 84 | ||
85 | - // 判断是否允许访问, 不允许则跳转到错误页面 | 85 | + // 判断是否允许访问, 不允许则跳转到错误页面 |
86 | if (!_.isString(token) || !_.isNumber(mobile) || !sign.verifyToken(mobile, token)) { | 86 | if (!_.isString(token) || !_.isNumber(mobile) || !sign.verifyToken(mobile, token)) { |
87 | return next({ | 87 | return next({ |
88 | code: 403, | 88 | code: 403, |
@@ -112,13 +112,13 @@ let sendCode = (req, res, next) => { | @@ -112,13 +112,13 @@ let sendCode = (req, res, next) => { | ||
112 | let mobile = +req.body.phoneNum; | 112 | let mobile = +req.body.phoneNum; |
113 | let area = +(req.body.areaCode || 86); | 113 | let area = +(req.body.areaCode || 86); |
114 | 114 | ||
115 | - /* 判断参数是否合法 */ | 115 | + // 判断参数是否合法 |
116 | if (!_.isNumber(mobile) || !_.isNumber(area)) { | 116 | if (!_.isNumber(mobile) || !_.isNumber(area)) { |
117 | data.message = '手机号错误'; | 117 | data.message = '手机号错误'; |
118 | return res.json(data); | 118 | return res.json(data); |
119 | } | 119 | } |
120 | 120 | ||
121 | - /* 设置注册有效时间30分钟, 防机器刷 */ | 121 | + // 设置注册有效时间30分钟, 防机器刷 |
122 | let expire = req.session._REG_EXPIRE; | 122 | let expire = req.session._REG_EXPIRE; |
123 | 123 | ||
124 | if (!expire || expire < Date.now()) { | 124 | if (!expire || expire < Date.now()) { |
@@ -126,7 +126,7 @@ let sendCode = (req, res, next) => { | @@ -126,7 +126,7 @@ let sendCode = (req, res, next) => { | ||
126 | return res.json(data); | 126 | return res.json(data); |
127 | } | 127 | } |
128 | 128 | ||
129 | - /* 向手机发送注册验证码 */ | 129 | + // 向手机发送注册验证码 |
130 | RegService.sendCodeToMobile(area, mobile).then((result) => { | 130 | RegService.sendCodeToMobile(area, mobile).then((result) => { |
131 | return result.code ? res.json(result) : res.json(data); | 131 | return result.code ? res.json(result) : res.json(data); |
132 | }).catch(next); | 132 | }).catch(next); |
@@ -148,7 +148,7 @@ let verifyCode = (req, res, next) => { | @@ -148,7 +148,7 @@ let verifyCode = (req, res, next) => { | ||
148 | return res.json(data); | 148 | return res.json(data); |
149 | } | 149 | } |
150 | 150 | ||
151 | - /* 设置注册有效时间30分钟, 防机器刷 */ | 151 | + // 设置注册有效时间30分钟, 防机器刷 |
152 | let expire = req.session._REG_EXPIRE; | 152 | let expire = req.session._REG_EXPIRE; |
153 | 153 | ||
154 | if (!expire || expire < Date.now()) { | 154 | if (!expire || expire < Date.now()) { |
@@ -156,13 +156,13 @@ let verifyCode = (req, res, next) => { | @@ -156,13 +156,13 @@ let verifyCode = (req, res, next) => { | ||
156 | return res.json(data); | 156 | return res.json(data); |
157 | } | 157 | } |
158 | 158 | ||
159 | - /* 验证注册的标识码是否有效 */ | 159 | + // 验证注册的标识码是否有效 |
160 | RegService.validMobileCode(area, mobile, code).then((result) => { | 160 | RegService.validMobileCode(area, mobile, code).then((result) => { |
161 | if (!result.code) { | 161 | if (!result.code) { |
162 | return res.json(data); | 162 | return res.json(data); |
163 | } | 163 | } |
164 | 164 | ||
165 | - /* 返回跳转到设置密码的链接 */ | 165 | + // 返回跳转到设置密码的链接 |
166 | if (result.code === 200) { | 166 | if (result.code === 200) { |
167 | let token = sign.makeToken(mobile); | 167 | let token = sign.makeToken(mobile); |
168 | 168 | ||
@@ -183,7 +183,7 @@ let passwordAction = (req, res, next) => { | @@ -183,7 +183,7 @@ let passwordAction = (req, res, next) => { | ||
183 | let mobile = +req.query.phoneNum; | 183 | let mobile = +req.query.phoneNum; |
184 | let area = +(req.query.areaCode || 86); | 184 | let area = +(req.query.areaCode || 86); |
185 | 185 | ||
186 | - // 判断是否允许访问, 不允许则跳转到错误页面 | 186 | + // 判断是否允许访问, 不允许则跳转到错误页面 |
187 | if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !sign.verifyToken(mobile, token)) { | 187 | if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !sign.verifyToken(mobile, token)) { |
188 | return next({ | 188 | return next({ |
189 | code: 403, | 189 | code: 403, |
@@ -214,27 +214,27 @@ let setPassword = (req, res, next) => { | @@ -214,27 +214,27 @@ let setPassword = (req, res, next) => { | ||
214 | let password = req.body.password; | 214 | let password = req.body.password; |
215 | let token = req.body.token; | 215 | let token = req.body.token; |
216 | 216 | ||
217 | - /* 判断参数是否合法 */ | 217 | + // 判断参数是否合法 |
218 | if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) { | 218 | if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) { |
219 | data.message = '请求参数不合法'; | 219 | data.message = '请求参数不合法'; |
220 | return res.json(data); | 220 | return res.json(data); |
221 | } | 221 | } |
222 | 222 | ||
223 | - /* 判断是否允许访问 */ | 223 | + // 判断是否允许访问 |
224 | if (!sign.verifyToken(mobile, token)) { | 224 | if (!sign.verifyToken(mobile, token)) { |
225 | data.message = '非法 token'; | 225 | data.message = '非法 token'; |
226 | return res.json(data); | 226 | return res.json(data); |
227 | } | 227 | } |
228 | 228 | ||
229 | - /* 判断密码是否符合规则 */ | 229 | + // 判断密码是否符合规则 |
230 | if (!helpers.verifyPassword(password)) { | 230 | if (!helpers.verifyPassword(password)) { |
231 | return res.json(data); | 231 | return res.json(data); |
232 | } | 232 | } |
233 | 233 | ||
234 | - // 购物车key | 234 | + // 购物车key |
235 | let shoppingKey = cookie.getShoppingKey(req); | 235 | let shoppingKey = cookie.getShoppingKey(req); |
236 | 236 | ||
237 | - // 验证注册的标识码是否有效 | 237 | + // 验证注册的标识码是否有效 |
238 | RegService.regMobile(area, mobile, password, shoppingKey).then((result) => { | 238 | RegService.regMobile(area, mobile, password, shoppingKey).then((result) => { |
239 | if (!result.code || result.code !== 200) { | 239 | if (!result.code || result.code !== 200) { |
240 | return Promise.reject(result); | 240 | return Promise.reject(result); |
@@ -245,7 +245,7 @@ let setPassword = (req, res, next) => { | @@ -245,7 +245,7 @@ let setPassword = (req, res, next) => { | ||
245 | 245 | ||
246 | return AuthHelper.syncUserSession(result.data.uid, req, res); | 246 | return AuthHelper.syncUserSession(result.data.uid, req, res); |
247 | }).then(() => { | 247 | }).then(() => { |
248 | - // 返回跳转到来源页面 | 248 | + // 返回跳转到来源页面 |
249 | let refer = req.cookies.refer; | 249 | let refer = req.cookies.refer; |
250 | 250 | ||
251 | if (refer) { | 251 | if (refer) { |
-
Please register or login to post a comment