Ejemplo n.º 1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String forward = "";
    String action = request.getParameter("action");
    List<User> list;
    int id;

    if (action == null) action = "X";
    System.out.println("doGet, action = " + action);

    if (action.equalsIgnoreCase("delete")) {
      id = Integer.parseInt(request.getParameter("userId"));
      System.out.println("doGet, delete Id=" + id);
      usrldao.delroles(id);
      dao.delete(id);
      forward = LIST;
      list = dao.getAll();
      System.out.println("doGet, list size =" + list.size());
      request.setAttribute("users", list);
    } else if (action.equalsIgnoreCase("edit")) {
      forward = INSERT_OR_EDIT;
      id = Integer.parseInt(request.getParameter("userId"));
      System.out.println("doGet, edit id = " + id);
      User user = dao.findById(id);
      System.out.println("doGet, edit name = " + user.getUserName());
      request.setAttribute("user", user);
      List<Role> roles = roledao.getAll();
      System.out.println("doGet, roles size = " + roles.size());
      request.setAttribute("roles", roles);
      List<UserRole> usroles = usrldao.list(user.getUserId(), 0);
      System.out.println("doGet, usroles size = " + usroles.size());
      request.setAttribute("usroles", usroles);
    } else if (action.equalsIgnoreCase("insert")) {
      forward = INSERT_OR_EDIT;
      User user = new User();
      user.setUserId(-1);
      request.setAttribute("user", user);
      List<Role> roles = roledao.getAll();
      request.setAttribute("roles", roles);
      List<UserRole> usroles = new ArrayList<UserRole>();
      request.setAttribute("usroles", usroles);
      System.out.println("doGet, roles size = " + roles.size());
    } else if (action.equalsIgnoreCase("list")) {
      System.out.println("doGet, list");
      forward = LIST;
      list = dao.getAll();
      System.out.println("doGet, list size =" + list.size());
      request.setAttribute("users", list);
    } else if (action.equalsIgnoreCase("home")) {
      System.out.println("doGet, go HOME");
      forward = HOME;
    } else {
      System.out.println("doGet, action not OK");
      forward = INSERT_OR_EDIT;
    }

    view = request.getRequestDispatcher(forward);
    view.forward(request, response);
  }
Ejemplo n.º 2
0
  public boolean checkUser(String userName) {

    System.out.println("checkUser " + userName);

    User usr = null;

    String qry = "select u from User u where u.userName = '******'";
    System.out.println("Query = " + qry);

    List<User> users =
        em.createQuery(qry, User.class).setFirstResult(0).setMaxResults(1).getResultList();

    System.out.println("Query uitgevoerd");

    if (users != null) {
      System.out.println("Er lijkt resultaat");
      if (!users.isEmpty()) {
        System.out.println("Proberen te lezen");
        usr = users.get(0);
        System.out.println("User gevonden : " + usr.getUserName());
        return true;
      } else {
        System.out.println("Toch geen resultaat");
        return false;
      }
    } else {
      System.out.println("User niet gevonden");
      return false;
    }
  }
Ejemplo n.º 3
0
  public ReturnStatus askpassword(String email, String userName) {

    System.out.println("askpassword");

    User usr = null;

    String qry = "select u from User u where u.userName = '******'";
    System.out.println("Query = " + qry);

    // Valideer correctheid email
    try {
      javax.mail.internet.InternetAddress ia = new javax.mail.internet.InternetAddress(email);
      ia.validate();
    } catch (javax.mail.internet.AddressException e) {
      return new ReturnStatus(false, "email is niet juist formaat (server controlled).");
    }

    List<User> users =
        em.createQuery(qry, User.class).setFirstResult(0).setMaxResults(1).getResultList();

    System.out.println("Query uitgevoerd");

    if (users != null) {
      System.out.println("Er lijkt resultaat");
      if (!users.isEmpty()) {
        System.out.println("Proberen te lezen");
        usr = users.get(0);
        System.out.println("User gevonden : " + usr.getUserName());
        if (usr.getEmail().equalsIgnoreCase(email)) {
          System.out.println("email ok");
          String message = "Uw password voor username " + userName + " is : " + usr.getPassword();
          boolean result = emailBean.sendEmailSSL(email, "password aanvraag", message);
          if (result) {
            return new ReturnStatus(true, "Mail verzonden");
          } else {
            return new ReturnStatus(true, "Mail niet verzonden");
          }
        } else {
          System.out.println("email is niet hetzelfde : " + usr.getEmail() + " en " + email);
          return new ReturnStatus(
              false, "email is niet hetzelfde : " + usr.getEmail() + " en " + email);
        }
      } else {
        System.out.println("Toch geen resultaat");
        return new ReturnStatus(false, "gebruiker is niet bekend");
      }
    } else {
      System.out.println("User niet gevonden");
      return new ReturnStatus(false, "gebruiker is niet bekend");
    }
  }
Ejemplo n.º 4
0
  public boolean checkPassword(String userName, String password) {

    System.out.println("checkPassword " + password);

    User usr = null;

    String qry = "select u from User u where u.userName = '******'";
    System.out.println("Query = " + qry);

    if (em != null) {
      List<User> users =
          em.createQuery(qry, User.class).setFirstResult(0).setMaxResults(1).getResultList();

      System.out.println("Query uitgevoerd");

      if (users != null) {
        System.out.println("Er lijkt resultaat");
        if (!users.isEmpty()) {
          System.out.println("Proberen te lezen");
          usr = users.get(0);
          System.out.println("User gevonden : " + usr.getUserName());
          System.out.println("User password = "******"password ok");
            return true;
          } else {
            System.out.println("password niet ok");
            return false;
          }
        } else {
          System.out.println("Toch geen resultaat");
          return false;
        }
      } else {
        return false;
      }
    } else {
      System.out.println("EntityManager em = null");
      return false;
    }
  }