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

    try {
      securityChecker.checkUserLoggedIn(request);
    } catch (ServiceNotAllowedException e) {
      ServiceNotAllowedJSONException exception =
          new ServiceNotAllowedJSONException("user/changePassword", request.getServiceKey());
      response.setServiceNotAllowedException(exception);
      return response;
    } catch (UserNotLoggedInException e) {
      UserNotLoggedInJSONException exception =
          new UserNotLoggedInJSONException("user/changePassword");
      response.setUserNotLoggedInException(exception);
      return response;
    }

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