Authored by htoooth

controller ok

1 /** 1 /**
2 * 找回密码 2 * 找回密码
3 - * Created by yoho on 2016/6/12. 3 + * Created by Tao.Huang on 2016/6/12.
4 */ 4 */
5 5
6 'use strict'; 6 'use strict';
@@ -12,19 +12,21 @@ const helpers = require(`${library}/helpers`); @@ -12,19 +12,21 @@ const helpers = require(`${library}/helpers`);
12 12
13 const service = require('../models/back-service'); 13 const service = require('../models/back-service');
14 14
  15 +const SIGN_IN_URL = helpers.urlFormat('signin.html');
  16 +
15 /** 17 /**
16 - * 通过邮箱找回密码 18 + * 通过邮箱找回密码页面
17 */ 19 */
18 -module.exports.indexByEmail = (req, res) => { 20 +module.exports.indexPageByEmail = (req, res) => {
19 21
20 let data = { 22 let data = {
21 - backUrl: helpers.urlFormat('signin.html'), 23 + backUrl: SIGN_IN_URL,
22 headerText: '找回密码', 24 headerText: '找回密码',
23 isPassportPage: true, 25 isPassportPage: true,
24 backEmail: true 26 backEmail: true
25 }; 27 };
26 28
27 - res.render('back/by-email', Object.assign({ 29 + res.render('back/email', Object.assign({
28 module: 'passport', 30 module: 'passport',
29 page: 'back', 31 page: 'back',
30 title: '找回密码-通过邮箱' 32 title: '找回密码-通过邮箱'
@@ -35,7 +37,7 @@ module.exports.indexByEmail = (req, res) => { @@ -35,7 +37,7 @@ module.exports.indexByEmail = (req, res) => {
35 /** 37 /**
36 * 发送验证码到邮箱 38 * 发送验证码到邮箱
37 */ 39 */
38 -module.exports.sendEmail = (req, res, next) => { 40 +module.exports.sendCodeToEmailAPI = (req, res, next) => {
39 let email = req.body.email || ''; 41 let email = req.body.email || '';
40 42
41 if (!helpers.verifyEmail(email)) { 43 if (!helpers.verifyEmail(email)) {
@@ -59,9 +61,9 @@ module.exports.sendEmail = (req, res, next) => { @@ -59,9 +61,9 @@ module.exports.sendEmail = (req, res, next) => {
59 }; 61 };
60 62
61 /** 63 /**
62 - * 重新发送邮箱验证码 64 + * 重新发送验证码到邮箱
63 */ 65 */
64 -module.exports.resendEmail = (req, res) => { 66 +module.exports.resendCodeToEmailAPI = (req, res) => {
65 let email = req.params.email || ''; 67 let email = req.params.email || '';
66 68
67 service.sendCodeToEmailAsync(email).then(result => { 69 service.sendCodeToEmailAsync(email).then(result => {
@@ -79,9 +81,9 @@ module.exports.resendEmail = (req, res) => { @@ -79,9 +81,9 @@ module.exports.resendEmail = (req, res) => {
79 }; 81 };
80 82
81 /** 83 /**
82 - * 邮箱找回密码-成功 84 + * 邮箱找回密码-返回成功页面
83 */ 85 */
84 -module.exports.success = (req, res) => { 86 +module.exports.backSuccessPageByEmail = (req, res) => {
85 let email = req.params.email || ''; 87 let email = req.params.email || '';
86 88
87 if (!helpers.verifyEmail(email)) { 89 if (!helpers.verifyEmail(email)) {
@@ -92,7 +94,9 @@ module.exports.success = (req, res) => { @@ -92,7 +94,9 @@ module.exports.success = (req, res) => {
92 94
93 let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`; 95 let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`;
94 96
95 - res.render('email-success', { 97 +
  98 +
  99 + res.render('back/email-success', {
96 backUrl: helpers.urlFormat('emailback.html'), 100 backUrl: helpers.urlFormat('emailback.html'),
97 headerText: '找回密码', 101 headerText: '找回密码',
98 isPassportPage: true, 102 isPassportPage: true,
@@ -107,14 +111,14 @@ module.exports.success = (req, res) => { @@ -107,14 +111,14 @@ module.exports.success = (req, res) => {
107 /** 111 /**
108 * 根据邮箱修改密码 112 * 根据邮箱修改密码
109 */ 113 */
110 -module.exports.success = (req, res) => { 114 +module.exports.changePasswordByEmailAPI = (req, res) => {
111 let pwd = req.body.password || ''; 115 let pwd = req.body.password || '';
112 116
113 let code = req.body.code || ''; 117 let code = req.body.code || '';
114 118
115 let data = { 119 let data = {
116 code: 200, 120 code: 200,
117 - data: helpers.urlFormat('signin.html') 121 + data: SIGN_IN_URL
118 }; 122 };
119 123
120 service.modifyPasswordByEmailAsync(pwd, code).then(result => { 124 service.modifyPasswordByEmailAsync(pwd, code).then(result => {
@@ -132,10 +136,10 @@ module.exports.success = (req, res) => { @@ -132,10 +136,10 @@ module.exports.success = (req, res) => {
132 /** 136 /**
133 * 找回密码-通过手机号 137 * 找回密码-通过手机号
134 */ 138 */
135 -module.exports.indexByMobile = (req, res) => { 139 +module.exports.indexPageByMobile = (req, res) => {
136 service.getAreaDataAsync().then(result => { 140 service.getAreaDataAsync().then(result => {
137 res.render('mobile', { 141 res.render('mobile', {
138 - backUrl: helpers.urlFormat('signin.html'), 142 + backUrl: SIGN_IN_URL,
139 headerText: '找回密码', 143 headerText: '找回密码',
140 isPassportPage: true, 144 isPassportPage: true,
141 backMobile: true, 145 backMobile: true,
@@ -149,7 +153,7 @@ module.exports.indexByMobile = (req, res) => { @@ -149,7 +153,7 @@ module.exports.indexByMobile = (req, res) => {
149 /** 153 /**
150 * 发送手机验证码 154 * 发送手机验证码
151 */ 155 */
152 -module.exports.sendVerifyCodeBySMS = (req, res) => { 156 +module.exports.sendCodeToMobileAPI = (req, res) => {
153 let result = { 157 let result = {
154 code: 400, 158 code: 400,
155 message: '密码只能使用数字、字母和半角标点符号,请重新输入', 159 message: '密码只能使用数字、字母和半角标点符号,请重新输入',
@@ -162,6 +166,7 @@ module.exports.sendVerifyCodeBySMS = (req, res) => { @@ -162,6 +166,7 @@ module.exports.sendVerifyCodeBySMS = (req, res) => {
162 166
163 if (!helpers.verifyMobile(phoneNum)) { 167 if (!helpers.verifyMobile(phoneNum)) {
164 res.json(result); 168 res.json(result);
  169 + return;
165 } 170 }
166 171
167 service.sendCodeToMobileAsync(phoneNum, areaCode).then(data=> { 172 service.sendCodeToMobileAsync(phoneNum, areaCode).then(data=> {
@@ -186,3 +191,97 @@ module.exports.sendVerifyCodeBySMS = (req, res) => { @@ -186,3 +191,97 @@ module.exports.sendVerifyCodeBySMS = (req, res) => {
186 191
187 }; 192 };
188 193
  194 +/**
  195 + * 校验验证码页面
  196 + */
  197 +module.exports.VerifyCodePageByMobile = (req, res) => {
  198 + let phoneNum = req.params.phoneNum || '';
  199 +
  200 + let areaCode = `+${(req.params.areaCode || '86')}`;
  201 +
  202 + res.render('mobile-code', {
  203 + backUrl: helpers.urlFormat('phoneback.html'),
  204 + headerText: '找回密码',
  205 + isPassportPage: true,
  206 + backCode: true,
  207 + areaCode: areaCode,
  208 + phoneNum: phoneNum
  209 + });
  210 +};
  211 +
  212 +/**
  213 + * 校验手机验证码
  214 + */
  215 +module.exports.verifyCodeByMobileAPI = (req, res) => {
  216 + let phoneNum = req.body.phoneNum || '';
  217 +
  218 + let code = req.body.code || '';
  219 +
  220 + let areaCode = req.body.areaCode || '86';
  221 +
  222 + service.validateMobileCodeAsync(phoneNum, code, areaCode)
  223 + .then(result => {
  224 + if (result.code === 200) {
  225 + result.data = helpers.urlFormat('passport/back/backcode', {
  226 + phoneNum: phoneNum,
  227 + token: result.data.token,
  228 + areaCode: areaCode
  229 + });
  230 + }
  231 +
  232 + res.json(result);
  233 + }).catch(() => res.json({code: 400, message: '验证码失购'}));
  234 +};
  235 +
  236 +/**
  237 + * 找回密码页面,设置新密码页面-手机
  238 + */
  239 +module.exports.forgotPasswordPageByMobile = (req, res) => {
  240 + let phoneNum = req.params.phoneNum || '';
  241 +
  242 + let token = req.params.token || '';
  243 +
  244 + let areaCode = req.params.areaCode || '86';
  245 +
  246 + let code = req.params.code || '';
  247 +
  248 + if (!token || (!helpers.verifyMobile(phoneNum) && !code)) {
  249 + res.redirect(400);
  250 + return;
  251 + }
  252 +
  253 + res.render('new-password', {
  254 + backUrl: SIGN_IN_URL,
  255 + headerText: '找回密码',
  256 + isPassportPage: true,
  257 + backNewPwd: true,
  258 + phoneNum: phoneNum,
  259 + token: token,
  260 + areaCode: areaCode,
  261 + code: code,
  262 + title: '找回密码-输入新密码'
  263 + });
  264 +};
  265 +
  266 +/**
  267 + * 根据手机验证码修改密码
  268 + */
  269 +module.exports.changePasswordByMobileAPI = (req, res) => {
  270 + let phoneNum = req.body.phoneNum || '';
  271 +
  272 + let token = req.body.token || '';
  273 +
  274 + let areaCode = req.body.areaCode || '86';
  275 +
  276 + let newPwd = req.body.password || '';
  277 +
  278 + service.modifyPasswordByMobileAsync(phoneNum, token, newPwd, areaCode)
  279 + .then(result => {
  280 + if (result.code === 200) {
  281 + result.data = SIGN_IN_URL;
  282 + }
  283 +
  284 + res.json(result);
  285 + }).catch(() => res.json({code: 400, message: '修改密码失败'}));
  286 +};
  287 +
1 /** 1 /**
2 - * Created by TaoHuang on 2016/6/14. 2 + * Created by Tao.Huang on 2016/6/14.
3 */ 3 */
4 4
5 'use strict'; 5 'use strict';
1 -/**  
2 - * Created by yoho on 2016/6/12.  
3 - */  
4 -  
5 -module.exports.email = (email) => {  
6 - email;  
7 -  
8 -};  
9 -