[Logo] JForum - Powering Communities
  [Search] 搜尋   [Recent Topics] 最新主題   [Hottest Topics] 熱門主題   [Top Downloads] 熱門下載   [Groups] 回首頁 
[Register] 會員註冊 /  [Login] 登入 


JForum 2.8.3 is out with various fixes and improvements. Read all about it here

Adding static functions to html template RSS feed
討論區首頁 » Developer Forum
發表人 內容
omark


註冊時間: 2014/3/6
文章: 1
離線
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


註冊時間: 2011/6/30
文章: 250
離線
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]
 
討論區首頁 » Developer Forum
前往:   
行動版
Powered by JForum 2.8.3 © 2023 JForum Team • Maintained by Andowson Chang and Ulf Dittmer