Esempio n. 1
0
  @PermitAll
  @GET
  @Path("/searchuser")
  @Consumes("application/json")
  @Produces("application/json")
  public Response searchUser(@QueryParam("q") String username) {

    logger.info("Searching for user " + username);

    User user = this.findUser(username);

    ResponseBuilder builder;

    if (user == null) {
      ForCodeError error = ErrorFactory.getErrorFromIndex(ErrorFactory.USER_NOT_FOUND);
      builder = Response.status(Response.Status.NOT_FOUND).entity(error);

      logger.info("Unsuccessful attempt to find user.");
    } else {

      user.setPassword(null);
      user.setUserKey(null);

      builder = Response.status(Response.Status.FOUND).entity(user);

      logger.info("Successful attempt to find user.");
    }

    return builder.build();
  }
Esempio n. 2
0
  @PermitAll
  @POST
  @Path("/login")
  @Consumes("application/json")
  @Produces("application/json")
  public Response login(@QueryParam("user") String username, String password) {

    username = EncodingUtil.decode(username);

    logger.info(username + " is signing in");

    User user = this.findUser(username);
    ResponseBuilder builder;

    if (user == null) {
      logger.info("Incorrect username: "******"Incorrect password for this username: "******" is logged");

        builder = Response.status(Response.Status.OK).entity(user);
        return builder.build();
      }
    }

    return builder.build();
  }
Esempio n. 3
0
  @RolesAllowed(value = {"Admin", "Manager", "Contestant"})
  @POST
  @Path("/logout")
  @Consumes("application/json")
  @Produces("application/json")
  public Response logout(User user) {
    ResponseBuilder builder;
    if (user == null) {
      logger.info("Null entry on logout");
      builder = Response.status(Response.Status.NO_CONTENT);
      return builder.build();
    }

    logger.info("Removing " + user.getUsername() + "'s key");

    Authorizator auth = new Authorizator();

    auth.deleteKey(user);

    builder = Response.status(Response.Status.OK);
    return builder.build();
  }