use of cn.cerc.jbean.client.LocalService in project summer-mis by cn-cerc.
the class AppLoginPage method checkLogin.
@Override
public boolean checkLogin(String userCode, String password) throws ServletException, IOException {
IForm form = this.getForm();
HttpServletRequest req = this.getRequest();
log.debug(String.format("校验用户帐号(%s)与密码", userCode));
// 进行设备首次登记
String deviceId = form.getClient().getId();
req.setAttribute("userCode", userCode);
req.setAttribute("password", password);
req.setAttribute("needVerify", "false");
// 如长度大于10表示用手机号码登入
if (userCode.length() > 10) {
String oldCode = userCode;
userCode = getAccountFromTel(form.getHandle(), oldCode);
log.debug(String.format("将手机号 %s 转化成帐号 %s", oldCode, userCode));
}
boolean result = false;
log.debug(String.format("进行用户帐号(%s)与密码认证", userCode));
// 进行用户名、密码认证
LocalService app;
if (form instanceof AbstractForm)
app = new LocalService((AbstractForm) form);
else
app = new LocalService(form.getHandle());
app.setService("SvrUserLogin.check");
String IP = getIPAddress();
if (app.exec("Account_", userCode, "Password_", password, "MachineID_", deviceId, "ClientIP_", IP, "Language_", form.getClient().getLanguage())) {
String sid = app.getDataOut().getHead().getString("SessionID_");
if (sid != null && !sid.equals("")) {
log.debug(String.format("认证成功,取得sid(%s)", sid));
((ClientDevice) this.getForm().getClient()).setSid(sid);
result = true;
}
} else {
// 登陆验证失败,进行判断,手机号为空,则回到登陆页,手机不为空,密码为空,则跳到发送验证码页面
String mobile = Utils.safeString(app.getDataOut().getHead().getString("Mobile_"));
if (mobile == null || "".equals(mobile)) {
log.debug(String.format("用户帐号(%s)与密码认证失败", userCode));
req.setAttribute("loginMsg", app.getMessage());
this.execute();
} else if (password == null || "".equals(password)) {
getResponse().sendRedirect("TFrmEasyReg?phone=" + mobile);
return false;
} else {
log.debug(String.format("用户帐号(%s)与密码认证失败", userCode));
req.setAttribute("loginMsg", app.getMessage());
this.execute();
}
}
return result;
}
use of cn.cerc.jbean.client.LocalService in project summer-mis by cn-cerc.
the class SvrUserLogin method sendVerifyCode.
@Webfunc
public boolean sendVerifyCode() throws DataValidateException {
try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, getUserCode(), SvrUserLogin.class.getName(), "sendVerifyCode")) {
if (!buff.isNull()) {
log.info(String.format("verifyCode %s", buff.getString("VerifyCode_")));
throw new RuntimeException(String.format("请勿在 %d 分钟内重复点击获取认证码!", TimeOut));
}
Record headIn = getDataIn().getHead();
DataValidateException.stopRun("用户帐号不允许为空", "".equals(getUserCode()));
String deviceId = headIn.getString("deviceId");
if ("".equals(deviceId)) {
throw new RuntimeException("认证码不允许为空");
}
SqlQuery cdsUser = new SqlQuery(this);
cdsUser.add("select Mobile_ from %s ", SystemTable.get(SystemTable.getUserInfo));
cdsUser.add("where Code_='%s' ", getUserCode());
cdsUser.open();
DataValidateException.stopRun("系统检测到该帐号还未登记过手机号,无法发送认证码到该手机上,请您联系管理员,让其开一个认证码给您登录系统!", cdsUser.eof());
String mobile = cdsUser.getString("Mobile_");
SqlQuery cdsVer = new SqlQuery(this);
cdsVer.add("select * from %s", SystemTable.get(SystemTable.getDeviceVerify));
cdsVer.add("where UserCode_='%s' and MachineCode_='%s'", getUserCode(), deviceId);
cdsVer.open();
DataValidateException.stopRun("系统出错,请您重新进入系统!", cdsVer.size() != 1);
String verifyCode = "888888";
if (ServerConfig.getAppLevel() != ServerConfig.appTest) {
verifyCode = intToStr(random(900000) + 100000);
}
cdsVer.edit();
cdsVer.setField("VerifyCode_", verifyCode);
cdsVer.setField("DeadLine_", TDateTime.Now().incDay(1));
cdsVer.post();
// 发送认证码到手机上
Record record = getDataOut().getHead();
LocalService svr = new LocalService(this, "SvrNotifyMachineVerify");
if (svr.exec("verifyCode", verifyCode, "mobile", mobile)) {
record.setField("Msg_", String.format("系统已将认证码发送到您尾号为 %s 的手机上,并且该认证码 %d 分钟内有效,请注意查收!", mobile.substring(mobile.length() - 4, mobile.length()), TimeOut));
buff.setExpires(TimeOut * 60);
buff.setField("VerifyCode", verifyCode);
} else {
record.setField("Msg_", String.format("验证码发送失败,失败原因:%s", svr.getMessage()));
}
record.setField("VerifyCode_", verifyCode);
return true;
}
}
use of cn.cerc.jbean.client.LocalService in project summer-mis by cn-cerc.
the class LocalServiceTest method test.
@Test
@Ignore
public void test() {
LocalService app = new LocalService(handle);
app.setService("SvrUserLogin.check");
System.out.println(app.exec());
System.out.println(app.getMessage());
}
use of cn.cerc.jbean.client.LocalService in project summer-bean by cn-cerc.
the class CustomHandle method init.
@Override
public boolean init(String corpNo, String userCode, String clientCode) {
String token = GuidFixStr(cn.cerc.jdb.other.utils.newGuid());
this.setProperty(Application.token, token);
this.setProperty(Application.bookNo, corpNo);
this.setProperty(Application.userCode, userCode);
this.setProperty(Application.clientIP, clientCode);
LocalService svr = new LocalService(this, "AppSessionRestore.byUserCode");
if (!svr.exec("userCode", userCode)) {
throw new RuntimeException(new UserNotFindException(userCode));
}
Record headOut = svr.getDataOut().getHead();
this.setProperty(Application.userId, headOut.getString("UserID_"));
this.setProperty(Application.loginTime, headOut.getDateTime("LoginTime_"));
this.setProperty(Application.roleCode, headOut.getString("RoleCode_"));
this.setProperty(Application.ProxyUsers, headOut.getString("ProxyUsers_"));
this.setProperty(Application.userName, headOut.getString("UserName_"));
this.setProperty(Application.deviceLanguage, headOut.getString("Language_"));
try (MemoryBuffer buff = new MemoryBuffer(BufferType.getSessionBase, token)) {
buff.setField("LoginTime_", headOut.getDateTime("LoginTime_"));
buff.setField("UserID_", headOut.getString("UserID_"));
buff.setField("UserCode_", userCode);
buff.setField("CorpNo_", corpNo);
buff.setField("UserName_", headOut.getString("UserName_"));
buff.setField("RoleCode_", headOut.getString("RoleCode_"));
buff.setField("ProxyUsers_", headOut.getString("ProxyUsers_"));
buff.setField("Language_", headOut.getString("Language_"));
buff.setField("exists", true);
}
return true;
}
use of cn.cerc.jbean.client.LocalService in project summer-mis by cn-cerc.
the class StartForms method passDevice.
// 是否在当前设备使用此菜单,如:检验此设备是否需要设备验证码
protected boolean passDevice(IForm form) {
// 若是iphone应用商店测试,则跳过验证
if (getIphoneAppstoreAccount().equals(form.getHandle().getUserCode()))
return true;
String deviceId = form.getClient().getId();
// TODO 验证码变量,需要改成静态变量,统一取值
String verifyCode = form.getRequest().getParameter("verifyCode");
log.debug(String.format("进行设备认证, deviceId=%s", deviceId));
String userId = (String) form.getHandle().getProperty(Application.userId);
try (MemoryBuffer buff = new MemoryBuffer(BufferType.getSessionInfo, userId, deviceId)) {
if (!buff.isNull()) {
if (buff.getBoolean("VerifyMachine")) {
log.debug("已经认证过,跳过认证");
return true;
}
}
boolean result = false;
LocalService app = new LocalService(form.getHandle());
app.setService("SvrUserLogin.verifyMachine");
app.getDataIn().getHead().setField("deviceId", deviceId);
if (verifyCode != null && !"".equals(verifyCode))
app.getDataIn().getHead().setField("verifyCode", verifyCode);
if (app.exec())
result = true;
else {
int used = app.getDataOut().getHead().getInt("Used_");
if (used == 1)
result = true;
else
form.setParam("message", app.getMessage());
}
if (result)
buff.setField("VerifyMachine", true);
return result;
}
}
Aggregations