Exemple #1
0
  // 处理提交更新信息操作
  private void processChangeInfoAction(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String password = null;
    String confirm_password = null;

    // 修改密码校对(部分已经使用javascript完成)
    password = request.getParameter(User.PASSWORD).trim();
    confirm_password = request.getParameter(UserServlet.CONFIRM_PASSWORD).trim();
    if (password != null && confirm_password != null && password.equals(confirm_password)) {

    } else {
      status_info = "密码不相同,请重新输入";
      request.setAttribute(STATUS_INFO, status_info);
      goJSP("/UpdateUser", request, response);
    }

    // 根据用户类型的不同采取不同的操作
    String privilege = EnispSession.getPrivilege(request);

    if (privilege.equals(User.PRIVILEGE_NORMAL)) {
      User user = new User();
      user.setProperty(User.ID, EnispSession.getUserId(request));
      user = (User) mDBOperator.selectObjectFromDB(user);
      user.setProperty(User.PASSWORD, password);
      mDBOperator.updateObjectToDB(user);

      // 清空session, 退出
      EnispSession.invalidate(request);

      status_info = "信息修改成功,请重新登录";
      request.setAttribute(STATUS_INFO, status_info);
      request.setAttribute(STATUS_INFO_FLAG, "positive");
      goJSP("/index.jsp", request, response);
    } else if (privilege.equals(User.PRIVLIEGE_ENTERPRISE)) {
      UserInfo userInfo = new UserInfo();
      Enterprise enterprise = new Enterprise();
      userInfo.setProperty(UserInfo.ID, EnispSession.getUserId(request));
      userInfo = (UserInfo) mDBOperator.selectObjectFromDB(userInfo);
      userInfo.setProperty(UserInfo.PASSWORD, password);
      userInfo.setProperty(UserInfo.ID, EnispSession.getUserId(request));
      enterprise.setProperty(Enterprise.ID, userInfo.getProperty(UserInfo.ENTERPRISEID));
      enterprise = (Enterprise) mDBOperator.selectObjectFromDB(enterprise);
      enterprise.setProperty(
          Enterprise.ENTERPRISENAME, request.getParameter(Enterprise.ENTERPRISENAME));
      enterprise.setProperty(Enterprise.ADDRESS, request.getParameter(Enterprise.ADDRESS));
      enterprise.setProperty(
          Enterprise.TELEPHONENUMBER, request.getParameter(Enterprise.TELEPHONENUMBER));
      enterprise.setProperty(Enterprise.FAXNUMABER, request.getParameter(Enterprise.FAXNUMABER));
      enterprise.setProperty(
          Enterprise.OFFICALWEBSITE, request.getParameter(Enterprise.OFFICALWEBSITE));
      enterprise.setProperty(Enterprise.EMAIL, request.getParameter(Enterprise.EMAIL));

      String year = request.getParameter(UserServlet.YEAR);
      String month = request.getParameter(UserServlet.MONTH);
      String day = request.getParameter(UserServlet.DAY);

      enterprise.setProperty(Enterprise.ESTABLISHMENTTIME, year + "-" + month + "-" + day);

      mDBOperator.updateObjectToDB(userInfo);
      mDBOperator.updateObjectToDB(enterprise);

      EnispSession.invalidate(request);

      status_info = "密码修改成功,请重新登录";
      request.setAttribute(STATUS_INFO, status_info);
      request.setAttribute(STATUS_INFO_FLAG, "positive");
      goJSP("/index.jsp", request, response);
    } else {
      goJSP("/error.jsp", request, response);
    }
  }
Exemple #2
0
  // 处理普通用户注册操作
  private void processRegisterNormalUserAction(
      HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String username = null;
    String password = null;
    String confirm_password = null;
    boolean isSuccessed = false;

    // 普通用户的注册操作相对简单
    // Step 1: 从请求中获取用户对象
    User user = (User) Factory.getObjectFromRequest(request, new User());
    username = user.getProperty(User.USERNAME);
    password = user.getProperty(User.PASSWORD);
    confirm_password = request.getParameter(UserServlet.CONFIRM_PASSWORD);

    // Step 2: 检查用户输入
    if (username == null
        || password == null
        || confirm_password == null
        || username.length() == 0
        || password.length() == 0
        || confirm_password.length() == 0) {
      status_info = "请输入完整信息";
    }
    // Step 3: 进行密码校验
    else if (!password.equals(confirm_password)) {
      status_info = "密码校验错误, 请重新输入";
    }
    // Step 4: 检查用户名是否重复
    else {
      User temp_user = new User(username, "", "", "");
      temp_user = (User) mDBOperator.selectObjectFromDB(temp_user);
      if (temp_user != null) {
        status_info = "该用户已经存在,请更换用户名";
      } else {
        // Step 5: 信息填写成功,在数据库中插入数据
        // 设置普通用户的权限
        user.setProperty(User.PRIVILEGE, User.PRIVILEGE_NORMAL);
        user.setProperty(User.STATUS, User.STATUS_INACTIVE);

        isSuccessed = mDBOperator.insertObjectToDB(user);

        if (!isSuccessed) {
          status_info = "数据库插入失败";
        }
      }
    }

    // Step 6: 注册成功,跳转到登录界面
    if (isSuccessed) {
      status_info = "注册成功,请登录";
      request.setAttribute(STATUS_INFO, status_info);
      request.setAttribute(STATUS_INFO_FLAG, "positive");
      goJSP("/index.jsp", request, response);
    }
    // 注册失败
    else {
      Factory.pushObjectIntoRequestAttribute(request, user);
      request.setAttribute(STATUS_INFO, status_info);
      request.setAttribute(USER_TYPE, USER_NOARMAL);
      goJSP("/register.jsp", request, response);
    }
  }