Example #1
0
  public Map login(String userId, String password) throws Exception {
    Map res = new HashMap();
    res.put("success", Boolean.valueOf(true));

    User paramUser = new User();
    paramUser.setUserId(userId);
    paramUser.setPassword(MD5Utils.getMD5String(password));
    List userList = this.userDao.selectByCriteria(paramUser);
    if ((userList == null) || (userList.size() != 1)) {
      res.put("success", Boolean.valueOf(false));
      res.put("message", "用户名或密码错误.");
    } else {
      User currentUser = (User) userList.get(0);
      if (!"1".equals(currentUser.getStatus())) {
        res.put("success", Boolean.valueOf(false));
        res.put("message", "该用户已被禁用.");
      } else {
        currentUser = getUserWithMetaByUserId(currentUser.getUserId());

        ClientSession cs = SessionUtils.getClientSession(currentUser);
        res.put("session", cs);
      }
    }

    return res;
  }
Example #2
0
  public JSONObject update(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));

    List<User> userList = selectByCriteria(new User());
    if (userList != null) {
      for (User user : userList) {
        if ((paramUser.getEmail().equals(user.getEmail()))
            && (!paramUser.getUserId().equals(user.getUserId()))) {
          isSuccess = false;
          message = "邮箱已被使用.";
          break;
        }
      }
    }

    if (isSuccess) {
      update(paramUser);

      Map userMetaMap = new HashMap();
      userMetaMap.put("theme", (String) map.get("theme"));
      userMetaMap.put("homePage", (String) map.get("homePage"));
      userMetaMap.put("showTodo", (String) map.get("showTodo"));
      userMetaMap.put("showNote", (String) map.get("showNote"));
      userMetaMap.put("showPicture", (String) map.get("showPicture"));
      userMetaMap.put("showAccount", (String) map.get("showAccount"));
      userMetaMap.put("showFeed", (String) map.get("showFeed"));
      userMetaMap.put("showDocument", (String) map.get("showDocument"));
      userMetaMap.put("showSystem", (String) map.get("showSystem"));
      this.userMetaService.updateByUserIdAndMetaKey(paramUser.getUserId(), userMetaMap);

      ((HttpSession) map.get("session")).removeAttribute("CLIENT_SESSION");

      User currentUser = getUserWithMetaByUserId((String) map.get("userId"));

      ClientSession cs = SessionUtils.getClientSession(currentUser);
      ((HttpSession) map.get("session")).setAttribute("CLIENT_SESSION", cs);
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }