Showing
10 changed files
with
522 additions
and
3 deletions
static/js/passport/api.js
0 → 100644
1 | +/** | ||
2 | + * 登录注册公用API | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2015/10/8 | ||
5 | + */ | ||
6 | +var $ = require('yoho.zepto'); | ||
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 | +var $errTip, | ||
30 | + tipTime; | ||
31 | + | ||
32 | +/** | ||
33 | + * 初始化错误提示 | ||
34 | + */ | ||
35 | +function initErrTip() { | ||
36 | + var errTipHtml = '<div id="err-tip" class="err-tip"></div>'; | ||
37 | + | ||
38 | + //插入错误提示HTML | ||
39 | + $('.passport-page').append(errTipHtml); | ||
40 | + | ||
41 | + $errTip = $('#err-tip'); | ||
42 | + $errTip.on('touchstart', function() { | ||
43 | + $errTip.fadeOut(); | ||
44 | + | ||
45 | + //清除Timeout | ||
46 | + clearTimeout(tipTime); | ||
47 | + }); | ||
48 | +} | ||
49 | + | ||
50 | +/** | ||
51 | + * 显示错误提示 | ||
52 | + */ | ||
53 | +function showErrTip(content) { | ||
54 | + if (typeof $errTip === 'undefined') { | ||
55 | + return; | ||
56 | + } | ||
57 | + | ||
58 | + $errTip.text(content).show(); | ||
59 | + | ||
60 | + //若2秒内未点击则自动消失 | ||
61 | + tipTime = setTimeout(function() { | ||
62 | + if ($errTip.css('display') === 'block') { | ||
63 | + $errTip.fadeOut(); | ||
64 | + } | ||
65 | + }, 2000); | ||
66 | +} | ||
67 | + | ||
68 | +//密码显示隐藏 | ||
69 | +function bindEyesEvt() { | ||
70 | + var $hasEye = $('.has-eye'), | ||
71 | + $eye; | ||
72 | + | ||
73 | + $hasEye.append('<div class="eye close"></div>'); | ||
74 | + $eye = $hasEye.children('.eye'); | ||
75 | + | ||
76 | + $eye.on('touchstart', function(e) { | ||
77 | + var $this = $(this), | ||
78 | + $pwd = $this.siblings('.pwd'); | ||
79 | + | ||
80 | + e.preventDefault(); | ||
81 | + $this.toggleClass('close'); | ||
82 | + | ||
83 | + //切换密码显示和文本显示 | ||
84 | + if ($this.hasClass('close')) { | ||
85 | + $pwd.attr('type', 'password'); | ||
86 | + } else { | ||
87 | + $pwd.attr('type', 'text'); | ||
88 | + } | ||
89 | + $pwd.focus(); | ||
90 | + }); | ||
91 | +} | ||
92 | + | ||
93 | +// 清空账号显示 | ||
94 | +function bindClearEvt() { | ||
95 | + var $hasClear = $('.has-clear'), | ||
96 | + $clear; | ||
97 | + | ||
98 | + $hasClear.append('<div class="clear-input"></div>'); | ||
99 | + $clear = $hasClear.children('.clear'); | ||
100 | + | ||
101 | + $clear.on('touchstart', function(e) { | ||
102 | + var $input = $clear.siblings('.input'); | ||
103 | + | ||
104 | + $input.val('').trigger('input').focus(); | ||
105 | + e.preventDefault(); | ||
106 | + }); | ||
107 | + | ||
108 | + //反向逻辑 | ||
109 | + $hasClear.children('.input').bind('input', function() { | ||
110 | + var $this = $(this), | ||
111 | + $thisClear = $this.siblings('.clear'), | ||
112 | + val = trim($this.val()); | ||
113 | + | ||
114 | + if (val === '') { | ||
115 | + $thisClear.hide(); | ||
116 | + } else { | ||
117 | + $thisClear.show(); | ||
118 | + } | ||
119 | + }); | ||
120 | +} | ||
121 | + | ||
122 | +// 密码长度验证 | ||
123 | +function pwdValidate(pwd) { | ||
124 | + if (pwd.length >= 6 && pwd.length <= 20) { | ||
125 | + return true; | ||
126 | + } | ||
127 | + return false; | ||
128 | +} | ||
129 | + | ||
130 | +// hack for resolving direction:rtl didn't work in android uc | ||
131 | +function selectCssHack($countrySelect) { | ||
132 | + var u = navigator.userAgent; | ||
133 | + | ||
134 | + function autoSelectWidth() { | ||
135 | + var wordCount = $countrySelect.find('option:selected').text().length; | ||
136 | + | ||
137 | + switch (wordCount) { | ||
138 | + | ||
139 | + //分别有2,3,4个汉字的情况 | ||
140 | + case 2: | ||
141 | + $countrySelect.outerWidth(90); | ||
142 | + break; | ||
143 | + case 3: | ||
144 | + $countrySelect.outerWidth(110); | ||
145 | + break; | ||
146 | + default: | ||
147 | + $countrySelect.outerWidth(130); | ||
148 | + } | ||
149 | + } | ||
150 | + | ||
151 | + if (u.match(/uc/i) && u.match(/android/i)) { | ||
152 | + $countrySelect.change(function() { | ||
153 | + autoSelectWidth(); | ||
154 | + }); | ||
155 | + } else { | ||
156 | + $countrySelect.removeClass('in-android-uc'); | ||
157 | + } | ||
158 | +} | ||
159 | + | ||
160 | +//Exports APIs | ||
161 | +module.exports = { | ||
162 | + emailRegx: emailRegx, | ||
163 | + phoneRegx: phoneRegx, | ||
164 | + initErrTip: initErrTip, | ||
165 | + showErrTip: showErrTip, | ||
166 | + bindEyesEvt: bindEyesEvt, | ||
167 | + bindClearEvt: bindClearEvt, | ||
168 | + pwdValidate: pwdValidate, | ||
169 | + selectCssHack: selectCssHack | ||
170 | +}; |
static/js/passport/code.js
0 → 100644
1 | +/** | ||
2 | + * 注册/找回密码-验证码 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2015/10/8 | ||
5 | + */ | ||
6 | +var $ = require('yoho.zepto'); | ||
7 | + | ||
8 | +module.exports = function(useInRegister) { | ||
9 | + var $captcha = $('#captcha'), | ||
10 | + $btnNext = $('#btn-next'), | ||
11 | + $captchaTip = $('#captcha-tip'); | ||
12 | + | ||
13 | + var api = require('./api'); | ||
14 | + | ||
15 | + var trim = $.trim; | ||
16 | + var showErrTip = api.showErrTip; | ||
17 | + | ||
18 | + var urlMid = useInRegister ? 'register' : 'back'; | ||
19 | + | ||
20 | + function countDown() { | ||
21 | + var count = 59, | ||
22 | + itime; | ||
23 | + | ||
24 | + itime = setInterval(function() { | ||
25 | + if (count === 0) { | ||
26 | + $captchaTip.text('重发验证码').removeClass('disable'); | ||
27 | + clearInterval(itime); | ||
28 | + } else { | ||
29 | + $captchaTip.text('重发验证码 (' + count-- + '秒)'); | ||
30 | + } | ||
31 | + }, 1000); | ||
32 | + } | ||
33 | + | ||
34 | + api.initErrTip(); | ||
35 | + | ||
36 | + api.bindClearEvt(); | ||
37 | + | ||
38 | + $captcha.bind('input', function() { | ||
39 | + if (trim($captcha.val()) !== '') { | ||
40 | + $btnNext.removeClass('disable'); | ||
41 | + } else { | ||
42 | + $btnNext.addClass('disable'); | ||
43 | + } | ||
44 | + }); | ||
45 | + | ||
46 | + //重新发送验证码 | ||
47 | + $captchaTip.on('touchstart', function() { | ||
48 | + if ($captchaTip.hasClass('disable')) { | ||
49 | + return; | ||
50 | + } | ||
51 | + | ||
52 | + $.ajax({ | ||
53 | + type: 'POST', | ||
54 | + url: '/passport/' + urlMid + '/sendPhone' | ||
55 | + }).then(function (data) { | ||
56 | + if (data.code === 200) { | ||
57 | + $captchaTip.text('重发验证码 (60秒)').addClass('disable'); | ||
58 | + countDown(); | ||
59 | + } else { | ||
60 | + | ||
61 | + //验证码不正确,显示提示 | ||
62 | + showErrTip(data.message); | ||
63 | + } | ||
64 | + }); | ||
65 | + }); | ||
66 | + | ||
67 | + $btnNext.on('touchstart', function() { | ||
68 | + if ($btnNext.hasClass('disable')) { | ||
69 | + return; | ||
70 | + } | ||
71 | + | ||
72 | + $.ajax({ | ||
73 | + type: 'POST', | ||
74 | + url: '/passport/' + urlMid + '/verifycode', | ||
75 | + data: { | ||
76 | + verifyCode: trim($captcha.val()) | ||
77 | + } | ||
78 | + }).then(function (data) { | ||
79 | + if (data.code === 200) { | ||
80 | + location.href = data.data; | ||
81 | + } else { | ||
82 | + | ||
83 | + //验证码不正确,显示提示 | ||
84 | + showErrTip(data.message); | ||
85 | + } | ||
86 | + }); | ||
87 | + }); | ||
88 | + | ||
89 | + countDown(); | ||
90 | +}; |
static/js/passport/index.js
0 → 100644
1 | +/** | ||
2 | + * 注册、登录、密码找回打包入口 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2015/10/8 | ||
5 | + */ | ||
6 | +var $ = require('yoho.zepto'); | ||
7 | + | ||
8 | +//注册 | ||
9 | +require('./register/register'); | ||
10 | +require('./register/code'); | ||
11 | +require('./register/password'); | ||
12 | + | ||
13 | +//登录 | ||
14 | +require('./login/login'); | ||
15 | +require('./login/interational'); | ||
16 | + | ||
17 | +//密码找回 | ||
18 | +require('./back/mobile'); | ||
19 | +require('./back/code'); | ||
20 | +require('./back/email'); | ||
21 | +require('./back/email-success'); | ||
22 | +require('./back/new-password'); | ||
23 | + | ||
24 | +//FOR:登录注册密码找回页面样式覆盖 | ||
25 | +$('body').addClass('passport-body'); |
1 | -body { | ||
2 | - background-color: #ff0; | 1 | +@import "compass", "compass/reset"; |
2 | +$pxConvertRem: 40; | ||
3 | + | ||
4 | +@import "passport/index"; | ||
5 | + | ||
6 | + | ||
7 | +html, body { | ||
8 | + font-family: helvetica,Arial,"黑体"; | ||
9 | + width: 100%; | ||
10 | + -webkit-tap-highlight-color: rgba(0,0,0,0); | ||
11 | +} | ||
12 | + | ||
13 | +.clearfix:before, | ||
14 | +.clearfix:after { | ||
15 | + content: ""; | ||
16 | + display: table; | ||
17 | +} | ||
18 | + | ||
19 | +.clearfix:after { | ||
20 | + clear: both; | ||
21 | +} | ||
22 | + | ||
23 | +.clearfix { | ||
24 | + *zoom: 1; | ||
3 | } | 25 | } |
static/sass/passport/_common.scss
0 → 100644
1 | +body.passport-body { | ||
2 | + background-color: #444; | ||
3 | + font-family: "MicroSoft YaHei",SimSun,sans-serif; | ||
4 | + | ||
5 | + * { | ||
6 | + box-sizing: border-box; | ||
7 | + } | ||
8 | +} | ||
9 | + | ||
10 | +.passport-page { | ||
11 | + text-align: center; | ||
12 | + padding: 0 6%; | ||
13 | + | ||
14 | + .header { | ||
15 | + position: relative; | ||
16 | + height: 40px; | ||
17 | + margin: 20px 0 30px; | ||
18 | + | ||
19 | + .go-back { | ||
20 | + position: absolute; | ||
21 | + height: 30px; | ||
22 | + width: 30px; | ||
23 | + top: 5px; | ||
24 | + left: 0; | ||
25 | + } | ||
26 | + | ||
27 | + .title { | ||
28 | + font-size: 20px; | ||
29 | + line-height: 40px; | ||
30 | + color: #fff; | ||
31 | + } | ||
32 | + | ||
33 | + .img-header { | ||
34 | + width: 68px; | ||
35 | + height: 40px; | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + .input-container, .select-container { | ||
40 | + position: relative; | ||
41 | + width: 100%; | ||
42 | + height: 52px; | ||
43 | + font-size: 20px; | ||
44 | + background-color: #575757; | ||
45 | + border: 1px solid #606060; | ||
46 | + border-radius: 5px; | ||
47 | + text-align: left; | ||
48 | + color: #fff; | ||
49 | + } | ||
50 | + | ||
51 | + .select-container { | ||
52 | + .select { | ||
53 | + position: absolute; | ||
54 | + height: 50px; | ||
55 | + padding-right: 40px; | ||
56 | + right: 0; | ||
57 | + color: #fff; | ||
58 | + background-color: transparent; | ||
59 | + border: 0; | ||
60 | + @include border-radius(5px); | ||
61 | + @include appearance(none); | ||
62 | + direction: rtl; | ||
63 | + | ||
64 | + &:focus { | ||
65 | + outline: 0; | ||
66 | + border: none; | ||
67 | + } | ||
68 | + | ||
69 | + &.:-moz-focusring { | ||
70 | + color: transparent; | ||
71 | + text-shadow: 0 0 0 #fff; | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + .arrow-right { | ||
76 | + position: absolute; | ||
77 | + width: 13px; | ||
78 | + height: 20px; | ||
79 | + right: 15px; | ||
80 | + top: 16px; | ||
81 | + background-image: url('http://static.dev.yohobuy.com/passport/arrow-right.png'); | ||
82 | + background-size: 100% 100%; | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + .has-eye, .has-clear { | ||
87 | + padding-left: 30px; | ||
88 | + } | ||
89 | + | ||
90 | + .country-code { | ||
91 | + position: absolute; | ||
92 | + left: 15px; | ||
93 | + line-height: 2.5; | ||
94 | + } | ||
95 | + | ||
96 | + .phone-container { | ||
97 | + padding-left: 55px; | ||
98 | + } | ||
99 | + | ||
100 | + .input { | ||
101 | + width: 100%; | ||
102 | + line-height: 26px; | ||
103 | + padding: 12px 0; | ||
104 | + padding-left: 15px; | ||
105 | + border-radius: 5px; | ||
106 | + color: #fff; | ||
107 | + background-color: transparent; | ||
108 | + border: none; | ||
109 | + } | ||
110 | + | ||
111 | + .btn { | ||
112 | + display: block; | ||
113 | + width: 100%; | ||
114 | + font-size: 20px; | ||
115 | + line-height: 2.5; | ||
116 | + background-color: #36a74c; | ||
117 | + @include border-radius(5px); | ||
118 | + color: #fff; | ||
119 | + | ||
120 | + &.disable { | ||
121 | + background-color: #a2a2a2; | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + .country-select.in-android-uc { | ||
126 | + width: 90px; | ||
127 | + } | ||
128 | + | ||
129 | + .clear-input { | ||
130 | + position: absolute; | ||
131 | + display: none; | ||
132 | + top: 18px; | ||
133 | + right: 10px; | ||
134 | + width: 16px; | ||
135 | + height: 16px; | ||
136 | + background-image: url('http://static.dev.yohobuy.com/passport/clear-input.png'); | ||
137 | + background-size: 100% 100%; | ||
138 | + } | ||
139 | + | ||
140 | + .eye { | ||
141 | + position: absolute; | ||
142 | + top: 20px; | ||
143 | + right: 10px; | ||
144 | + width: 19px; | ||
145 | + height: 12px; | ||
146 | + background-image: url('http://static.dev.yohobuy.com/passport/eye.png'); | ||
147 | + background-size: 100% 100%; | ||
148 | + | ||
149 | + &.close { | ||
150 | + background-image: url('http://static.dev.yohobuy.com/passport/eye-close.png'); | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + .row { | ||
155 | + margin-bottom: 10px; | ||
156 | + } | ||
157 | + | ||
158 | + .err-tip { | ||
159 | + position: absolute; | ||
160 | + display: none; | ||
161 | + text-align: center; | ||
162 | + width: 70%; | ||
163 | + padding: 34px 0; | ||
164 | + top: 50%; | ||
165 | + left: 50%; | ||
166 | + margin-left: -35%; | ||
167 | + margin-top: -45px; | ||
168 | + background-color: #000; | ||
169 | + opacity: 0.7; | ||
170 | + color: #fff; | ||
171 | + font-size: 18px; | ||
172 | + border: none; | ||
173 | + @include border-radius(10px); | ||
174 | + } | ||
175 | +} |
static/sass/passport/_index.scss
0 → 100644
1 | +@import "common", "register", "login", "back"; |
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> |
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}} {{#selected}}selected{{/selected}}>{{name}}</option> | ||
6 | + {{/ countrys}} | ||
7 | + </select> | ||
8 | + <div class="arrow-right"></div> | ||
9 | +</div> |
1 | +<div class="header"> | ||
2 | + {{#if showGoBack}} | ||
3 | + <a class="go-back" href={{../backUrl}}> | ||
4 | + <img src="http://static.dev.yohobuy.com/img/passport/go-back.png"> | ||
5 | + </a> | ||
6 | + {{/if}} | ||
7 | + {{#if useHeaderImg}} | ||
8 | + <img src="img-header" src="http://static.dev.yohobuy.com/img/passport/yoho-family.png"> | ||
9 | + {{/if}} | ||
10 | + {{#if useHeaderText}} | ||
11 | + <p class="title">{{../headerText}}</p> | ||
12 | + {{/if}} | ||
13 | +</div> |
-
Please register or login to post a comment