protected Body getPasswordResetMailingBody(String token, User user, Context ctx) {

    boolean isSecure = getConfiguration().getBoolean(SETTING_KEY_PASSWORD_RESET_LINK_SECURE);
    String url = routes.Signup.resetPassword(token).absoluteURL(ctx.request(), isSecure);

    Lang lang = Lang.preferred(ctx.request().acceptLanguages());
    String langCode = lang.code();

    String html =
        getEmailTemplate(
            "views.html.account.email.password_reset",
            langCode,
            url,
            token,
            user.getName(),
            user.getEmail());
    String text =
        getEmailTemplate(
            "views.txt.account.email.password_reset",
            langCode,
            url,
            token,
            user.getName(),
            user.getEmail());

    return new Body(text, html);
  }
  protected Body getVerifyEmailMailingBodyAfterSignup(String token, User user, Context ctx) {

    boolean isSecure = getConfiguration().getBoolean(SETTING_KEY_VERIFICATION_LINK_SECURE);
    String url = routes.Signup.verify(token).absoluteURL(ctx.request(), isSecure);

    Lang lang = Lang.preferred(ctx.request().acceptLanguages());
    String langCode = lang.code();

    String html =
        getEmailTemplate(
            "views.html.account.email.verify_email",
            langCode,
            url,
            token,
            user.getName(),
            user.getEmail());
    String text =
        getEmailTemplate(
            "views.txt.account.email.verify_email",
            langCode,
            url,
            token,
            user.getName(),
            user.getEmail());

    return new Body(text, html);
  }
Ejemplo n.º 3
0
  public static void editPage(String tmpl, String pageName, Long id) {
    CMSPage page = id != null ? CMSPage.findById(id) : CMSPage.findByName(pageName, Lang.get());
    if (page == null) {
      page = new CMSPage();
      page.name = pageName;
      page.active = true;
      page.locale = Lang.get();
    }

    if (!Profiler.canEdit(page.name)) forbidden();

    renderTemplate("@edit", page, tmpl);
  }
Ejemplo n.º 4
0
 public static void addPage(String tags, String name) {
   if (!Profiler.canEnter()) forbidden();
   CMSPage page = new CMSPage();
   page.active = true;
   page.tags = tags;
   page.locale = Lang.get();
   page.name = name;
   renderTemplate("@edit", page);
 }
  public GTRenderingResult internalGTRender(Map<String, Object> args) {
    Http.Request currentResponse = Http.Request.current();
    if (currentResponse != null) {
      args.put("_response_encoding", currentResponse.encoding);
    }
    args.put("play", new Play());
    args.put("messages", new Messages());
    args.put("lang", Lang.get());

    return renderGTTemplate(args);
  }
Ejemplo n.º 6
0
  public static void savePage(@Valid CMSPage page, boolean active) throws Throwable {
    if (!Profiler.canEdit(page.name)) forbidden();

    checkAuthenticity();

    page.locale = defaultString(page.locale, Lang.get());
    page.active = active;

    if (request.params.get("delete") != null) {
      page.delete();
      Extension.invoke("afterDelete", page);
      index();
    }

    if (validation.hasErrors()) renderTemplate("@edit", page);

    page.save();
    Extension.invoke("afterSave", page);
    if (request.params.get("savePage") != null) Frontend.show(null, page.name);
    index();
  }
