Package cpe.hapa.model

Examples of cpe.hapa.model.User


   * COMMANDES ET SOUS-METHODES
   * =============================
   * ********************************/
 
  private void changePassword(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    User user = null;
    try {
      user = Authenticate.getConnectedUser(request);
    } catch(Exception e) {
      throw new ServletException(e);
    }
   
    if(user == null) {
      response.getWriter().print("{\"redirect\":\"index.html\"}");
    } else {
      String oldPassword = request.getParameter("oldPassword");
      String newPassword = request.getParameter("newPassword");
      String newPassword2 = request.getParameter("newPassword2");
     
      if(user.getPassword().equals(oldPassword)) {
        if(newPassword != null && !newPassword.isEmpty() && newPassword.equals(newPassword2)) {
          try {
            user.setPassword(newPassword);
            user.setIsPasswordChanged(true);
            UserDAO.update(user);
          } catch (Exception e) {
            throw new ServletException(e);
          }
         
View Full Code Here


 
  private void authenticationInfos(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
    Boolean connected = false;
    String authInfos = "";
    try {
      User user = Authenticate.getConnectedUser(request);
      if(user != null) {
        connected = true;
        String redirect = null;
        if(user.isPasswordChanged()) {
          redirect = "userDetails.html";
        } else {
          redirect = "changePassword.html";
        }
        authInfos = ","
          + "\"redirect\":\"" + redirect + "\","
          + "\"duration\":" + (int) (user.getDureeConnexion()/60) + ","
          + "\"role\":\"" + user.getRole() + "\","
          + "\"username\":\"" + user.getPrenom() + " " + user.getNom() + "\","
          + "\"lastConnection\":\"" + new SimpleDateFormat("dd/MM/yyyy hh:mm").format(user.getDateConnexion()) + "\"";
      }
      response.getWriter().print("{"+
        "\"connected\":" + connected + ","
        + "\"nbUserConnected\":" + SessionHandler.getTotalActiveSession()
        + authInfos + "}"
View Full Code Here

    String email = request.getParameter("email");
    String login = request.getParameter("login");
    String role = RoleDAO.getUserRole();
    String isPasswordChanged = "false";
    String creationDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    User user = null;
    String password = UUID.randomUUID().toString().substring(0, 9);
   
    try {
      if(UserDAO.count()==0) {
        role = RoleDAO.getAdminRole();
View Full Code Here

    String email = request.getParameter("email");
    String login = request.getParameter("login");
    String role = request.getParameter("role");
    String isPasswordChanged = "false";
    String creationDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    User user = null;
    String password = request.getParameter("password");
    String rePassword = request.getParameter("password2");
   
    if(password == null || !password.equals(rePassword)) {
      throw new ServletException("Les mots de passe ne sont pas corrects");
View Full Code Here

      response.sendError(HttpServletResponse.SC_BAD_REQUEST,"Données du formulaire incorrectes");
    }
  }

  private void addUserQueue(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    User connectedUser = null;
   
    try {
      connectedUser = Authenticate.getConnectedUser(request);
    } catch (NumberFormatException | ParseException e) {
      throw new ServletException(e);
    }
   
    if( !(connectedUser != null && connectedUser.isInRole(RoleDAO.getAdminRole())) ) {
      throw new ServletException("Vous n'êtes pas administrateur, vous ne pouvez pas ajouter d'utilisateur");
    }
   
    String nom = request.getParameter("nom");
    String prenom = request.getParameter("prenom");
View Full Code Here

  }
 
  protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    String login = request.getParameter("login");
    String password = request.getParameter("password");
    User user = null;
   
    try {
      if(!Authenticate.authenticate(request, login, password)) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN,"Mauvais login et/ou mot de passe");
      } else {
        user = Authenticate.getConnectedUser(request);
        if(!user.isPasswordChanged()) {
          response.getWriter().print("{\"redirect\":\"changePassword.html\"}");
        } else {
          response.getWriter().print("{\"redirect\":\"userDetails.html\"}");
        }
      }
View Full Code Here

      e.printStackTrace();
    }
  }
 
  private void userDetails(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    User user = null;
    try {
      user = Authenticate.getConnectedUser(request);
    } catch (NumberFormatException | ParseException e) {
      throw new ServletException(e);
    }
   
    if(user == null) {
      throw new ServletException("Vous n'êtes pas/plus connecté");
    }
   
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
    JSONObject jsonUser = new JSONObject();
    jsonUser.put("id", KeyFactory.keyToString(user.getKey()));
    jsonUser.put("nom", user.getNom());
    jsonUser.put("prenom", user.getPrenom());
    jsonUser.put("dateNaissance", simpleDateFormat.format(user.getDateNaissance()));
    jsonUser.put("email", user.getEmail());
    jsonUser.put("login", user.getLogin());
    jsonUser.put("dateCreation", simpleDateFormat.format(user.getDateCreation()));
    if(user.getDateConnexion() != null) {
      jsonUser.put("lastConnection", simpleDateFormat.format(user.getDateConnexion()));
    }
    jsonUser.put("duration", user.getDureeConnexion());
   
    response.getWriter().print(jsonUser);
  }
View Full Code Here

   
    response.getWriter().print(jsonUser);
  }

  protected User checkAndInstantiateUserModel(String nom,String prenom,String dateNaissance,String email,String login,String password,String role,String isPasswordChanged,String dateConnexion,String dureeConnexion,String dateCreation) throws ParseException, ServletException {
    User user = null;
    if ( nom != null &&
        prenom != null &&
        dateNaissance != null &&
        email != null &&
        login != null &&
        password != null &&
        role != null &&
        isPasswordChanged != null &&
        !nom.isEmpty() &&
        !prenom.isEmpty() &&
        !dateNaissance.isEmpty() &&
        !email.isEmpty() &&
        !login.isEmpty() &&
        !password.isEmpty() &&
        !role.isEmpty() &&
        !isPasswordChanged.isEmpty())
    {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      user = new User(
        null,
        nom,
        prenom,
        sdf.parse(dateNaissance),
        email,
View Full Code Here

    String arrivalDate = request.getParameter("arrivalDate");
    String departureTime = request.getParameter("departureTime");
    String arrivalTime = request.getParameter("arrivalTime");
    String price = request.getParameter("price");
    String availableSeats = request.getParameter("availableSeats");
    User connectedUser = null;
    Vol vol = null;
   
    try {
      connectedUser = Authenticate.getConnectedUser(request);
    } catch (NumberFormatException | ParseException e) {
View Full Code Here

public class Authenticate {
  public static String AuthenticationKey = "userKeyString";
 
  public static Boolean authenticate(HttpServletRequest request, String login, String password) throws NumberFormatException, TooManyResultsException, ParseException, EntityNotFoundException {
    User user = UserDAO.getByLoginOrEmail(login);
    if (user==null) {
      return false;
    }
   
    if(user.getPassword().equals(password)) {
      HttpSession session = request.getSession(true);
      session.setAttribute(AuthenticationKey, KeyFactory.keyToString(user.getKey()));
      SessionHandler.addSession(user.getKey());
      return true;
    }
   
    return false;
  }
View Full Code Here

TOP

Related Classes of cpe.hapa.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.