• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How add static function to htm templates in JForum

 
Omar Komiha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

My name is Omar.

My knowledge about JForum is very minimal so forgive me if my question is very stupid or unrelated to JForum.

I want to add a token to an htm (template) page 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 that calling static functions is possible from htm templates, and since this is normally not possible from htm/html pages I assumed that this is a JForum feature.

What I did is add the following code to the htm page:



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.

It seems that I also need to configure something to complete this, however I have no clue how to do that ...

Any help would be appreciated.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. That's not so much a feature of JForum, but rather of the FreeMarker templating engine JForum uses. I don't think it allows you to call random static methods without some preparation; at least that's how I read http://freemarker.org/docs/pgui_misc_beanwrapper.html#autoid_55. A better way would be to call that method in the Java class, and then put its results into the HashMap that collects all template variables.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34072
333
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar,
Welcome to CodeRanch! As Ulf noted, those aren't really html files. They are Freemarker templates.

I wrote a blog series on how we fixed CSRF on our JForum install. It's not trivial.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic