예제 #1
0
  @POST
  @Path("register")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @Override
  public AuthenticationResponse register(UserRegistrationRequest request) {
    AuthenticationResponse response = new AuthenticationResponse();

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

    if (StringUtils.isBlank(request.getEmail())) {
      response.setFieldRequiredJSONException(
          new FieldRequiredJSONException("user/register", request, "email"));
      return response;
    } else if (StringUtils.isBlank(request.getPassword())) {
      response.setFieldRequiredJSONException(
          new FieldRequiredJSONException("user/register", request, "password"));
      return response;
    } else if (StringUtils.isBlank(request.getFirstName())) {
      response.setFieldRequiredJSONException(
          new FieldRequiredJSONException("user/register", request, "firstName"));
      return response;
    } else if (StringUtils.isBlank(request.getLastName())) {
      response.setFieldRequiredJSONException(
          new FieldRequiredJSONException("user/register", request, "lastName"));
      return response;
    }

    if (!EmailValidator.getInstance().isValid(request.getEmail())) {
      response.setInvalidEmailJSONException(
          new InvalidEmailJSONException("user/register", request.getEmail()));
      return response;
    }

    User user = new User();
    user.setEmail(request.getEmail().toLowerCase());
    user.setFirstName(request.getFirstName());
    user.setLastName(request.getLastName());

    try {
      String sessionKey = userService.register(user, request.getPassword(), Platform.OTHER);
      response.setSessionKey(sessionKey);
      return response;
    } catch (EmailAlreadyInUseException e) {
      response.setRegisterEmailAlreadyInUseJSONException(
          new RegisterEmailAlreadyInUseJSONException("user/register", request.getEmail()));
      return response;
    } catch (PasswordLenghtInvalidException e) {
      response.setPasswordLengthInvalidJSONException(
          new PasswordLengthInvalidJSONException("user/register"));
      return response;
    }
  }
예제 #2
0
  @Post
  public String post(Request request) {
    String superResult = super.get(request);
    if (shouldRedirect(superResult)) {
      return superResult;
    }

    buildContactReasons();

    if (StringUtils.isBlank(firstName) || StringUtils.isBlank(lastName)) {
      if (StringUtils.isBlank(firstName)) {
        firstName = "";
      }

      if (StringUtils.isBlank(lastName)) {
        lastName = "";
      }
      setErrorMessage(getMessage("contact.error.nameRequired"));
    }

    if (StringUtils.isBlank(email)) {
      setErrorMessage(getMessage("contact.error.emailRequired"));
    } else if (!EmailValidator.getInstance().isValid(email)) {
      setErrorMessage(getMessage("contact.error.emailInvalid"));
    }

    if (StringUtils.isBlank(message)) {
      setErrorMessage(getMessage("contact.error.messageRequired"));
    }

    if (hasErrorMessages()) {
      return null;
    }

    String body =
        "This is an automated messages sent using the WorkTime form located at http://worktime-web.appspot.com/contact.<br/>"
            + "In order to reply to this message just hit the the reply button and you will be in direct contact with the person who sent the form!<br/>"
            + "<br/>"
            + "The message sent is:<br/>"
            + "<br/>"
            + message;

    User from = new User();
    from.setFirstName(firstName);
    from.setLastName(lastName);
    from.setEmail(email);

    User to = new User();
    to.setFirstName("Work Time");
    to.setLastName("");
    to.setEmail("*****@*****.**");
    EmailUtil.sendEmail(
        "WorkTime Contact Form (" + reason + ")",
        body,
        "text/html",
        from,
        Arrays.asList(new User[] {User.getTechnicalUser()}));

    return addMessageToSelf(MessageType.INFO, getMessage("contact.emailSent"));
  }
예제 #3
0
  @GET
  @Path("profile")
  @Consumes(MediaType.TEXT_PLAIN)
  @Produces(MediaType.APPLICATION_JSON)
  @Override
  public UserProfileResponse profile(
      @QueryParam("serviceKey") String serviceKey,
      @QueryParam("email") String email,
      @QueryParam("sessionKey") String sessionKey) {
    UserProfileResponse response = new UserProfileResponse();

    AuthenticatedUserRequest request = new AuthenticatedUserRequest() {};
    request.setServiceKey(serviceKey);
    request.setEmail(email);
    request.setSessionKey(sessionKey);

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

    User user = userService.findUser(email);

    response.setFirstName(user.getFirstName());
    response.setLastName(user.getLastName());
    response.setEmail(user.getEmail());
    response.setRegisteredSince(user.getRegistrationDate());
    response.setRole(user.getRole());
    response.setLoggedInSince(userService.getLogInTime(user, sessionKey));

    return response;
  }