/**
* 用户登录Processor
*/
var tableName = 'demo_user';
function run() {
var username = _webParams.getParamValues().get("loginName");
var password = _webParams.getParamValues().get("password");
var checkCode = _webParams.getParamValues().get("checkCode");
if(username == null || username == "") {
return _webTools.getJsonMessage(false, 0, null, null, "登录账号不能为空");
}
if(password == "" || password == null) {
return _webTools.getJsonMessage(false, 1, null, null, "密码不能为空");
}
if(checkCode == "" || checkCode == null) {
return _webTools.getJsonMessage(false, 2, null, null, "验证码不能为空:" + checkCode);
}
var checkCaptchaCode = _webTools.validateCaptcha(_webParams, checkCode);
if(checkCaptchaCode == false) {
return _webTools.getJsonMessage(false, 3, null, null, "验证码不正确:" + checkCode);
}
var user = findUserByColVal("Username", username); //首先根据用户查找
if(user == null) { //不存在的话根据手机号码查找
user = findUserByColVal("MobilePhone", username);
if(user != null) {
if(user.get("phoneValidate") != "true") {
return _webTools.getJsonMessage(false, -2, null, null, "手机号需要验证");
}
}
}
if(user == null) { //不存在的话根据邮箱查找
user = findUserByColVal("Email", username);
if(user != null) {
if(user.get("emailValidate") != "true") {
return _webTools.getJsonMessage(false, -3, null, null, "邮箱需要验证");
}
}
}
if(user == null) {
return _webTools.getJsonMessage(false, 4, null, null, "用户不存在");
} else {
//注意解密的问题
var uname = user.get("Username");
password = _security.encryptSHA(uname + password);
var userPassword = user.get("Password");
if(userPassword != password) {
return _webTools.getJsonMessage(false, 5, null, null, "用户密码错误");
}
var status = user.get("status");
if(status != "ENABLE") {
if(status == "WAITEAMLACTIVE") {
return _webTools.getJsonMessage(false, 6, null, null, "您的帐户需要激活才能使用,请进入您的注册邮箱里面激活账号!");
} else if(status == "DISABLE") {
return _webTools.getJsonMessage(false, 7, null, null, "您的帐户已禁用,请联系管理员激活!");
} else if(status == "FROZEN") {
return _webTools.getJsonMessage(false, 8, null, null, "您的帐户已冻结,请联系管理员解冻!");
} else if(status == "LOCK") {
return _webTools.getJsonMessage(false, 8, null, null, "您的帐户处于锁定状态,请联系管理员解锁账户!");
} else {
return _webTools.getJsonMessage(false, -1, null, null, "帐户状态异常,登录失败!");
}
}
}
//放入到Session中
_webParams.getSessionItem().put('PRINCIPAL_CUSTOMER_OBJECT', user);
return _webTools.getJsonMessage(true, null, null, null, "登陆成功");;
}
functionfindUserByColVal(col, val) {
var data = _db.findData("cms", tableName, [col], [val], -1, 1);
if(data.size() == 0) {
return null;
} else {
return data.get(0);
}
}
run();
$_service.get("demoHeader")
$_service.get("demoFooter")