Exemple #1
0
 @Get("json")
 public Representation getUserData() {
   try {
     if (getQuery().getValues("search") == null) {
       return mono();
     } else {
       return multi();
     }
   } catch (BadAuthenticationException e) {
     System.err.println(StatusFactory.getErrorMessage(e));
     return new JacksonRepresentation<Status>(StatusFactory.clientUnauthorized(e.getMessage()));
   } catch (Exception e) {
     System.err.println(StatusFactory.getErrorMessage(e));
     return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
   }
 }
Exemple #2
0
  private Representation editPasswordData(Form form) {
    String sessionHash = form.getFirstValue("session_hash");
    String oldPassword = form.getFirstValue("old_password");
    String newPassword = form.getFirstValue("new_password");

    try {
      mUserService.editPassword(sessionHash, oldPassword, newPassword);

      return new JacksonRepresentation<Status>(StatusFactory.ok());
    } catch (BadAuthenticationException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientUnauthorized(e.getMessage()));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }
Exemple #3
0
  @Post
  public Representation createUser(Representation entity) {
    Form form = new Form(entity);
    try {
      String fullName = form.getFirstValue("full_name");
      String password = form.getFirstValue("password");
      String hostIp = getClientInfo().getAddress();
      String hostAgent = getClientInfo().getAgent();

      Session session = mUserService.createUser(mLogin, fullName, password, hostIp, hostAgent);

      return new JacksonRepresentation<SessionRepresentation>(new SessionRepresentation(session));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }
Exemple #4
0
  private Representation editSimpleData(Form form) {
    String sessionHash = form.getFirstValue("session_hash");
    String fullName = form.getFirstValue("full_name");
    String email = form.getFirstValue("email");

    try {
      mUserService.editSimpleData(sessionHash, fullName, email);

      return new JacksonRepresentation<Status>(StatusFactory.ok());
    } catch (BadAuthenticationException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientUnauthorized(e.getMessage()));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }