Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  public JSONObject resetPwd(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    String userId = (String) map.get("userId");

    String email = (String) map.get("email");

    String verifyCode = (String) map.get("verifyCode");
    String verifyCodeInSession = (String) map.get("verifyCodeInSession");

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      message = "验证码错误.";
    }

    List userList = null;
    if ((StringUtils.isNotEmpty(userId)) && (StringUtils.isNotEmpty(email))) {
      User paramUser = new User();
      paramUser.setUserId(userId);
      paramUser.setEmail(email);
      userList = selectByCriteria(paramUser);
    }
    if ((userList == null) || (userList.size() != 1)) {
      isSuccess = false;
      message = "用户名或邮箱错误.";
    }

    if (isSuccess) {
      User user = (User) userList.get(0);

      String newPassword = RandomStringUtils.random(6, true, true);

      String title = "密码重置";
      String content = user.getUserId() + ",您好:<br/>您的新密码是:" + newPassword;
      boolean rs = ServletHelp.sendEmail(email, title, content);
      if (rs) {
        User paramUser = new User();
        paramUser.setUserId(userId);
        paramUser.setPassword(MD5Utils.getMD5String(newPassword));
        update(paramUser);
      } else {
        isSuccess = false;
        message = "邮件发送失败.";
      }
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }
Ejemplo n.º 3
0
  public void insert(User user) {
    String userId = SessionUtils.getCurrentUserId();
    if (StringUtils.isEmpty(userId)) {
      userId = user.getUserId();
    }

    user.setPassword(MD5Utils.getMD5String(user.getPassword()));

    user.setDelflag("1");

    Timestamp sysdate = new Timestamp(System.currentTimeMillis());
    user.setCreateUser(userId);
    user.setCreateTime(sysdate);
    user.setUpdateUser(userId);
    user.setUpdateTime(sysdate);
    this.userDao.insert(user);
  }