會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

Developer Forum » Adding static functions to html template

發表人: omark
10 年 前
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
10 年 前
It looks like I18n, so I guess you can put it in the prepareTemplateContext() method of ControllerUtils.java:
[code=java;first-line:91]public void prepareTemplateContext(final SimpleHash context, final ForumContext jforumContext)
{
...
context.put("I18n", I18n.getInstance());
...
context.put("TokenGenerator", TokenGenerator.getInstance());
...
}[/code]




會員註冊 / 登入  |  電腦版  |  Jump to top of page