コード例 #1
0
ファイル: LoginServlet.java プロジェクト: GutiX/surveytool
  protected void ProcessRequest(HttpServletRequest request, HttpServletResponse response) {
    SurveyToolProperties bodyPages = new SurveyToolProperties(getServletContext().getRealPath("/"));

    // System.out.println("Path: " + bodyPages.getBudyPagePath());
    /** cargar correspondiente body page */
    Language lang = new Language(getServletContext().getRealPath("/"));
    lang.loadLanguage(Language.getLanguageRequest(request));

    Login loginHandler = new Login();
    Credentials credentials = new Credentials();
    credentials.setUsername(request.getParameter(Parameter.s_USERNAME));
    credentials.setPassword(request.getParameter(Parameter.s_PASSWORD));
    // System.out.println("Parameters: " + credentials.getUsername() + " - " +
    // credentials.getPassword());
    LoginResponse loginResp = loginHandler.login(credentials);

    System.out.println(loginResp.toString());

    if (loginResp.isValid() && loginResp.getRol().equals(DBConstants.s_VALUE_ROLNAME_ADMIN)) {
      request.setAttribute(
          Attribute.s_BODY_PAGE, bodyPages.getBudyPagePath(Address.s_BODY_USER_PANEL_HOME));
      HttpSession session = request.getSession();
      session.setAttribute(Attribute.s_USER_SESSION_INFO, loginResp);
      request.setAttribute(Attribute.s_PAGE_TITLE, "User Panel");
    } else {
      request.setAttribute(Attribute.s_BODY_PAGE, bodyPages.getBudyPagePath(Address.s_BODY_LOGIN));
      request.setAttribute(Attribute.s_LOGIN_RESPONSE, loginResp);
      request.setAttribute(Attribute.s_PAGE_TITLE, "Home");
    }

    CommonCode.redirect(request, response, Address.s_MASTER_PAGE);
  }
コード例 #2
0
ファイル: RegisterServlet.java プロジェクト: GutiX/surveytool
  protected void ProcessRequest(HttpServletRequest request, HttpServletResponse response) {
    SurveyToolProperties bodyPages = new SurveyToolProperties(getServletContext().getRealPath("/"));

    // System.out.println("Path: " + bodyPages.getBudyPagePath());
    /** cargar correspondiente body page */
    String langReq = Language.getLanguageRequest(request);

    Register registerHandler = new Register();
    RegisterResponse registerReponse = new RegisterResponse();
    registerReponse.setUserName(request.getParameter(Parameter.s_USERNAME));
    registerReponse.setPassword(request.getParameter(Parameter.s_PASSWORD));
    registerReponse.setRepassword(request.getParameter(Parameter.s_REPASSWORD));
    registerReponse.setEmail(request.getParameter(Parameter.s_EMAIL));
    registerReponse.setIsoLanguage(langReq);

    System.out.println(
        "Parameters: " + registerReponse.getUserName() + " - " + registerReponse.getPassword());
    RegisterResponse regResp = registerHandler.register(registerReponse);
    System.out.println(registerReponse.toString());

    if (regResp.isValid()) {
      // cargar usuario y entrar en el sistema
      Login loginHandler = new Login();
      Credentials credentials = new Credentials();
      credentials.setUsername(request.getParameter(Parameter.s_USERNAME));
      credentials.setPassword(request.getParameter(Parameter.s_PASSWORD));
      System.out.println(
          "Parameters: " + credentials.getUsername() + " - " + credentials.getPassword());
      LoginResponse loginResp = loginHandler.login(credentials);

      request.setAttribute(
          Attribute.s_BODY_PAGE, bodyPages.getBudyPagePath(Address.s_BODY_USER_PANEL_HOME));
      HttpSession session = request.getSession();
      session.setAttribute(Attribute.s_USER_SESSION_INFO, loginResp);
      request.setAttribute(Attribute.s_PAGE_TITLE, "User Panel");
    } else {
      request.setAttribute(Attribute.s_BODY_PAGE, bodyPages.getBudyPagePath(Address.s_BODY_LOGIN));
      request.setAttribute(Attribute.s_REGISTER_RESPONSE, regResp);
      request.setAttribute(Attribute.s_PAGE_TITLE, "Home");
    }

    CommonCode.redirect(request, response, Address.s_MASTER_PAGE);
  }