Beispiel #1
0
  public Result create() {
    Form<Profit> form = Form.form(Profit.class).bindFromRequest();

    if (form.hasErrors()) {
      return badRequest(form.errorsAsJson());
    }

    Profit profit = form.get();

    if (Profit.existsProfitWithId(profit.getIdProfit())) {
      return Results.status(409, "already exists");
    }

    Integer idAdvisedUser = RequestUtils.getIntegerFromBody(request(), "idAdvisedUser");

    if (idAdvisedUser == null) {
      return badRequest("You need to add the id of the adviseduser");
    }

    AdvisedUser advisedUser = AdvisedUser.findAdvisedUserWithId(idAdvisedUser);

    if (advisedUser == null) {
      return Results.status(409, "there is no adviseduser with this id");
    }

    profit.setUser(advisedUser);

    profit.save();

    return created();
  }
  public Result doResetPassword() {
    com.feth.play.module.pa.controllers.AuthenticateDI.noCache(this.session.response());
    final Form<ModelAuth.PasswordReset> filledForm = getResetPasswordForm().bindFromRequest();
    if (filledForm.hasErrors()) {

      boolean disableIndexing = false;
      ContentInner contentInner = renderResetPasswordView(filledForm);

      return Results.badRequest(this.onRenderListener.onRender(contentInner, disableIndexing));
    } else {
      final String token = filledForm.get().token;
      final String newPassword = filledForm.get().password;

      final EntryTokenAction tokenAction =
          Auth.isTokenValid(token, EntryTokenAction.Type.PASSWORD_RESET);
      if (tokenAction == null) {

        ContentInner contentInner =
            new PageAuthAccount(this.session, this.onRenderListener).renderNoTokenOrInvalidView();
        boolean disableIndexing = false;

        return Results.badRequest(this.onRenderListener.onRender(contentInner, disableIndexing));
      }
      final EntryUser user = tokenAction.targetUser;
      try {
        // Pass true for the second parameter if you want to
        // automatically create a password and the exception never to
        // happen
        user.resetPassword(new ProviderUsernamePasswordAuthUser(newPassword), false);
      } catch (final RuntimeException re) {
        this.session.flash(
            Auth.FLASH_MESSAGE_KEY,
            Messages.get("playauthenticate.reset_password.message.no_password_account"));
      }
      final boolean login = ProviderUsernamePasswordAuth.getProvider().isLoginAfterPasswordReset();
      if (login) {
        // automatically log in
        this.session.flash(
            Auth.FLASH_MESSAGE_KEY,
            Messages.get("playauthenticate.reset_password.message.success.auto_login"));

        return PlayAuthenticate.loginAndRedirect(
            this.session.ctx(), new ProviderLoginUsernamePasswordAuthUser(user.email));
      } else {
        // send the user to the login page
        this.session.flash(
            Auth.FLASH_MESSAGE_KEY,
            Messages.get("playauthenticate.reset_password.message.success.manual_login"));
      }
      return this.onRenderListener.redirectToLogin();
    }
  }
  public static Result addThirdParty() {
    AppUtils.setHeaders(response());

    try {
      ThirdParty thirdParty = Form.form(ThirdParty.class).bindFromRequest().get();
      thirdParty.save();

      return Results.ok(Json.toJson(thirdParty));
    } catch (Exception e) {
      e.printStackTrace();
      return Results.internalServerError(AppUtils.errorJsonResponse(e.getMessage()));
    }
  }
