Example #1
0
  @POST
  @Path("login")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @Override
  public AuthenticationResponse login(UserLoginRequest request) {
    AuthenticationResponse response = new AuthenticationResponse();

    try {
      securityChecker.checkService(request);
    } catch (ServiceNotAllowedException e1) {
      ServiceNotAllowedJSONException exception =
          new ServiceNotAllowedJSONException("user/login", request.getServiceKey());
      response.setServiceNotAllowedException(exception);
      return response;
    }

    try {
      String sessionKey =
          userService.login(request.getEmail(), request.getPassword(), Platform.OTHER);
      response.setSessionKey(sessionKey);
      return response;
    } catch (UserNotFoundException e) {
      response.setEmailOrPasswordIncorrectJSONException(
          new EmailOrPasswordIncorrectJSONException("user/login"));
      return response;
    } catch (PasswordIncorrectException e) {
      response.setEmailOrPasswordIncorrectJSONException(
          new EmailOrPasswordIncorrectJSONException("user/login"));
      return response;
    }
  }