[Logo] JForum - Powering Communities
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


JForum 2.6.2, which fixes a few bugs in 2.6.0, has been released. Download it from here
Adding static functions to html template RSS feed
Forum Index » Developer Forum
Author Message
omark


Joined: 2014/3/6
Messages: 1
Offline
Hi folks,

My name is Omar I'm new to JForum.

I want to add a token to an htm template by calling a java static function. The token is meant to protect the form from Cross-Site Request Forgery (CSRF) attacks, and therefore needs to be generated dynamically.

I saw similar constructions in some htm templates and since normally htm/html pages do not allow to have dynamic components I assumed that this is a JForum feature.

What i did is put the following code into the htm file:
<input type="hidden" name="csrf" value="${TokenGenerator.generateToken()}" />


However when I run the code I get the following error:
Expression TokenGenerator is undefined on line 4, column 47 in custom/forum_login.htm.

I think I also need to define that function in some configuration file, however I have no clue how to do that.

Any help would be appreciated.
andowson


Joined: 2011/6/30
Messages: 214
Offline
It looks like I18n, so I guess you can put it in the prepareTemplateContext() method of ControllerUtils.java:
public void prepareTemplateContext(final SimpleHash context, final ForumContext jforumContext)
{
    ...
    context.put("I18n", I18n.getInstance());
    ...
    context.put("TokenGenerator", TokenGenerator.getInstance());
    ...
}
 
Forum Index » Developer Forum
Go to:   
Mobile view
Powered by JForum 2.6.0 © 2019 JForum Team • Maintained by Andowson Chang and Ulf Dittmer
Website Security Test