Ejemplo n.º 7
0
 public static void getInvite(@Required @Email String email, String returnUrl) throws Throwable {
   if (validation.hasErrors()) {
     flash.error(Messages.get("web.invite.email.invalid"));
     params.flash();
   } else {
     if (User.findByEmail(email) != null) {
       flash.error(Messages.get("web.invite.email.exists"));
       params.flash();
     } else {
       // Create the invitation instance.
       String lang = Lang.get();
       Invitation invite = new Invitation();
       invite.email = email;
       invite.locale = lang;
       invite.insert();
       flash.success(Messages.get("web.invite.success"));
     }
   }
   if (StringUtils.isBlank(returnUrl)) {
     Application.index();
   }
   redirect(returnUrl);
 }
  public static void _recaptcha(
      Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {

    final String disabled = Play.configuration.getProperty("ugot.recaptcha.disable", "false");
    if ("true".equals(disabled.trim().toLowerCase())) {
      return;
    }
    String publickey =
        Play.configuration.getProperty("ugot.recaptcha.publicKey", "YOUR_RECAPTCHA_PUBLIC_KEY");
    String privatekey =
        Play.configuration.getProperty(
            "ugot.recaptcha.privateKey", RecaptchaValidator.YOUR_RECAPTCHA_PRIVATE_KEY);

    if (publickey == null
        || privatekey == null
        || publickey.trim().length() == 0
        || privatekey.trim().length() == 0
        || "YOUR_RECAPTCHA_PUBLIC_KEY".equals(publickey)
        || RecaptchaValidator.YOUR_RECAPTCHA_PRIVATE_KEY.equals(privatekey)) {

      throw new TemplateExecutionException(
          template.template, fromLine, ERROR_MSG, new TagInternalException(ERROR_MSG));
    } else {

      Properties props = new Properties();

      Object o = args.get("tabindex");
      if (o != null) {
        String tabindex = o.toString();
        if (tabindex != null) props.put("tabindex", tabindex);
      }

      String theme = (String) args.get("theme");
      if (theme != null) props.put("theme", theme);

      String lang = (String) args.get("lang");
      if (lang == null) {
        // figure what language the application use and see if recaptcha
        // supports it, defaults to en
        lang = Lang.get();
        if (lang == null || lang.trim().length() == 0 || !isLangSupported(lang)) lang = "en";
      }
      props.put("lang", lang);

      // add support for captcha over https:
      Boolean https = (Boolean) args.get("https");

      if (https == null) {
        https = false;
      }

      String captcha;
      if (https) {
        captcha =
            ReCaptchaFactory.newSecureReCaptcha(publickey, privatekey, false)
                .createRecaptchaHtml(null, props);

      } else {
        captcha =
            ReCaptchaFactory.newReCaptcha(publickey, privatekey, false)
                .createRecaptchaHtml(null, props);
      }

      out.print(captcha);
    }
  }
Ejemplo n.º 9
0
 /**
  * Needs this method to do stuff *before* init() is executed. The different
  * Invocation-implementations does a lot of stuff in init() and they might do it before calling
  * super.init()
  */
 protected void preInit() {
   // clear language for this request - we're resolving it later when it is needed
   Lang.clear();
 }
Ejemplo n.º 10
0
 public String render(Map<String, Object> args) {
     compile();
     Binding binding = new Binding(args);
     binding.setVariable("play", new Play());
     binding.setVariable("messages", new Messages());
     binding.setVariable("lang", Lang.get());
     StringWriter writer = null;
     Boolean applyLayouts = false;
     if (!args.containsKey("out")) {
         applyLayouts = true;
         layout.set(null);
         writer = new StringWriter();
         binding.setProperty("out", new PrintWriter(writer));
         currentTemplate.set(this);
     }
     if (!args.containsKey("_body") && !args.containsKey("_isLayout") && !args.containsKey("_isInclude")) {
         layoutData.set(new HashMap<Object, Object>());
         TagContext.init();
     }
     ExecutableTemplate t = (ExecutableTemplate) InvokerHelper.createScript(compiledTemplate, binding);
     t.template = this;
     Monitor monitor = null;
     try {
         monitor = MonitorFactory.start(name);
         long start = System.currentTimeMillis();
         t.run();
         monitor.stop();
         monitor = null;
         Logger.trace("%sms to render template %s", System.currentTimeMillis() - start, name);
     } catch (NoRouteFoundException e) {
         if (e.isSourceAvailable()) {
             throw e;
         }
         throwException(e);
     } catch (PlayException e) {
         throw (PlayException) cleanStackTrace(e);
     } catch (DoBodyException e) {
         if (Play.mode == Mode.DEV) {
             compiledTemplate = null;
             BytecodeCache.deleteBytecode(name);
         }
         Exception ex = (Exception) e.getCause();
         throwException(ex);
     } catch (Throwable e) {
         if (Play.mode == Mode.DEV) {
             compiledTemplate = null;
             BytecodeCache.deleteBytecode(name);
         }
         throwException(e);
     } finally {
         if (monitor != null) {
             monitor.stop();
         }
     }
     if (applyLayouts && layout.get() != null) {
         Map<String, Object> layoutArgs = new HashMap<String, Object>(args);
         layoutArgs.remove("out");
         layoutArgs.put("_isLayout", true);
         String layoutR = layout.get().render(layoutArgs);
         return layoutR.replace("____%LAYOUT%____", writer.toString().trim());
     }
     if (writer != null) {
         return writer.toString();
     }
     return null;
 }
Ejemplo n.º 11
0
 /** Returns the current lang. */
 public static play.i18n.Lang lang() {
   return play.i18n.Lang.preferred(Context.current().request().acceptLanguages());
 }