Beispiel #4
0
  @Override
  public play.mvc.Result onError(final RequestHeader rh, final Throwable t) {
    Logger.error("onError " + rh + " " + t);

    JPA.withTransaction(
        new play.libs.F.Callback0() {

          @Override
          public void invoke() throws Throwable {
            Group group =
                Group.findByTitle(
                    play.Play.application().configuration().getString("htwplus.admin.group"));
            if (group != null) {
              Post p = new Post();
              p.content = "Request: " + rh + "\nError: " + t;
              p.owner =
                  Account.findByEmail(
                      play.Play.application().configuration().getString("htwplus.admin.mail"));
              p.group = group;
              p.create();
            }
          }
        });

    // prod mode? return 404 page
    if (Play.mode(play.api.Play.current()).toString().equals("Prod")) {
      return play.mvc.Results.redirect(routes.Application.error());
    }

    return super.onError(rh, t);
  }
  public static Result deleteThirdParty(long thirdPartyId) {
    AppUtils.setHeaders(response());

    ThirdParty thirdParty = ThirdParty.getById(thirdPartyId);
    thirdParty.delete();

    return Results.ok(AppUtils.okJsonResponse());
  }
 @Override
 public Result onHandlerNotFound(RequestHeader r) {
   // usually one need to use a customized error reporting in production.
   //
   if (Play.application().isProd() || Play.application().isDev())
     return Results.notFound(JapidController.renderJapidWith("onHandlerNotFound.html", r));
   else return super.onHandlerNotFound(r);
 }
  public Result renderResetPassword(final String token) {
    com.feth.play.module.pa.controllers.AuthenticateDI.noCache(this.session.response());
    final EntryTokenAction ta = Auth.isTokenValid(token, EntryTokenAction.Type.PASSWORD_RESET);
    if (ta == null) {

      ContentInner contentInner =
          new PageAuthAccount(this.session, this.onRenderListener).renderNoTokenOrInvalidView();
      boolean disableIndexing = false;

      return Results.badRequest(this.onRenderListener.onRender(contentInner, disableIndexing));
    }

    boolean disableIndexing = false;
    ContentInner contentInner =
        renderResetPasswordView(getResetPasswordForm().fill(new ModelAuth.PasswordReset(token)));

    return Results.ok(this.onRenderListener.onRender(contentInner, disableIndexing));
  }
  public Result doRemindPassword() {
    com.feth.play.module.pa.controllers.AuthenticateDI.noCache(this.session.response());
    final Form<ModelAuth.Identity> filledForm = getForgotPasswordForm().bindFromRequest();
    if (filledForm.hasErrors()) {
      // User did not fill in his/her email

      boolean disableIndexing = false;
      ContentInner contentInner = renderRemindPasswordView(filledForm);

      return Results.badRequest(this.onRenderListener.onRender(contentInner, disableIndexing));
    } else {
      // The email address given *BY AN UNKNWON PERSON* to the form - we
      // should find out if we actually have a user with this email
      // address and whether password login is enabled for him/her. Also
      // only send if the email address of the user has been verified.
      final String email = filledForm.get().email;

      // We don't want to expose whether a given email address is signed
      // up, so just say an email has been sent, even though it might not
      // be true - that's protecting our user privacy.
      this.session.flash(
          Auth.FLASH_MESSAGE_KEY,
          Messages.get("playauthenticate.reset_password.message.instructions_sent", email));

      final EntryUser user = EntryUser.findByEmail(email);
      if (user != null) {
        // yep, we have a user with this email that is active - we do
        // not know if the user owning that account has requested this
        // reset, though.
        final ProviderUsernamePasswordAuth provider = ProviderUsernamePasswordAuth.getProvider();
        // User exists
        if (user.emailValidated) {
          provider.sendPasswordResetMailing(user, this.session.ctx());
          // In case you actually want to let (the unknown person)
          // know whether a user was found/an email was sent, use,
          // change the flash message
        } else {
          // We need to change the message here, otherwise the user
          // does not understand whats going on - we should not verify
          // with the password reset, as a "bad" user could then sign
          // up with a fake email via OAuth and get it verified by an
          // a unsuspecting user that clicks the link.
          this.session.flash(
              Auth.FLASH_MESSAGE_KEY,
              Messages.get("playauthenticate.reset_password.message.email_not_verified"));

          // You might want to re-send the verification email here...
          provider.sendVerifyEmailMailingAfterSignup(user, this.session.ctx());
        }
      }

      return this.onRenderListener.redirectToMain();
    }
  }
Beispiel #9
0
 public static Result toResult(RuntimeException re) {
   Logger.error("ERROR: ", re);
   String msg = re.getMessage();
   if (msg == null) {
     // api doesn't allow null strings
     msg = "";
   }
   re.printStackTrace();
   if (re instanceof NotFoundException) {
     return Results.notFound(msg);
   } else if (re instanceof ForbiddenException) {
     return Results.forbidden(msg);
   } else if (re instanceof IllegalStateException
       || re instanceof IllegalArgumentException
       || re instanceof UnsupportedOperationException
       || re instanceof PersistenceException) {
     return Results.badRequest(re.getMessage());
   }
   return Results.internalServerError(msg);
 }
