@RequestMapping(value = "/doRegister", produces = "application/json; charset=UTF-8") @ResponseBody public String doRegister(SignInUserInfo signInUserInfo) { JSONObject result = new JSONObject(); try { if (validateUserInfo(signInUserInfo, result)) { return result.toJSONString(); } signInUserInfo.setRoleType(Constants.USR.ROLE_TYPE_USER); signInUserInfo.setSts(Constants.USR.STR_VAL_A); iUserMaintainDao.addUser(signInUserInfo); if (StringUtil.isBlank(signInUserInfo.getUid())) { result.put("code", "500"); result.put("message", "Failed to register user" + signInUserInfo.getUserName()); return result.toJSONString(); } result.put("code", "200"); result.put("message", "register success"); } catch (Exception e) { logger.error( "Failed to register the user[{}]", signInUserInfo.getUserName(), signInUserInfo.getPassword(), e); result.put("code", "500"); result.put("message", "fatal error. please try it again."); } return result.toJSONString(); }
@RequestMapping(value = "/doLogin", produces = "application/json; charset=UTF-8") @ResponseBody public String doLogin(HttpServletRequest request, LoginUserInfo loginInfo) { JSONObject result = new JSONObject(); try { if (validateUserInfo(loginInfo, result)) { return result.toJSONString(); } LoginUserInfo dbLoginInfo = iUserMaintainDao.queryUserInfoByName(loginInfo.getUserName()); if (dbLoginInfo == null || !loginInfo.getPassword().equals(dbLoginInfo.getPassword())) { result.put("code", "400"); result.put("message", "Username or password is not correct"); return result.toJSONString(); } logger.info("The userId[{}] has been login", dbLoginInfo.getUid()); result.put("code", "200"); result.put("message", "Login success"); // request.getSession().setAttribute(Constants.SESSION_LOGIN_INFO_KEY, dbLoginInfo); } catch (Exception e) { logger.error( "Failed to login the user[{}] and password[{}]", loginInfo.getUserName(), loginInfo.getPassword(), e); result.put("code", "500"); result.put("message", "fatal error. please try it again."); } return result.toJSONString(); }