Пример #1
0
  @Override
  public String execute(HttpServletRequest request, HttpServletResponse response)
      throws FunctionalException, TechnicalException {
    String username = request.getParameter(BaseConfig.USERNAME);
    String password = request.getParameter(BaseConfig.PASSWORD);

    UserService service;
    if (BaseConfig.USEMOCK) {
      service = UserServiceMock.getInstance();
    } else {
      service = UserServiceImpl.getInstance();
    }

    User user = null;

    user = service.find(username);

    if (user != null && user.getPassword().equals(password)) {

      HttpSession session = request.getSession();
      session.setAttribute(BaseConfig.USERNAME, user.getName());
      Role role = user.getRole();
      session.setAttribute(BaseConfig.ROLE, role);

    } else {
      throw new FunctionalException(Level.WARNING, BaseConfig.INVALID_DATA);
    }

    return BaseConfig.APP_CONTEXT; // Redirect to home page.
  }
  public void insertValues(User user) {

    try {

      stmt = conn.createStatement();
      String sql =
          "INSERT INTO user values('"
              + user.getUserId()
              + "','"
              + user.getUserEmail()
              + "','"
              + user.getPassword()
              + "','"
              + user.getRole()
              + "')";
      stmt.execute(sql);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
 @GET
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 @Produces("application/json")
 public Response getAllTimezones(@HeaderParam("token") String tokenString) {
   try {
     JSONObject jsonObject = new JSONObject();
     User user = verifyToken(tokenString);
     if (user == null) {
       return Response.status(Response.Status.UNAUTHORIZED).build();
     } else if (user.getRole().getIdRole() == 1) {
       List<Timezone> timezoneList = timezoneDAO.listTimezones();
       TimezoneDto[] timezones = Converters.listTimezoneToDto(timezoneList);
       jsonObject.put("timezones", timezones);
     } else {
       List<Timezone> timezoneList = timezoneDAO.listTimezones(user);
       TimezoneDto[] timezones = Converters.listTimezoneToDto(timezoneList);
       jsonObject.put("timezones", timezones);
     }
     return Response.status(Response.Status.OK).entity(String.valueOf(jsonObject)).build();
   } catch (Exception ex) {
     return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
   }
 }