/** * @Title: userRegist @Description: 用户注册 * * @param @param user * @param @return 设定文件 * @return UserInfo 返回类型 * @throws */ public UserInfo userRegisterOrResetPassword(String json) { UserInfo info = new UserInfo(); MResult mResult = new MResult(false); User user = parseJsonToUser(json); // 用户已存在 -- 重置密码 if (userDao.selectByUsername(user.getUsername()) != null) { mResult.setInfo("修改密码"); int update = userDao.resetPassword(user); if (update > 0) { mResult.setSuccess(true); } info.setmResult(mResult); info.setUser(userDao.selectByUsername(user.getUsername())); return info; } if (user != null) { if (insert(user) > 0) { user = userDao.selectByUsername(user.getUsername()); mResult.setSuccess(true); mResult.setInfo("注册成功"); mResult.setReverse1(user.getId() + ""); } else { mResult.setSuccess(false); mResult.setInfo("注册失败,请重试"); } } info.setmResult(mResult); info.setUser(user); return info; }
@Override public UserInfo getUserByUsername(String json) { UserInfo info = new UserInfo(); MResult mResult = new MResult(false); // true 找到用户 false 未找到用户 User user = null; if (!StringUtils.isNullOrEmpty(json)) { user = userDao.selectByUsername(String.valueOf(JSON.parseObject(json, String.class))); if (user != null) { mResult.setSuccess(true); } } info.setmResult(mResult); info.setUser(user); return info; }
/** * @Title: updateUserInfo @Description: 完善用户资料 * * @param @param user * @param @return 设定文件 * @return UserInfo 返回类型 * @throws */ public UserInfo updateUserInfo(String json) { UserInfo info = new UserInfo(); MResult mResult = new MResult(); User user = parseJsonToUser(json); System.out.println(user); if (user != null) { if (update(user) > 0) { mResult.setSuccess(true); User updateUser = userDao.selectByUsername(user.getUsername()); info.setUser(user); } else { mResult.setSuccess(false); } } else { mResult.setSuccess(false); } info.setmResult(mResult); return info; }
/** 处理用户登录请求 */ public UserInfo doLogin(String json) { System.out.println(json); MResult result = new MResult(); UserInfo userInfo = new UserInfo(); User user = parseJsonToUser(json); User userLogin = userDao.selectByUsername(user.getUsername()); if (userLogin != null) { if (userLogin.getPassword().equals(user.getPassword())) { result.setSuccess(true); } else { result.setInfo("密码错误"); result.setSuccess(false); } } else { result.setInfo("用户不存在"); result.setSuccess(false); } userInfo.setmResult(result); userInfo.setUser(userLogin); return userInfo; }