コード例 #1
0
  public void logout() {
    menu1 = false;
    menu2 = false;
    menu3 = false;
    adminBean.setLogin("");
    adminBean.setHaslo("");
    prowadzacyBean.setLogin("");
    prowadzacyBean.setPassword("");
    studentBean.setIndex(0);
    studentBean.setHaslo("");

    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navHandler = context.getApplication().getNavigationHandler();
    navHandler.handleNavigation(context, null, "zaloguj");
  }
コード例 #2
0
  public String zaloguj() {
    String whereTo = "";
    menu1 = false;
    menu2 = false;
    menu3 = false;
    if (typ.equalsIgnoreCase("0")) {
      adminBean.setLogin(pole1);
      adminBean.setHaslo(pole2);
      adminBean.zaloguj(pole1, pole2);
      // logika czy zalogowanie sie powiodlo
      if (adminBean.getId() > 0) {
        menu1 = true;
        whereTo = "adminHome";
      } else {
        menu1 = false;
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
      }
    }
    if (typ.equalsIgnoreCase("1")) {

      prowadzacyBean.setLogin(pole1);
      prowadzacyBean.setPassword(pole2);
      prowadzacyBean.zaloguj(pole1, pole2);
      // logika czy zalogowanie sie powiodlo
      if (prowadzacyBean.getId() > 0) {
        menu2 = true;
        whereTo = "prowadzacypf";
        System.out.println("zalogowano");
      } else {
        menu2 = false;
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
      }
    }
    if (typ.equalsIgnoreCase("2")) {
      int nrIdx = 0;
      try {
        nrIdx = Integer.parseInt(pole1);
      } catch (NumberFormatException e) {
        nrIdx = -1;
      }
      if (nrIdx > 0) {
        studentBean.setIndex(nrIdx);
        studentBean.setHaslo(pole2);
        studentBean.zaloguj(nrIdx, pole2);
        if (studentBean.getId() > 0) {
          menu3 = true;
          whereTo = "studentpf";

        } else {
          menu3 = false;
          FacesContext context = FacesContext.getCurrentInstance();
          context.addMessage(
              null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
        }
      } else {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Zaloguj siê u¿ywaj¹c numeru indeksu!"));
      }
    }

    // redirection bo PF
    if (!whereTo.equalsIgnoreCase("")) {
      System.out.println("Proba nawigacji");
      FacesContext context = FacesContext.getCurrentInstance();
      NavigationHandler navHandler = context.getApplication().getNavigationHandler();
      navHandler.handleNavigation(context, null, whereTo);
    }
    return "Bledne";
  }