Browse Source

注册添加图形验证码

luyanan 7 years ago
parent
commit
45556338fe
2 changed files with 43 additions and 8 deletions
  1. 8 0
      app/html/reg.html
  2. 35 8
      app/js/register.js

+ 8 - 0
app/html/reg.html

@ -23,6 +23,14 @@
23 23
		        <div class="mui-input-row frm-input">
24 24
		            <input type="tel" class="mui-input-clear frmtype" placeholder="请输入手机号码" id="username">
25 25
		        </div>
26
		        <div class="mui-row mui-input-row frm-input">
27
		        	<div class="mui-col-xs-8">
28
		        		<input type="tel" class="frmtype" placeholder="请输入图形验证码" id="imgCode">
29
		        	</div>
30
					<div class="mui-col-xs-4">
31
						<img src="http://www.ekexiu.com/ajax/PictureVC" alt="" id="changImage" width="100%" height="48"/>
32
					</div>
33
				</div>
26 34
		        <div class="mui-row mui-input-row frm-input">
27 35
		        	<div class="mui-col-xs-8">
28 36
		        		<input type="tel" class="frmtype" placeholder="请输入验证码" id="set-code">

+ 35 - 8
app/js/register.js

@ -9,14 +9,16 @@ mui.ready(function() {
9 9
	var setpassword = document.getElementById("setpassword");
10 10
	var reg = document.getElementById("reg");
11 11
	var protocollink = document.getElementById("protocollink");
12
	var imgCode = document.getElementById("imgCode");
13
	var changImage = document.getElementById("changImage")
12 14
	var phoneCode = false;
13 15
	var state = 0;
14 16
	
15 17
	mui.plusReady(function() {
16 18

17 19
		/*校验提交按钮显示状态*/
18
		mui('.frmboxNew').on('keyup', "#name,#username,#set-code,#setpassword", function() {
19
			if(name.value == "" || phoneName.value == "" || setCode.value == "" || setpassword.value == "") {
20
		mui('.frmboxNew').on('keyup', "#name,#username,#imgCode,#set-code,#setpassword", function() {
21
			if(name.value == "" || phoneName.value == "" || imgCode.value == "" || setCode.value == "" || setpassword.value == "") {
20 22
				reg.classList.remove("frmactiveok");
21 23
				reg.disabled = "disabled";
22 24
			} else {
@ -51,6 +53,15 @@ mui.ready(function() {
51 53
				plus.nativeUI.toast("请输入正确的手机号码", toastStyle);
52 54
				return;
53 55
			}
56
			if(imgCode.value.length==0) {
57
				plus.nativeUI.toast("请输入图形验证码", toastStyle);
58
				return;
59
			}else if(imgCode.value.length==4){
60
				
61
			}else{
62
				plus.nativeUI.toast("图形验证码4位", toastStyle);
63
				return;
64
			}
54 65
			if(!oNum.test(setCode.value)) {
55 66
				plus.nativeUI.toast("验证码为4位数字", toastStyle);
56 67
				return;
@ -59,7 +70,8 @@ mui.ready(function() {
59 70
				plus.nativeUI.toast("密码由6-24个字符组成,区分大小写", toastStyle);
60 71
				return;
61 72
			}
62
			isReg(1);
73
//			isReg(1);
74
			isReg();
63 75
		})
64 76
		
65 77
		/*用户协议*/
@ -73,6 +85,9 @@ mui.ready(function() {
73 85
			});
74 86
		});
75 87
		
88
		changImage.addEventListener("tap",function(){
89
			this.setAttribute("src","http://www.ekexiu.com/ajax/PictureVC?"+new Date().getTime());
90
		})
76 91
		/*校验手机号*/
77 92
		function phoneVal() {
78 93
			var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
@ -96,7 +111,7 @@ mui.ready(function() {
96 111
						plus.nativeUI.toast("该账号已存在,请直接登录", toastStyle);
97 112
						return;
98 113
					} else {
99
						if(oArg==1){	
114
						if(oArg==1){
100 115
							codeVal();
101 116
						}else{	
102 117
							phoneCode = true;
@ -115,10 +130,12 @@ mui.ready(function() {
115 130

116 131
		/*手机发送验证码*/ 
117 132
		function sendAuthentication() {
118
			console.log("send code")
119
			mui.ajax(baseUrl + '/ajax/regmobilephone_onlyphone', {
133
			console.log(phoneName.value)
134
			console.log(imgCode.value)
135
			mui.ajax(baseUrl + '/ajax/regmobilephone', {
120 136
				data: {
121
					mobilePhone: phoneName.value
137
					mobilePhone: phoneName.value,
138
					vcode: imgCode.value
122 139
				},
123 140
				dataType: 'json', //数据格式类型
124 141
				type: 'GET', //http请求类型
@ -129,6 +146,11 @@ mui.ready(function() {
129 146
					if(data.success) {
130 147
						state = data.data;
131 148
						doClick();
149
					}else{
150
						if(data.code==20001) {
151
							plus.nativeUI.toast("请输入正确的图形验证码", toastStyle);
152
							changImage.setAttribute("src","http://www.ekexiu.com/ajax/PictureVC?"+new Date().getTime());
153
						}
132 154
					}
133 155
				},
134 156
				error: function() {
@ -158,7 +180,6 @@ mui.ready(function() {
158 180
				}
159 181
			}, 1000);
160 182
		}
161

162 183
		/*校验验证码*/
163 184
		function codeVal() {
164 185
			mui.ajax(baseUrl + '/ajax/validCode', {
@ -227,6 +248,12 @@ mui.ready(function() {
227 248
								aniShow: "slide-in-right"
228 249
							}
229 250
						});
251
					}else{
252
						if(data.code==-1){
253
							plus.nativeUI.toast("验证码已过期,请重新获取", toastStyle);
254
						}else if(data.code==-2 || data.code==-3 ||data.code==0){
255
							plus.nativeUI.toast("验证码错误,请检查后重试", toastStyle);
256
						}
230 257
					}
231 258
				},
232 259
				error: function() {