|
楼主 |
发表于 2016-11-16 11:04:23
|
显示全部楼层
/ 注册-点击提交密码
Model.prototype.button1Click = function(event) {
var self = this;
var context = this.getContext();
var mima1 = this.comp('password1').val();
var mima2 = this.comp("password2").val();
// 正则表达式
var mimaReg = /^(?![^a-zA-Z]+$)(?!\D+$)[0-9a-zA-Z]{6,12}$/;
// 正则校验
var m1Reg = mimaReg.test(mima1);
var m2Reg = mimaReg.test(mima2);
if ($.trim(mima1) != "" && $.trim(mima2) != "" && $.trim(mima1) != null && $.trim(mima2) != null) {
if (mima1 == mima2) {
if (m1Reg && m2Reg) {// 密码格式正确
justep.Baas.sendRequest({
"url" : "/***/****",
"action" : "zhuceSavemima",
"async" : false,
"params" : {
"shoujihao" : this.shoujihao,
"mima1" : mima1,
"mima2" : mima2
},
"success" : function(data) {
var ret = data.ret;
if (ret == "success") {
$.each(data.rows, function(idx, item) {
var user_id = item.user_id.value;
// var uuid = item.uuid.value;
var shoujihao = item.shoujihao.value;
var user_mima = item.user_mima.value;
var user_nicheng = item.user_nicheng.value;
var user_banjiid = item.user_banjiid.value;
var user_touxiang = item.user_touxiang.value;
var user_youxiang = item.user_youxiang.value;
// var user_dengluming = item.user_dengluming.value;
// var user_realname = item.user_realname.value;
localStorage.setItem('user_id', user_id);
// localStorage.setItem('uuid', uuid);
localStorage.setItem('shoujihao', shoujihao);
localStorage.setItem('user_mima', user_mima);
localStorage.setItem('user_nicheng', user_nicheng);
localStorage.setItem('user_banjiid', user_banjiid);
localStorage.setItem('user_touxiang', user_touxiang);
localStorage.setItem('user_youxiang', user_youxiang);
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>注册成功</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
var guanbi = self.comp("zhuceshoujiReceiver");
guanbi.windowEnsure({
jieguo : "zhucesuccess"
});
});
} else if (ret == "isExisted") {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>手机号码已存在</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
} else {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>密码输入不一致</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
}
},
"error" : function(data) {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>操作失败</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
}
});
// } else if (m1Reg) {
// hintC.hintcustom("<div class='text'
// style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>重复密码错误</div>",
// {
// "delay" : 3000,
// "position" : "bottom"// ,
// });
} else {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>密码格式错误</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
}
} else {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>密码输入不一致</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
}
} else {
hintC.hintcustom("<div class='text' style='text-align:center;background-color:#000000;padding:12px;border-radius:6px;font-size:16px;color:#fff;'>请输入密码</div>", {
"delay" : 3000,
"position" : "bottom"// ,
});
}
};
页面源码 :
<div class="x-contents-content" xid="content1">
<div class="form-vertical" component="$UI/system/components/bootstrap/form/form" xid="form1" style="border-top:1px solid #ddd;border-bottom:1px solid #ddd;background:#fff;">
<div xid="div12" class="form-group" style="margin-right:auto;margin-left:auto;width:100%;">
<label xid="label4" class="sr-only"><![CDATA[密码]]></label>
<div xid="div14" class="input-group username" style="width:100%;position:relative;">
<input component="$UI/system/components/justep/input/password" class="form-control" xid="password1" maxLength="12" placeHolder="输入您的密码(字母+数字)" bind-focus="password1Focus" bind-keyup="password1Keyup"></input>
<a component="$UI/system/components/justep/button/button" class="btn btn-default mima1Btn" label="重新输入" xid="button2" bind-visible="qingkongyButton">
<i xid="i2" class="iconfont iconfont-edu08" style="color:#999999;font-size:20px;"></i></a></div>
</div>
<div xid="div13" class="form-group" style="margin-right:auto;margin-left:auto;width:100%;">
<label xid="label5" class="sr-only"><![CDATA[密码]]></label>
<div xid="div16" class="input-group" style="width:100%;position:relative;">
<input component="$UI/system/components/justep/input/password" class="form-control" xid="password2" maxLength="12" placeHolder="再次输入密码(字母+数字)" bind-keyup="password2Keyup"></input>
<a component="$UI/system/components/justep/button/button" class="btn btn-default mima2Btn" label="重新输入" xid="button3" bind-visible="qingkongButton">
<i xid="i3" class="iconfont iconfont-edu08" style="color:#999999;font-size:20px;"></i>
</a></div>
</div>
</div>
<div component="$UI/system/components/justep/row/row" class="x-row" xid="row4">
<div class="x-col" xid="col10" style="text-align:center;">
<a component="$UI/system/components/justep/button/button" class="btn btn-success btn-block" label="开启东道学院" xid="button1" bind-touchstart="button1Touchstart" bind-touchend="button1Touchend">
<i xid="i1"></i>
<span xid="span1">开启东道学院</span>
</a>
</div>
</div>
<div component="$UI/system/components/justep/row/row" class="x-row" xid="row1" style="text-align:center;">
<div class="x-col xieyi" xid="col2">注册即代表您同意<a xid="a1" bind-click="a1Click">用户服务协议</a></div>
</div>
</div>
后台代码:
/**
* 注册 1,获取手机号码,用户输入的2次密码 2,做对比
*/
public static JSONObject zhuceSavemima(JSONObject params, ActionContext context) throws SQLException, NamingException, java.sql.SQLException {
JSONObject ret = new JSONObject();
PreparedStatement pstmt = null;
// 获取参数
Table table = null;
String shoujihao = params.getString("shoujihao");
String mima1 = params.getString("mima1");
String mima2 = params.getString("mima2");
String touxiang = "img_touxiang/picture.jpg";
// long sendTime = Long.parseLong(params.getString("sendTime"));
// long reTime =new Date().getTime();//返回时间
Connection conn = null;
conn = context.getConnection(DATASOURCE_DONGDAO);
String uuid = genOrderNum();
try {
conn.setAutoCommit(false);
// 查找用户是否存在
String querysql = "select shoujihao from t_user where shoujihao='" + shoujihao + "' and isdelete=0 ";
// System.out.println(querysql);
Object Shoujihao = DataUtils.getValueBySQL(conn, querysql, null);
String querysql2 = "select uuid from t_user where uuid='" + uuid + "' and isdelete=0";
Object UUId = DataUtils.getValueBySQL(conn,querysql2, null);
while (UUId !=null) {
uuid=genOrderNum();
}
if (Shoujihao != null) {
ret.put("ret", "isExisted"); // 用户存在
} else {
if (mima1.equals(mima2)) {
String sql = "insert into t_user(uuid,shoujihao,user_nicheng,user_mima,user_banjiid,xingbie,user_touxiang,createTime,user_fenshishu,guanzhushu,user_jifen,user_dongbi,user_yonghuleixing,isdelete,isRegister,user_gerenjianli) values('"
+uuid+"','"+ shoujihao + "','" + shoujihao + "','" + mima1 + "'," + "0,2,'" + touxiang + "',NOW(),0,0,50,0,0,0,1,'这个人很懒什么都没写')";
// System.out.println(sql);
pstmt = conn.prepareStatement(sql);
pstmt.execute();
String sql2 = "select uuid,user_id,user_dengluming,user_realname,user_banjiid,shoujihao,user_mima,user_touxiang,user_youxiang,user_nicheng,isRegister from t_user where shoujihao='"
+ shoujihao + "' and user_mima='" + mima1 + "' and isdelete=0 ";
table = DataUtils.queryData(conn, sql2, null, null, null, null);
ret = Transform.tableToJson(table);
ret.put("ret", "success");
} else {
ret.put("ret", "codewrong"); // 密码不一致
}
// 再放入各种数据
}
} catch (java.sql.SQLException e) {
conn.rollback();
e.printStackTrace();
return null;
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
} finally {
conn.setAutoCommit(true);
conn.close();
}
return ret;
}
|
|