예제 #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);
  }
예제 #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;
    }
  }
예제 #3
0
  public ReturnStatus register(String email, String userName, String password) {

    System.out.println("register");

    if (checkUser(userName)) {
      return new ReturnStatus(false, "Gebruiker bestaat al. Kies een andere naam.");
    }

    // 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).");
    }

    User user = new User();
    user.setEmail(email);
    user.setUserName(userName);
    user.setPassword(password);
    System.out.println("create : " + userName);

    em.persist(user);

    String subject = "Accountaanvraag";
    String message =
        "Uw aanvraag voor gebruikersnaam "
            + userName
            + " en wachtwoord "
            + password
            + " is verwerkt.";

    boolean result = emailBean.sendEmailSSL(email, subject, message);

    // boolean result = emailBean.sendEmailTLS(email, subject,  message);
    // boolean result = emailBean.sendEmailSSL_HTML(email, subject,  message);

    if (result) {
      return new ReturnStatus(true, "Mail verzonden");
    } else {
      return new ReturnStatus(true, "Mail niet verzonden");
    }
  }
예제 #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;
    }
  }
예제 #5
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    User user = new User();
    String userName = request.getParameter("userName");
    user.setUserName(userName);
    String password = request.getParameter("password");
    user.setPassword(password);
    String email = request.getParameter("email");
    user.setEmail(email);
    String userId = request.getParameter("userId");

    String[] roleIds = request.getParameterValues("roleId");
    for (int i = 0; i < roleIds.length; i++) {
      System.out.println("selecter role : " + roleIds[i]);
    }

    System.out.println("doPost, name=" + userName + " password ="******" email=" + email);
    if (userId == null || userId.isEmpty() || userId.equals("-1")) {
      System.out.println("doPost, call dao.save()");
      dao.save(user);
      List<User> users = dao.findUsers(userName);
      usrldao.createroles(users.get(0).getUserId(), roleIds);
    } else {
      System.out.println("doPost, userId=" + userId);
      int id = Integer.parseInt(userId);
      user.setUserId(id);
      usrldao.delroles(id);
      usrldao.createroles(id, roleIds);
      System.out.println("doPost, call dao.update()");
      dao.update(id, user);
    }
    view = request.getRequestDispatcher(LIST);
    List<User> list = dao.getAll();
    System.out.println("doPost, list size =" + list.size());
    request.setAttribute("users", list);
    view.forward(request, response);
  }
예제 #6
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");
    }
  }