Exemplo n.º 1
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;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException If a servlet-specific error occurs
   * @throws IOException If an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // get Parameters from jsp page.
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    // authorize user from database, if exist, store it in session.
    User userObj = UserDAO.getUser(username, password);
    if (userObj != null) {
      HttpSession session = request.getSession(true);
      session.setAttribute("username", username);
      session.setAttribute("userId", userObj.getUserId());
      RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/JSP/home.jsp");
      dispatcher.forward(request, response);
    } else {
      response.sendRedirect("invalid.jsp");
      // redirect user to invalid.jsp page if the input does not match
    }
  }
Exemplo n.º 6
0
  public JSONObject register(Map map) throws Exception {
    boolean isSuccess = true;
    String errorMsg = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));
    paramUser.setStatus("1");
    if ((StringUtils.isEmpty(SessionUtils.getUserRole()))
        || ("3".equals(SessionUtils.getUserRole()))) {
      paramUser.setRole("3");
    }

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

    String password = map.get("password").toString();

    String repassword = map.get("repassword").toString();

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

    if ("1".equals(SessionUtils.getUserRole())) {
      if ((!"2".equals(paramUser.getRole())) && (!"3".equals(paramUser.getRole()))) {
        isSuccess = false;
        errorMsg = "角色设置错误.";
      }
    } else if (!"3".equals(paramUser.getRole())) {
      isSuccess = false;
      errorMsg = "角色设置错误.";
    }

    if (!password.equals(repassword)) {
      isSuccess = false;
      errorMsg = "两次输入的密码不一致.";
    }

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

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

    if (isSuccess) {
      insert(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"));
      if ("3".equals(paramUser.getRole())) userMetaMap.put("showSystem", "off");
      else {
        userMetaMap.put("showSystem", "on");
      }
      this.userMetaService.insert(userId, userMetaMap);

      String uploadFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/document", new String[] {userId}));
      FileUtils.createDirs(uploadFilePath);

      String uploadPicturePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/picture", new String[] {userId}));
      FileUtils.createDirs(uploadPicturePath);

      FileUtils.createDirs(uploadPicturePath + "/" + "thumbnail");

      String feedFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/feed", new String[] {userId}));
      FileUtils.createDirs(feedFilePath);
    }

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