play.mvc.Http.Context Java Examples
The following examples show how to use
play.mvc.Http.Context.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 6 votes |
protected Body getVerifyEmailMailingBodyAfterSignup(final String token, final User user, final Context ctx) { final boolean isSecure = getConfiguration().getBoolean( SETTING_KEY_VERIFICATION_LINK_SECURE); final String url = controllers.gsn.auth.routes.Signup.verify(token).absoluteURL( ctx.request(), isSecure); final Lang lang = Lang.preferred(ctx.request().acceptLanguages()); final String langCode = lang.code(); final String html = getEmailTemplate( "views.html.account.email.verify_email", langCode, url, token, user.name, user.email); final String text = getEmailTemplate( "views.txt.account.email.verify_email", langCode, url, token, user.name, user.email); return new Body(text, html); }
Example #2
Source File: Component.java From htwplus with MIT License | 6 votes |
@Override @Transactional public CompletionStage<Result> call(Context ctx) { String sessionId = ctx.session().get("id"); if(sessionId != null) { Long id = Long.parseLong(ctx.session().get("id")); Account account = accountManager.findById(id); if(account == null) { ctx.session().clear(); Logger.info("Clear Session"); return delegate.call(ctx); } ctx.args.put("account", account); } else { ctx.args.put("account", null); } return delegate.call(ctx); }
Example #3
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 6 votes |
protected Body getPasswordResetMailingBody(final String token, final User user, final Context ctx) { final boolean isSecure = getConfiguration().getBoolean( SETTING_KEY_PASSWORD_RESET_LINK_SECURE); final String url = controllers.gsn.auth.routes.Signup.resetPassword(token).absoluteURL( ctx.request(), isSecure); final Lang lang = Lang.preferred(ctx.request().acceptLanguages()); final String langCode = lang.code(); final String html = getEmailTemplate( "views.html.account.email.password_reset", langCode, url, token, user.name, user.email); final String text = getEmailTemplate( "views.txt.account.email.password_reset", langCode, url, token, user.name, user.email); return new Body(text, html); }
Example #4
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 6 votes |
@Override protected Body getVerifyEmailMailingBody(final String token, final GSNUsernamePasswordAuthUser user, final Context ctx) { final boolean isSecure = getConfiguration().getBoolean( SETTING_KEY_VERIFICATION_LINK_SECURE); final String url = controllers.gsn.auth.routes.Signup.verify(token).absoluteURL( ctx.request(), isSecure); final Lang lang = Lang.preferred(ctx.request().acceptLanguages()); final String langCode = lang.code(); final String html = getEmailTemplate( "views.html.account.signup.email.verify_email", langCode, url, token, user.getName(), user.getEmail()); final String text = getEmailTemplate( "views.txt.account.signup.email.verify_email", langCode, url, token, user.getName(), user.getEmail()); return new Body(text, html); }
Example #5
Source File: Navigation.java From htwplus with MIT License | 5 votes |
public static void set(Level level, String title, String parentTitle, Call parentCall) { Context ctx = Context.current(); ctx.args.put(levelIdent, level); ctx.args.put(titleIdent, title); ctx.args.put(parentTitleIdent, parentTitle); ctx.args.put(parentCallIdent, parentCall); }
Example #6
Source File: Navigation.java From htwplus with MIT License | 5 votes |
public static String getUriWithoutPagination() { String currentURI = Context.current().request().uri(); String returnURI = currentURI; // will remove &page=X&raw=true/false from currentURI if(currentURI.contains("&page=")) returnURI = currentURI.substring(0, currentURI.indexOf("&page=")); return returnURI; }
Example #7
Source File: Secured.java From play-rest-security with MIT License | 5 votes |
@Override public String getUsername(Context ctx) { String[] authTokenHeaderValues = ctx.request().headers().get(SecurityController.AUTH_TOKEN_HEADER); if ((authTokenHeaderValues != null) && (authTokenHeaderValues.length == 1) && (authTokenHeaderValues[0] != null)) { User user = models.User.findByAuthToken(authTokenHeaderValues[0]); if (user != null) { ctx.args.put("user", user); return user.getEmailAddress(); } } return null; }
Example #8
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 5 votes |
public void sendVerifyEmailMailingAfterSignup(final User user, final Context ctx) { final String subject = getVerifyEmailMailingSubjectAfterSignup(user, ctx); final String token = generateVerificationRecord(user); final Body body = getVerifyEmailMailingBodyAfterSignup(token, user, ctx); sendMail(subject, body, getEmailName(user)); }
Example #9
Source File: Secured.java From htwplus with MIT License | 5 votes |
/** * Returns the ID of the currently logged in user. * * @param ctx HTTP context * @return ID or null */ @Override public String getUsername(Context ctx) { // see if user is logged in if (ctx.session().get("id") == null) return null; // see if the session is expired String previousTick = ctx.session().get("userTime"); if (previousTick != null && !previousTick.equals("")) { long previousT = Long.valueOf(previousTick); long currentT = new Date().getTime(); long timeout = Long.valueOf(configuration.getString("sessionTimeout")) * 1000 * 60; long passedT = currentT - previousT; if (passedT > timeout && !ctx.session().containsKey("rememberMe")) { // session expired ctx.session().clear(); play.mvc.Controller.flash("info", messagesApi.get(Lang.defaultLang(), "error.sessionExpired")); return null; } } // update time in session String tickString = Long.toString(new Date().getTime()); ctx.session().put("userTime", tickString); return ctx.session().get("id"); }
Example #10
Source File: Secured.java From htwplus with MIT License | 5 votes |
/** * Returns Result instance to landing page (on un-authorization). * @param ctx HTTP context * @return Result instance */ @Override @SuppressWarnings("unchecked") public Result onUnauthorized(Context ctx) { // cookie outdated? save originURL to prevent redirect to index page after login ctx.session().put("originURL", ctx.request().path()); Form<Login> form = formFactory.form(Login.class).bindFromRequest(); if (Component.getFromContext(Component.ContextIdent.loginForm) != null) { form = (Form<Login>) Component.getFromContext(Component.ContextIdent.loginForm); } return unauthorized(landingpage.render(form)); }
Example #11
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 5 votes |
@Override protected String onLoginUserNotFound(final Context context) { context.flash() .put(controllers.gsn.auth.LocalAuthController.FLASH_ERROR_KEY, Messages.get("playauthenticate.password.login.unknown_user_or_pw")); return super.onLoginUserNotFound(context); }
Example #12
Source File: Secured.java From play-rest-security with MIT License | 4 votes |
@Override public Result onUnauthorized(Context ctx) { return unauthorized(); }
Example #13
Source File: AbstractJudgelsController.java From judgels with GNU General Public License v2.0 | 4 votes |
private boolean isSidebarOnTheLeft() { return !Context.current().args.containsKey("sidebar.isAfter"); }
Example #14
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
protected String getVerifyEmailMailingSubjectAfterSignup(final User user, final Context ctx) { return Messages.get("playauthenticate.password.verify_email.subject"); }
Example #15
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
public void sendPasswordResetMailing(final User user, final Context ctx) { final String token = generatePasswordResetRecord(user); final String subject = getPasswordResetMailingSubject(user, ctx); final Body body = getPasswordResetMailingBody(token, user, ctx); sendMail(subject, body, getEmailName(user)); }
Example #16
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
protected String getPasswordResetMailingSubject(final User user, final Context ctx) { return Messages.get("playauthenticate.password.reset_email.subject"); }
Example #17
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
@Override protected String getVerifyEmailMailingSubject( final GSNUsernamePasswordAuthUser user, final Context ctx) { return Messages.get("playauthenticate.password.verify_signup.subject"); }
Example #18
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
@Override protected GSNLoginUsernamePasswordAuthUser transformAuthUser(final GSNUsernamePasswordAuthUser authUser, final Context context) { return new GSNLoginUsernamePasswordAuthUser(authUser.getEmail()); }
Example #19
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
@Override protected GSNLoginUsernamePasswordAuthUser buildLoginAuthUser( final GSNLogin login, final Context ctx) { return new GSNLoginUsernamePasswordAuthUser(login.getPassword(), login.getEmail()); }
Example #20
Source File: GSNUsernamePasswordAuthProvider.java From gsn with GNU General Public License v3.0 | 4 votes |
@Override protected GSNUsernamePasswordAuthUser buildSignupAuthUser( final GSNSignup signup, final Context ctx) { return new GSNUsernamePasswordAuthUser(signup); }
Example #21
Source File: Component.java From htwplus with MIT License | 4 votes |
public static Account currentAccount() { return (Account)Context.current().args.get("account"); }
Example #22
Source File: Component.java From htwplus with MIT License | 4 votes |
public static Object getFromContext(String ident) { return Context.current().args.get(ident); }
Example #23
Source File: Component.java From htwplus with MIT License | 4 votes |
public static void addToContext(String ident, Object object) { Context.current().args.put(ident, object); }
Example #24
Source File: Navigation.java From htwplus with MIT License | 4 votes |
public static Call getParentCall() { return (Call)Context.current().args.get(parentCallIdent); }
Example #25
Source File: Navigation.java From htwplus with MIT License | 4 votes |
public static String getParentTitle() { return (String)Context.current().args.get(parentTitleIdent); }
Example #26
Source File: Navigation.java From htwplus with MIT License | 4 votes |
public static String getTitle() { return (String)Context.current().args.get(titleIdent); }
Example #27
Source File: Navigation.java From htwplus with MIT License | 4 votes |
public static Level getLevel() { return (Level)Context.current().args.get(levelIdent); }