Beispiel #10
0
  @Override
  public Result onError(RequestHeader request, Throwable t) {
    AccessLogger.log(request, null, Http.Status.INTERNAL_SERVER_ERROR);

    if (Play.isProd()) {
      return Results.internalServerError(
          views.html.error.internalServerError_default.render("error.internalServerError"));
    } else {
      return super.onError(request, t);
    }
  }
 public Result authUser() {
   Http.Cookie cookie = request().cookie(Constants.AuthTokenCookieKey);
   if (cookie != null) {
     User user = new User(3L, "*****@*****.**", "123456", "TestUser");
     return ok(Json.toJson(user));
   } else {
     ObjectNode node = Json.newObject();
     node.put("code", "UNAUTHORIZED");
     node.put("message", "Unauthorized");
     return Results.unauthorized(node);
   }
 }
  public Result render() {

    boolean disableIndexing = true;
    String title = Messages.get("playauthenticate.index.intro");
    String description = Messages.get("playauthenticate.index.intro.description");
    String keywords = Messages.get("playauthenticate.index.intro.keywords");

    Content content = ViewIndex.render();

    ContentInner contentInner = new ContentInner(title, description, keywords, content);
    return Results.ok(this.onRenderListener.onRender(contentInner, disableIndexing));
  }
  public Result renderRemindPassword(final String email) {

    com.feth.play.module.pa.controllers.AuthenticateDI.noCache(this.session.response());
    Form<ModelAuth.Identity> form = getForgotPasswordForm();

    if (email != null && !email.trim().isEmpty()) {
      form = form.fill(new ModelAuth.Identity(email));
    }

    boolean disableIndexing = false;
    ContentInner contentInner = renderRemindPasswordView(form);

    return Results.ok(this.onRenderListener.onRender(contentInner, disableIndexing));
  }
  public static Promise<Result> get(String symbol) {
    ActorRef stockSentimentActor =
        ActorManagerExtension.ActorManagerExtensionProvider.get(Akka.system())
            .getStockSentimentProxy();
    Future<Object> futureStockSentiments =
        Patterns.ask(stockSentimentActor, new StockSentimentActor.GetSentiment(symbol), timeout);
    Promise<Object> promiseSentiments = Promise.wrap(futureStockSentiments);

    return promiseSentiments
        .<Result>map(
            obj -> {
              StockSentimentActor.SendSentiment sendSentiment =
                  (StockSentimentActor.SendSentiment) obj;
              return Results.ok(sendSentiment.getSentiment());
            })
        .recover(StockSentiment::errorResponse);
  }
  @SecuredAction
  public WebSocket<String> getSocket() {
    // User player = (User) ctx().args.get(SecureSocial.USER_KEY);
    User player = (User) SecureSocial.currentUser(env).get(100);
    logger.debug("[LobbyController:getSocket] getSocket called from User: "******"[LobbyController:getSocket] ...player found! Returning WebSocket for this player");
          return lobbys.get(lobbyName).getSocketForPlayer(player);
        }
      }
    }
    logger.debug(
        "[LobbyController:getSocket] ...player not found. Player didn't joined a lobby. Rejecting WebSocket.");
    return WebSocket.reject(Results.badRequest("Player didn't joined a game."));
  }
 @Override
 public Result onBadRequest(RequestHeader r, String s) {
   if (Play.application().isProd())
     return Results.badRequest(JapidController.renderJapidWith("onBadRequest.html", r, s));
   else return super.onBadRequest(r, s);
 }
  public static Result getThirdParties() {
    AppUtils.setHeaders(response());

    List<ThirdParty> thirdParties = ThirdParty.getAll();
    return Results.ok(Json.toJson(thirdParties));
  }
  public static Result getThirdParty(long thirdPartyId) {
    AppUtils.setHeaders(response());

    ThirdParty thirdParty = ThirdParty.getById(thirdPartyId);
    return Results.ok(Json.toJson(thirdParty));
  }
Beispiel #19
0
 public static Result badRequestWrapper(String s) {
   Map<String, String> map = new HashMap<>();
   map.put("error", s);
   String error = new Gson().toJson(map);
   return Results.ok(error);
 }
 @Override
 public Result onError(RequestHeader h, Throwable t) {
   if (Play.application().isProd())
     return Results.internalServerError(JapidController.renderJapidWith("onError.html", h, t));
   else return super.onError(h, t);
 }
Beispiel #21
0
 @Override
 public Result onHandlerNotFound(RequestHeader request) {
   AccessLogger.log(request, null, Http.Status.NOT_FOUND);
   return Results.notFound(ErrorViews.NotFound.render());
 }