Authored by htoooth

add assets.

Showing 59 changed files with 763 additions and 188 deletions
@@ -12,7 +12,9 @@ const helpers = require(`${library}/helpers`); @@ -12,7 +12,9 @@ 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'); 15 +// helpers.urlFormat = helpers.fakeUrlFormat;
  16 +
  17 +const SIGN_IN_URL = helpers.urlFormat('/signin.html');
16 18
17 /** 19 /**
18 * 通过邮箱找回密码页面 20 * 通过邮箱找回密码页面
@@ -28,47 +30,48 @@ module.exports.indexPageByEmail = (req, res) => { @@ -28,47 +30,48 @@ module.exports.indexPageByEmail = (req, res) => {
28 30
29 res.render('back/email', Object.assign({ 31 res.render('back/email', Object.assign({
30 module: 'passport', 32 module: 'passport',
31 - page: 'back', 33 + page: 'back-email',
32 title: '找回密码-通过邮箱' 34 title: '找回密码-通过邮箱'
33 - }, data)  
34 - ); 35 + }, data));
35 }; 36 };
36 37
37 /** 38 /**
38 * 发送验证码到邮箱 39 * 发送验证码到邮箱
39 */ 40 */
40 -module.exports.sendCodeToEmailAPI = (req, res, next) => { 41 +module.exports.sendCodeToEmailAPI = (req, res) => {
41 let email = req.body.email || ''; 42 let email = req.body.email || '';
42 43
43 - if (!helpers.verifyEmail(email)) {  
44 -  
45 - res.json({  
46 - code: 400,  
47 - message: '邮箱格式不正确,请重新输入',  
48 - data: ''  
49 - }); 44 + let error = {
  45 + code: 400,
  46 + message: '邮箱格式不正确,请重新输入',
  47 + data: ''
  48 + };
50 49
  50 + if (!helpers.verifyEmail(email)) {
  51 + res.json(error);
51 return; 52 return;
52 } 53 }
53 54
54 service.sendCodeToEmailAsync(email).then(result => { 55 service.sendCodeToEmailAsync(email).then(result => {
55 if (result.code === 200) { 56 if (result.code === 200) {
56 - result.data = helpers.urlFormat('passport/back/success', {email: email}); 57 + result.data = helpers.urlFormat('/passport/back/success.html', {email: email});
57 } 58 }
58 59
59 res.json(result); 60 res.json(result);
60 - }).catch(next); 61 + }).catch(() => {
  62 + res.json(error);
  63 + });
61 }; 64 };
62 65
63 /** 66 /**
64 * 重新发送验证码到邮箱 67 * 重新发送验证码到邮箱
65 */ 68 */
66 module.exports.resendCodeToEmailAPI = (req, res) => { 69 module.exports.resendCodeToEmailAPI = (req, res) => {
67 - let email = req.params.email || ''; 70 + let email = req.query.email || '';
68 71
69 service.sendCodeToEmailAsync(email).then(result => { 72 service.sendCodeToEmailAsync(email).then(result => {
70 if (_.isEmpty(result)) { 73 if (_.isEmpty(result)) {
71 - return Promise.rejected('重发邮件失败'); 74 + return Promise.rejected('重发邮件失败');
72 } 75 }
73 76
74 res.json(result); 77 res.json(result);
@@ -84,7 +87,7 @@ module.exports.resendCodeToEmailAPI = (req, res) => { @@ -84,7 +87,7 @@ module.exports.resendCodeToEmailAPI = (req, res) => {
84 * 邮箱找回密码-返回成功页面 87 * 邮箱找回密码-返回成功页面
85 */ 88 */
86 module.exports.backSuccessPageByEmail = (req, res) => { 89 module.exports.backSuccessPageByEmail = (req, res) => {
87 - let email = req.params.email || ''; 90 + let email = req.query.email || '';
88 91
89 if (!helpers.verifyEmail(email)) { 92 if (!helpers.verifyEmail(email)) {
90 res.redirect(400); 93 res.redirect(400);
@@ -95,23 +98,25 @@ module.exports.backSuccessPageByEmail = (req, res) => { @@ -95,23 +98,25 @@ module.exports.backSuccessPageByEmail = (req, res) => {
95 let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`; 98 let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`;
96 99
97 100
98 -  
99 - res.render('back/email-success', {  
100 - backUrl: helpers.urlFormat('emailback.html'), 101 + res.render('back/email-success', Object.assign({
  102 + module: 'passport',
  103 + page: 'back-email-success',
  104 + title: '找回密码-通过邮箱'
  105 + }, {
  106 + backUrl: helpers.urlFormat('/passport/back/email.html'),
101 headerText: '找回密码', 107 headerText: '找回密码',
102 isPassportPage: true, 108 isPassportPage: true,
103 backEmailSuccess: true, 109 backEmailSuccess: true,
104 goEmail: emailUrl, 110 goEmail: emailUrl,
105 - resendUrl: helpers.urlFormat('passport/back/resendemail', {email: email}),  
106 - title: '找回密码-通过邮箱'  
107 - }); 111 + resendUrl: helpers.urlFormat('/passport/back/resendemail', {email: email})
  112 + }));
108 }; 113 };
109 114
110 115
111 /** 116 /**
112 * 根据邮箱修改密码 117 * 根据邮箱修改密码
113 */ 118 */
114 -module.exports.changePasswordByEmailAPI = (req, res) => { 119 +module.exports.setNewPasswordByEmailAPI = (req, res) => {
115 let pwd = req.body.password || ''; 120 let pwd = req.body.password || '';
116 121
117 let code = req.body.code || ''; 122 let code = req.body.code || '';
@@ -134,20 +139,25 @@ module.exports.changePasswordByEmailAPI = (req, res) => { @@ -134,20 +139,25 @@ module.exports.changePasswordByEmailAPI = (req, res) => {
134 }; 139 };
135 140
136 /** 141 /**
137 - * 找回密码-通过手机号 142 + * 找回密码页面-通过手机号
138 */ 143 */
139 -module.exports.indexPageByMobile = (req, res) => {  
140 - service.getAreaDataAsync().then(result => {  
141 - res.render('mobile', {  
142 - backUrl: SIGN_IN_URL,  
143 - headerText: '找回密码',  
144 - isPassportPage: true,  
145 - backMobile: true,  
146 - countrys: result,  
147 - areaCode: '+86',  
148 - title: '找回密码-通过手机号'  
149 - });  
150 - }); 144 +module.exports.indexPageByMobile = (req, res, next) => {
  145 +
  146 + service.getAreaDataAsync()
  147 + .then(result => {
  148 + res.render('back/mobile', Object.assign({
  149 + module: 'passport',
  150 + page: 'back-mobile',
  151 + title: '找回密码-通过手机号'
  152 + }, {
  153 + backUrl: SIGN_IN_URL,
  154 + headerText: '找回密码',
  155 + isPassportPage: true,
  156 + backMobile: true,
  157 + countrys: result.data,
  158 + areaCode: '+86'
  159 + }));
  160 + }).catch(next);
151 }; 161 };
152 162
153 /** 163 /**
@@ -175,7 +185,7 @@ module.exports.sendCodeToMobileAPI = (req, res) => { @@ -175,7 +185,7 @@ module.exports.sendCodeToMobileAPI = (req, res) => {
175 } 185 }
176 186
177 if (data.code === 200) { 187 if (data.code === 200) {
178 - result.data = helpers.urlFormat('passport/back/mobilecode', { 188 + result.data = helpers.urlFormat('/passport/back/verifycode', {
179 phoneNum: phoneNum, 189 phoneNum: phoneNum,
180 areaCode: areaCode 190 areaCode: areaCode
181 }); 191 });
@@ -194,19 +204,24 @@ module.exports.sendCodeToMobileAPI = (req, res) => { @@ -194,19 +204,24 @@ module.exports.sendCodeToMobileAPI = (req, res) => {
194 /** 204 /**
195 * 校验验证码页面 205 * 校验验证码页面
196 */ 206 */
197 -module.exports.VerifyCodePageByMobile = (req, res) => {  
198 - let phoneNum = req.params.phoneNum || ''; 207 +module.exports.verifyCodePageByMobile = (req, res) => {
  208 + let phoneNum = req.query.phoneNum || '';
199 209
200 - let areaCode = `+${(req.params.areaCode || '86')}`; 210 + let areaCode = `+${(req.query.areaCode || '86')}`;
201 211
202 - res.render('mobile-code', {  
203 - backUrl: helpers.urlFormat('phoneback.html'), 212 + res.render('back/mobile-code', Object.assign({
  213 + module: 'passport',
  214 + page: 'mobile-code',
  215 + title: '找回密码-通过手机号'
  216 + }, {
  217 + backUrl: helpers.urlFormat('/passport/back/mobile.html'),
204 headerText: '找回密码', 218 headerText: '找回密码',
205 isPassportPage: true, 219 isPassportPage: true,
206 backCode: true, 220 backCode: true,
207 areaCode: areaCode, 221 areaCode: areaCode,
208 phoneNum: phoneNum 222 phoneNum: phoneNum
209 - }); 223 +
  224 + }));
210 }; 225 };
211 226
212 /** 227 /**
@@ -222,7 +237,7 @@ module.exports.verifyCodeByMobileAPI = (req, res) => { @@ -222,7 +237,7 @@ module.exports.verifyCodeByMobileAPI = (req, res) => {
222 service.validateMobileCodeAsync(phoneNum, code, areaCode) 237 service.validateMobileCodeAsync(phoneNum, code, areaCode)
223 .then(result => { 238 .then(result => {
224 if (result.code === 200) { 239 if (result.code === 200) {
225 - result.data = helpers.urlFormat('passport/back/backcode', { 240 + result.data = helpers.urlFormat('/passport/back/backcode.html', {
226 phoneNum: phoneNum, 241 phoneNum: phoneNum,
227 token: result.data.token, 242 token: result.data.token,
228 areaCode: areaCode 243 areaCode: areaCode
@@ -230,27 +245,31 @@ module.exports.verifyCodeByMobileAPI = (req, res) => { @@ -230,27 +245,31 @@ module.exports.verifyCodeByMobileAPI = (req, res) => {
230 } 245 }
231 246
232 res.json(result); 247 res.json(result);
233 - }).catch(() => res.json({code: 400, message: '验证码失'})); 248 + }).catch(() => res.json({code: 400, message: '验证码失'}));
234 }; 249 };
235 250
236 /** 251 /**
237 * 找回密码页面,设置新密码页面-手机 252 * 找回密码页面,设置新密码页面-手机
238 */ 253 */
239 -module.exports.forgotPasswordPageByMobile = (req, res) => {  
240 - let phoneNum = req.params.phoneNum || ''; 254 +module.exports.setNewPasswordPageByMobile = (req, res) => {
  255 + let phoneNum = req.query.phoneNum || '';
241 256
242 - let token = req.params.token || ''; 257 + let token = req.query.token || '';
243 258
244 - let areaCode = req.params.areaCode || '86'; 259 + let areaCode = req.query.areaCode || '86';
245 260
246 - let code = req.params.code || ''; 261 + let code = req.query.code || '';
247 262
248 if (!token || (!helpers.verifyMobile(phoneNum) && !code)) { 263 if (!token || (!helpers.verifyMobile(phoneNum) && !code)) {
249 res.redirect(400); 264 res.redirect(400);
250 return; 265 return;
251 } 266 }
252 267
253 - res.render('new-password', { 268 + res.render('back/new-password', Object.assign({
  269 + module: 'passport',
  270 + page: 'back-new-password',
  271 + title: '找回密码-输入新密码'
  272 + }, {
254 backUrl: SIGN_IN_URL, 273 backUrl: SIGN_IN_URL,
255 headerText: '找回密码', 274 headerText: '找回密码',
256 isPassportPage: true, 275 isPassportPage: true,
@@ -258,15 +277,14 @@ module.exports.forgotPasswordPageByMobile = (req, res) => { @@ -258,15 +277,14 @@ module.exports.forgotPasswordPageByMobile = (req, res) => {
258 phoneNum: phoneNum, 277 phoneNum: phoneNum,
259 token: token, 278 token: token,
260 areaCode: areaCode, 279 areaCode: areaCode,
261 - code: code,  
262 - title: '找回密码-输入新密码'  
263 - }); 280 + code: code
  281 + }));
264 }; 282 };
265 283
266 /** 284 /**
267 * 根据手机验证码修改密码 285 * 根据手机验证码修改密码
268 */ 286 */
269 -module.exports.changePasswordByMobileAPI = (req, res) => { 287 +module.exports.setNewPasswordByMobileAPI = (req, res) => {
270 let phoneNum = req.body.phoneNum || ''; 288 let phoneNum = req.body.phoneNum || '';
271 289
272 let token = req.body.token || ''; 290 let token = req.body.token || '';
@@ -9,12 +9,53 @@ @@ -9,12 +9,53 @@
9 const express = require('express'); 9 const express = require('express');
10 const cRoot = './controllers'; 10 const cRoot = './controllers';
11 const login = require(cRoot + '/login'); 11 const login = require(cRoot + '/login');
  12 +const back = require(cRoot + '/back');
12 13
13 const router = express.Router(); // eslint-disable-line 14 const router = express.Router(); // eslint-disable-line
14 15
15 router.get('/login', login.local.loginPage); 16 router.get('/login', login.local.loginPage);
16 router.get('/login/wechat', login.wechat.beforeLogin, login.wechat.login); // 登录 17 router.get('/login/wechat', login.wechat.beforeLogin, login.wechat.login); // 登录
17 router.get('/login/wechat/callback', login.wechat.callback); 18 router.get('/login/wechat/callback', login.wechat.callback);
18 -router.get('/ '); 19 +
  20 +/**
  21 + * 邮箱
  22 + */
  23 +
  24 +// 通过邮箱找回密码
  25 +router.get('/back/email.html', back.indexPageByEmail);
  26 +
  27 +// 发送邮箱验证码
  28 +router.post('/back/sendemail', back.sendCodeToEmailAPI);
  29 +
  30 +// 重新发送邮箱验证码
  31 +router.get('/back/resendemail', back.resendCodeToEmailAPI);
  32 +
  33 +// 邮箱找回密码-成功
  34 +router.get('/back/success.html', back.backSuccessPageByEmail);
  35 +
  36 +// 据邮箱修改密码
  37 +router.post('/back/passwordbyemail', back.setNewPasswordByEmailAPI);
  38 +
  39 +/**
  40 + * 手机
  41 + */
  42 +
  43 +// 通过手机找回密码
  44 +router.get('/back/mobile.html', back.indexPageByMobile);
  45 +
  46 +// 发送手机验证码
  47 +router.get('/back/mobilecode.html', back.verifyCodePageByMobile);
  48 +
  49 +// 发送手机验证码
  50 +router.post('/back/sendcode', back.sendCodeToMobileAPI);
  51 +
  52 +// 校验手机验证码
  53 +router.post('/back/verifycode', back.verifyCodeByMobileAPI);
  54 +
  55 +// 找回密码
  56 +router.get('/back/backcode.html', back.setNewPasswordPageByMobile);
  57 +
  58 +// 根据手机验证码修改密码
  59 +router.post('/back/passwordbymobile', back.setNewPasswordByMobileAPI);
19 60
20 module.exports = router; 61 module.exports = router;
  1 +<div class="back-email-success-page passport-page yoho-page">
  2 + {{> passport/header}}
  3 + <div class="content">
  4 + <p class="tip">验证邮件已发送至你的邮箱</p>
  5 + <p class="sub-tip">请在24小时内通过邮件内的链接设置新密码</p>
  6 + <a class="go-email btn" href={{goEmail}}>去邮箱看看</a>
  7 + <a id="resend" class="resend" data-url={{resendUrl}}>重新发送邮件</a>
  8 + </div>
  9 +</div>
  1 +<div class="back-email-page passport-page yoho-page">
  2 + {{> passport/header}}
  3 + <div class="content">
  4 + <div class="input-container row has-clear">
  5 + <input id="email" class="input email" type="text" placeholder="请输入邮箱" autocomplete="off">
  6 + </div>
  7 + <span id="btn-sure" class="btn btn-sure disable row">确定</span>
  8 + </div>
  9 +</div>
  1 +<div class="back-code-page passport-page yoho-page">
  2 + {{> passport/code}}
  3 +</div>
  1 +<div class="back-mobile-page passport-page yoho-page">
  2 + {{> passport/header}}
  3 + <div class="content">
  4 + {{> passport/country_list}}
  5 + <div class="input-container phone-container row has-clear">
  6 + <span id="area-code" class="area-code">{{areaCode}}</span>
  7 + <input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
  8 + </div>
  9 + <span id="btn-next" class="btn btn-next disable row">下一步</span>
  10 + </div>
  11 +</div>
  1 +<div class="back-new-password-page passport-page yoho-page">
  2 + {{> passport/header}}
  3 + <div class="content">
  4 + <div class="input-container row has-eye">
  5 + <input id="pwd" class="input pwd" type="text" placeholder="请输入新密码" autocomplete="off" maxlength="20">
  6 + </div>
  7 + <span id="btn-ok" class="btn btn-ok disable">完成</span>
  8 + </div>
  9 + {{#if phoneNum}}
  10 + <input id="phone-num" type="hidden" value={{phoneNum}}>
  11 + <input id="area-code" type="hidden" value={{areaCode}}>
  12 + <input id="token" type="hidden" value={{token}}>
  13 + {{/if}}
  14 +
  15 + {{# code}}
  16 + <input id="email-code" type="hidden" value={{.}}>
  17 + {{/ code}}
  18 +</div>
  1 +{{> passport/header}}
  2 +<div class="content">
  3 + <div class="text-container">
  4 + 验证码已发送至
  5 + <span class="phone">
  6 + +{{areaCode}} {{phoneNum}}
  7 + </span>
  8 + </div>
  9 + <div class="input-container row has-clear">
  10 + <input id="captcha" class="input captcha" type="text" placeholder="验证码" maxlength="6" autocomplete="off">
  11 + <div id="captcha-tip" class="captcha-tip disable">重新发送 (60秒)</div>
  12 + </div>
  13 + <span id="btn-next" class="btn btn-next disable row">确定</span>
  14 + <div class="tip">
  15 + {{#if relateCode}}
  16 + 注:关联的手机号不能用来登录此帐号
  17 + {{/if}}
  18 + </div>
  19 + <input id="phone-num" type="hidden" value={{phoneNum}}>
  20 + <input id="area-code" type="hidden" value={{areaCode}}>
  21 + <input id="token" type="hidden" value={{token}}>
  22 +</div>
  1 +<div class="select-container row">
  2 + <span class="select-title">国家和地区</span>
  3 + <select id="country-select" class="country-select select in-android-uc">
  4 + {{# countrys}}
  5 + <option value={{areaCode}} {{#if selected}}selected{{/if}}>{{name}}</option>
  6 + {{/ countrys}}
  7 + </select>
  8 + <div class="arrow-right"></div>
  9 +</div>
@@ -73,6 +73,40 @@ exports.urlFormat = (uri, qs, module) => { @@ -73,6 +73,40 @@ exports.urlFormat = (uri, qs, module) => {
73 return url; 73 return url;
74 }; 74 };
75 75
  76 +/**
  77 + * 站内地址格式化
  78 + * @param {[string]} uri 路径
  79 + * @param {[object]} qs 查询字符串
  80 + * @param {[string]} module 模块
  81 + * @return {[string]}
  82 + */
  83 +exports.fakeUrlFormat = (uri, qs, module) => {
  84 + const subDomain = 'http://localhost:6001';
  85 + const subName = {
  86 + default: subDomain,
  87 + guang: `${subDomain}`,
  88 + list: `${subDomain}`,
  89 + search: `${subDomain}`,
  90 + huodong: `${subDomain}`,
  91 + index: subDomain
  92 + };
  93 + let url;
  94 +
  95 + module = module || 'default';
  96 + if (subName[module]) {
  97 + url = subName[module];
  98 + } else {
  99 + url = `//${module}${subDomain}`; // 规则没匹配到就把模块当作子域名
  100 + }
  101 +
  102 + url += uri;
  103 + if (qs) {
  104 + url += `?${querystring.stringify(qs)}`;
  105 + }
  106 +
  107 + return url;
  108 +};
  109 +
76 110
77 /** 111 /**
78 * 大写转小写处理 112 * 大写转小写处理
@@ -94,6 +94,7 @@ @@ -94,6 +94,7 @@
94 "yoho-handlebars": "^4.0.5", 94 "yoho-handlebars": "^4.0.5",
95 "yoho-jquery": "^2.2.4", 95 "yoho-jquery": "^2.2.4",
96 "yoho-jquery-lazyload": "^1.9.7", 96 "yoho-jquery-lazyload": "^1.9.7",
  97 + "yoho-jquery-placeholder": "^0.0.3",
97 "yoho-mlellipsis": "^0.0.3", 98 "yoho-mlellipsis": "^0.0.3",
98 "yoho-swiper": "^3.3.1" 99 "yoho-swiper": "^3.3.1"
99 } 100 }
  1 +/**
  2 + * 登录注册公用API
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/8
  5 + */
  6 +var $ = require('yoho-jquery');
  7 +
  8 +var trim = $.trim;
  9 +
  10 +// 邮箱验证规则
  11 +var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  12 +
  13 +// 手机号码验证规则
  14 +var phoneRegx = {
  15 + '+86': /^1[35847]{1}[0-9]{9}$/,
  16 + '+852': /^[965]{1}[0-9]{7}$/,
  17 + '+853': /^[0-9]{8}$/,
  18 + '+886': /^[0-9]{10}$/,
  19 + '+65': /^[98]{1}[0-9]{7}$/,
  20 + '+60': /^1[1234679]{1}[0-9]{8}$/,
  21 + '+1': /^[0-9]{10}$/,
  22 + '+82': /^01[0-9]{9}$/,
  23 + '+44': /^7[789][0-9]{8}$/,
  24 + '+81': /^0[9|8|7][0-9]{9}$/,
  25 + '+61': /^[0-9]{11}$/
  26 +};
  27 +
  28 +/**
  29 + * 密码显示隐藏
  30 + * @params opt 初始化参数
  31 + */
  32 +function bindEyesEvt(opt) {
  33 + var $hasEye = $('.has-eye'),
  34 + $eye;
  35 +
  36 + if (opt && opt.status === 'open') {
  37 + $hasEye.append('<div class="eye"></div>');
  38 + } else {
  39 + $hasEye.append('<div class="eye close"></div>');
  40 + }
  41 + $eye = $hasEye.children('.eye');
  42 +
  43 + $eye.on('touchstart', function(e) {
  44 + var $this = $(this),
  45 + $pwd = $this.siblings('.pwd');
  46 +
  47 + e.preventDefault();
  48 + $this.toggleClass('close');
  49 +
  50 + // 切换密码显示和文本显示
  51 + if ($this.hasClass('close')) {
  52 + $pwd.attr('type', 'password');
  53 + } else {
  54 + $pwd.attr('type', 'text');
  55 + }
  56 + $pwd.focus();
  57 + });
  58 +}
  59 +
  60 +// 清空账号显示
  61 +function bindClearEvt() {
  62 + var $hasClear = $('.has-clear'),
  63 + $clear;
  64 +
  65 + $hasClear.append('<div class="clear-input"></div>');
  66 + $clear = $hasClear.children('.clear-input');
  67 +
  68 + $clear.on('touchstart', function(e) {
  69 + var $input = $clear.siblings('.input');
  70 +
  71 + $input.val('').trigger('input').focus();
  72 + e.preventDefault();
  73 + });
  74 +
  75 + // 反向逻辑
  76 + $hasClear.children('.input').bind('input', function() {
  77 + var $this = $(this),
  78 + $thisClear = $this.siblings('.clear-input'),
  79 + val = trim($this.val());
  80 +
  81 + if (val === '') {
  82 + $thisClear.hide();
  83 + } else {
  84 + $thisClear.show();
  85 + }
  86 + });
  87 +}
  88 +
  89 +// 密码长度验证
  90 +function pwdValidate(pwd) {
  91 + if (pwd.length >= 6 && pwd.length <= 20) {
  92 + return true;
  93 + }
  94 + return false;
  95 +}
  96 +
  97 +// hack for resolving direction:rtl didn't work in android uc
  98 +function selectCssHack($countrySelect) {
  99 + var u = navigator.userAgent;
  100 +
  101 + function autoSelectWidth() {
  102 + var wordCount = $countrySelect.find('option:selected').text().length;
  103 +
  104 + switch (wordCount) {
  105 +
  106 + // 分别有2,3,4个汉字的情况
  107 + case 2:
  108 + $countrySelect.outerWidth(90);
  109 + break;
  110 + case 3:
  111 + $countrySelect.outerWidth(110);
  112 + break;
  113 + default:
  114 + $countrySelect.outerWidth(130);
  115 + }
  116 + }
  117 +
  118 + if (u.match(/uc/i) && u.match(/android/i)) {
  119 + $countrySelect.change(function() {
  120 + autoSelectWidth();
  121 + });
  122 + } else {
  123 + $countrySelect.removeClass('in-android-uc');
  124 + }
  125 +}
  126 +
  127 +// Exports APIs
  128 +module.exports = {
  129 + emailRegx: emailRegx,
  130 + phoneRegx: phoneRegx,
  131 + bindEyesEvt: bindEyesEvt,
  132 + bindClearEvt: bindClearEvt,
  133 + pwdValidate: pwdValidate,
  134 + selectCssHack: selectCssHack
  135 +};
  1 +/**
  2 + * Created by TaoHuang on 2016/6/15.
  3 + */
  4 +
  5 +require('./back/code');
  1 +require('./back/email-success');
  1 +require('./back/email');
  2 +
  1 +/**
  2 + * Created by TaoHuang on 2016/6/15.
  3 + */
  4 +
  5 +require('./back/mobile');
  1 +require('./back/new-password');
  1 +/**
  2 + * Created by TaoHuang on 2016/6/15.
  3 + */
  4 +require('../code')(false);
  1 +/**
  2 + * 找回密码-邮箱找回成功
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/8
  5 + */
  6 +
  7 +var $ = require('yoho-jquery');
  8 +
  9 +var $resend = $('#resend');
  10 +
  11 +var tip = require('../../plugin/tip'),
  12 + showTip = tip.show;
  13 +
  14 +$resend.on('touchstart', function(e) {
  15 + e.preventDefault();
  16 +
  17 + $.ajax({
  18 + url: $resend.data('url'),
  19 + type: 'GET',
  20 + success: function(data) {
  21 + showTip(data.message);
  22 + }
  23 + });
  24 +});
  1 +/**
  2 + * 找回密码-邮箱找回
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/8
  5 + */
  6 +var $ = require('yoho-jquery');
  7 +
  8 +var $email = $('#email'),
  9 + $btnSure = $('#btn-sure');
  10 +
  11 +var api = require('./../api');
  12 +var tip = require('../../plugin/tip');
  13 +
  14 +var trim = $.trim;
  15 +var showErrTip = tip.show;
  16 +
  17 +api.bindClearEvt();
  18 +
  19 +$email.bind('input', function() {
  20 + if (trim($email.val()) === '') {
  21 + $btnSure.addClass('disable');
  22 + } else {
  23 + $btnSure.removeClass('disable');
  24 + }
  25 +});
  26 +
  27 +$btnSure.on('touchstart', function() {
  28 + var email = trim($email.val());
  29 +
  30 + if ($btnSure.hasClass('disable')) {
  31 + return;
  32 + }
  33 +
  34 + if (api.emailRegx.test(email)) {
  35 + $.ajax({
  36 + url: '/passport/back/sendemail',
  37 + type: 'POST',
  38 + data: {
  39 + email: email
  40 + },
  41 + success: function(data) {
  42 + console.log(data);
  43 + if (data.code === 200) {
  44 + location.href = data.data;
  45 + } else {
  46 + showErrTip(data.message);
  47 + }
  48 + }
  49 + });
  50 + } else {
  51 + showErrTip('邮箱格式不正确,请重新输入');
  52 + }
  53 +});
  1 +
  2 +/**
  3 + * 找回密码-手机
  4 + * @author: xuqi<qi.xu@yoho.cn>
  5 + * @date: 2015/10/8
  6 + */
  7 +var $ = require('yoho-jquery');
  8 +
  9 +var $phoneNum = $('#phone-num'),
  10 + $countrySelect = $('#country-select'),
  11 + $areaCode = $('#area-code'),
  12 + $btnNext = $('#btn-next');
  13 +
  14 +var api = require('../api');
  15 +var tip = require('../../plugin/tip');
  16 +
  17 +var trim = $.trim;
  18 +var showErrTip = tip.show;
  19 +
  20 +api.selectCssHack($('#country-select'));
  21 +
  22 +api.bindClearEvt();
  23 +
  24 +$phoneNum.bind('input', function() {
  25 + if (trim($phoneNum.val()) === '') {
  26 + $btnNext.addClass('disable');
  27 + } else {
  28 + $btnNext.removeClass('disable');
  29 + }
  30 +});
  31 +
  32 +$countrySelect.change(function() {
  33 + $areaCode.text($countrySelect.val());
  34 +});
  35 +
  36 +$btnNext.on('touchstart', function() {
  37 + var pn = trim($phoneNum.val()),
  38 + area = $countrySelect.val();
  39 +
  40 + if ($btnNext.hasClass('disable')) {
  41 + return;
  42 + }
  43 +
  44 + if (api.phoneRegx[area].test(pn)) {
  45 + $.ajax({
  46 + url: '/passport/back/sendcode',
  47 + type: 'POST',
  48 + data: {
  49 + areaCode: area.replace('+', ''),
  50 + phoneNum: pn
  51 + },
  52 + success: function(data) {
  53 + if (data.code === 200) {
  54 + location.href = data.data;
  55 + } else {
  56 + showErrTip(data.message);
  57 + }
  58 + }
  59 + });
  60 + } else {
  61 + showErrTip('手机号格式不正确,请重新输入');
  62 + }
  63 +});
  1 +/**
  2 + * 密码找回-新密码
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/8
  5 + */
  6 +var $ = require('yoho-jquery');
  7 +
  8 +var $pwd = $('#pwd'),
  9 + $btnOk = $('#btn-ok');
  10 +
  11 +var api = require('../api');
  12 +var tip = require('../../plugin/tip');
  13 +
  14 +var trim = $.trim;
  15 +var showErrTip = tip.show;
  16 +
  17 +var $phoneNum = $('#phone-num');
  18 +
  19 +api.bindEyesEvt({
  20 + status: 'open'
  21 +});
  22 +
  23 +$pwd.bind('input', function() {
  24 + if (trim($pwd.val()) === '') {
  25 + $btnOk.addClass('disable');
  26 + } else {
  27 + $btnOk.removeClass('disable');
  28 + }
  29 +});
  30 +
  31 +$btnOk.on('touchstart', function() {
  32 + var pwd = trim($pwd.val()),
  33 + mobileBack = true,
  34 + setting,
  35 + url;
  36 +
  37 + if ($btnOk.hasClass('disable')) {
  38 + return;
  39 + }
  40 +
  41 + setting = {
  42 + password: pwd
  43 + };
  44 +
  45 + if ($phoneNum.length === 0) {
  46 + mobileBack = false;
  47 + }
  48 +
  49 + if (mobileBack) {
  50 + $.extend(setting, {
  51 + phoneNum: $phoneNum.val(),
  52 + areaCode: $('#areaCode').val(),
  53 + token: $('#token').val()
  54 + });
  55 +
  56 + url = '/passport/back/passwordByMobile';
  57 + } else {
  58 + $.extend(setting, {
  59 + code: $('#email-code').val()
  60 + });
  61 +
  62 + url = '/passport/back/passwordByEmail';
  63 + }
  64 +
  65 +
  66 + if (api.pwdValidate(pwd)) {
  67 + $.ajax({
  68 + type: 'POST',
  69 + url: url,
  70 + data: setting,
  71 + success: function(data) {
  72 + if (data.code === 200) {
  73 + showErrTip('密码修改成功');
  74 +
  75 + // 1000ms后跳转页面
  76 + setTimeout(function() {
  77 + location.href = data.data;
  78 + }, 1000);
  79 + } else {
  80 + showErrTip(data.message);
  81 + }
  82 + }
  83 + });
  84 + } else {
  85 + showErrTip('密码6-20位,请重新输入');
  86 + }
  87 +});
  1 +/**
  2 + * 注册/找回密码-验证码
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/8
  5 + */
  6 +var $ = require('yoho-jquery');
  7 +
  8 +module.exports = function(useInRegister, useForBind, useForRelate) {
  9 + var $captcha = $('#captcha'),
  10 + $btnNext = $('#btn-next'),
  11 + $captchaTip = $('#captcha-tip'),
  12 + nickname = $('#nickname').val(),
  13 + sourceType = $('#sourceType').val(),
  14 + openId = $('#openId').val(),
  15 + phoneNum = $('#phone-num').val(),
  16 + areaCode = $('#area-code').val().replace('+', '');
  17 +
  18 + var api = require('./api');
  19 + var tip = require('../plugin/tip');
  20 +
  21 + var trim = $.trim;
  22 + var showErrTip = tip.show;
  23 +
  24 + var urlMid = useInRegister ? 'reg' : 'back';
  25 +
  26 + var isReg = parseInt($('#isReg').val());
  27 +
  28 + function startBind() {
  29 + $.ajax({
  30 + url: useForBind ? '/passport/bind/bindMobile' : '/passport/bind/relateMobile',
  31 + type: 'post',
  32 + data: {
  33 + areaCode: areaCode.replace('+', ''),
  34 + phoneNum: phoneNum,
  35 + openId: openId,
  36 + sourceType: sourceType,
  37 + nickname: nickname,
  38 + password: '',
  39 + code: trim($captcha.val())
  40 + },
  41 + success: function(res) {
  42 + if (res.code === 200) {
  43 + tip.show('登录成功');
  44 + setTimeout(function() {
  45 + location.href = res.data.refer;
  46 + }, 2000);
  47 + } else {
  48 + tip.show(res.message);
  49 + }
  50 + },
  51 + error: function() {
  52 + tip.show('登录失败,请重试!');
  53 + }
  54 + });
  55 + }
  56 +
  57 + function startReg() {
  58 + $.ajax({
  59 + type: 'POST',
  60 + url: '/passport/' + urlMid + '/verifycode',
  61 + data: {
  62 + phoneNum: phoneNum,
  63 + areaCode: areaCode,
  64 + code: trim($captcha.val()),
  65 + token: $('#token').val()
  66 + },
  67 + success: function(data) {
  68 + if (data.code === 200) {
  69 + location.href = data.data;
  70 + } else {
  71 +
  72 + // 验证码不正确,显示提示
  73 + showErrTip(data.message);
  74 + }
  75 +
  76 + }
  77 + });
  78 + }
  79 +
  80 + function countDown() {
  81 + var count = 59,
  82 + itime;
  83 +
  84 + itime = setInterval(function() {
  85 + if (count === 0) {
  86 + $captchaTip.text('重新发送').removeClass('disable');
  87 + clearInterval(itime);
  88 + } else {
  89 + $captchaTip.text('重新发送 (' + count-- + '秒)');
  90 + }
  91 + }, 1000);
  92 + }
  93 +
  94 + api.bindClearEvt();
  95 +
  96 + $captcha.bind('input', function() {
  97 + if (trim($captcha.val()) !== '') {
  98 + $btnNext.removeClass('disable');
  99 + } else {
  100 + $btnNext.addClass('disable');
  101 + }
  102 + });
  103 +
  104 + // 重新发送验证码
  105 + $captchaTip.on('touchstart', function() {
  106 + if ($captchaTip.hasClass('disable')) {
  107 + return;
  108 + }
  109 +
  110 + $.ajax({
  111 + type: 'POST',
  112 + url: (useForBind || useForRelate) ? '/passport/bind/sendBindMsg' : '/passport/' + urlMid + '/sendcode',
  113 + data: {
  114 + phoneNum: phoneNum,
  115 + areaCode: areaCode
  116 + },
  117 + success: function(data) {
  118 + if (data.code === 200) {
  119 + $captchaTip.text('重发验证码 (60秒)').addClass('disable');
  120 + countDown();
  121 + } else {
  122 +
  123 + // 验证码不正确,显示提示
  124 + showErrTip(data.message);
  125 + }
  126 + }
  127 + });
  128 + });
  129 +
  130 + $btnNext.on('touchstart', function() {
  131 + if ($btnNext.hasClass('disable')) {
  132 + return;
  133 + }
  134 +
  135 + if (useForBind || useForRelate) {
  136 + if (isReg) {
  137 + startBind();
  138 + } else {
  139 + location.href = '/passport/bind/password?phoneNum=' +
  140 + phoneNum + '&areaCode=' + areaCode + '&openId=' +
  141 + openId + '&sourceType=' + sourceType + '&nickname=' + nickname + '&code=' + trim($captcha.val());
  142 + }
  143 +
  144 + } else {
  145 + startReg();
  146 + }
  147 + });
  148 +
  149 + countDown();
  150 +};
1 -/**  
2 - * 登录  
3 - * @author: xuqi<qi.xu@yoho.cn>  
4 - * @date: 2015/9/30  
5 - */  
6 -var $ = require('jquery');  
7 -  
8 -var $account = $('#account'),  
9 - $pwd = $('#pwd'),  
10 - $loginBtn = $('#btn-login'),  
11 -  
12 - $mask = $('#retrive-pwd-mask'),  
13 - $ways = $('#retrive-pwd-ways'),  
14 -  
15 - accPass = false,  
16 - pwdPass = false;  
17 -  
18 -var api = require('../api');  
19 -var tip = require('../../plugin/tip');  
20 -  
21 -var trim = $.trim;  
22 -var showErrTip = tip.show;  
23 -  
24 -// 登录按钮状态切换  
25 -function switchLoginBtnStatus() {  
26 - if (accPass && pwdPass) {  
27 - $loginBtn.removeClass('disable');  
28 - } else {  
29 - $loginBtn.addClass('disable');  
30 - }  
31 -}  
32 -  
33 -// 显示找回密码面板  
34 -function showRetrivePanel() {  
35 - $mask.show();  
36 - $ways.show();  
37 -}  
38 -  
39 -// 隐藏找回密码面板  
40 -function hideRetrivePanel() {  
41 - $mask.hide();  
42 - $ways.hide();  
43 -}  
44 -  
45 -// 密码显示与隐藏  
46 -api.bindEyesEvt();  
47 -  
48 -// 清空账号输入框  
49 -api.bindClearEvt();  
50 -  
51 -$account.bind('input', function() {  
52 - if (trim($account.val()) !== '') {  
53 - accPass = true;  
54 - } else {  
55 - accPass = false;  
56 - }  
57 - switchLoginBtnStatus();  
58 -});  
59 -  
60 -$pwd.bind('input', function() {  
61 - if (trim($pwd.val()) === '') {  
62 - pwdPass = false;  
63 - } else {  
64 - pwdPass = true;  
65 - }  
66 - switchLoginBtnStatus();  
67 -});  
68 -  
69 -  
70 -// Login  
71 -$loginBtn.on('touchstart', function() {  
72 - var acc = trim($account.val()),  
73 - pwd = trim($pwd.val());  
74 -  
75 - if ($loginBtn.hasClass('disable')) {  
76 - return;  
77 - }  
78 -  
79 - $loginBtn.text('正在登录...').addClass('disable');  
80 -  
81 - // 验证账号(数字或者邮箱)和密码合理性  
82 - if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) {  
83 - $.ajax({  
84 - type: 'POST',  
85 - url: '/passport/login/auth',  
86 - data: {  
87 - account: acc,  
88 - password: pwd  
89 - },  
90 - success: function(data) {  
91 - var res;  
92 -  
93 - if (data.code === 200) {  
94 - res = data.data;  
95 -  
96 - showErrTip('登录成功');  
97 - location.href = res.href;  
98 - } else {  
99 - showErrTip(data.message);  
100 - }  
101 - },  
102 - error: function() {  
103 - showErrTip('网络断开连接啦~');  
104 - },  
105 - complete: function() {  
106 - $loginBtn.text('登录').removeClass('disable');  
107 - }  
108 - });  
109 - } else {  
110 - showErrTip('账号或密码有错误,请重新输入');  
111 - $loginBtn.text('登录').removeClass('disable');  
112 - }  
113 -});  
114 -  
115 -  
116 -$('#forget-pwd').on('touchstart', function() {  
117 - showRetrivePanel();  
118 -});  
119 -  
120 -$mask.on('touchstart', function() {  
121 - hideRetrivePanel();  
122 -});  
123 -  
124 -$('#cancel-retrive').on('touchstart', function(e) {  
125 - e.preventDefault();  
126 - hideRetrivePanel();  
127 -});  
128 -  
129 -// 对初始有默认值的情况去初始化登录按钮状态  
130 -$account.trigger('input');  
131 -$pwd.trigger('input');  
@@ -10,3 +10,4 @@ @@ -10,3 +10,4 @@
10 @import "common/index"; 10 @import "common/index";
11 @import "cart/chose-panel"; 11 @import "cart/chose-panel";
12 @import "coupon/index"; 12 @import "coupon/index";
  13 +@import "passport/index"