2

How can I set page session on a specific Web-content Structure so if I assign any page with this specific Structure, it will check if the session is there or not and if not it will ask for password input. The user should then insert the password.

In the page structure I also want to add Next, Finish and Cancel buttons, so if I finish or cancel it will destroy the session. And if after this the user is trying to access the page, he will be again asked for the password.

I'm trying to do it from the Web-content template *.VM.

Following is the code I have made till now:

Structure code:

<?xml version="1.0"?>

<root>
    <dynamic-element name="classified" type="list" index-type="" repeatable="false">
        <dynamic-element name="Yes" type="1" index-type="" repeatable="false" />
        <dynamic-element name="No" type="0" index-type="" repeatable="false"/>
    </dynamic-element>
    <dynamic-element name="content" type="text_area" index-type="" repeatable="false"/>
</root>

Template code:

#if($classified.getData() == "1")
    #if($request.parameters.get('password') == "1234")
        <p>$content.getData()</p>
    #else
        <h2>This is the second authentication verification</h2>
        <p>Please enter your second password</p>

        #set ($url = $request.get('render-url'))

        <form action="$url" name="auth" method="POST">
            <label name="password">Password<span style="color:red">*</span></label>
            <input type="password" name="password" />
            <input type="submit" />
        </form>

        #if($request.parameters.get('password') != "1234")
            <p>Please enter correct password</p>
        #end
    #end
#else
    <h2>This is not a classified page</h2>
#end

How can I make this idea work.

Kara
  • 6,115
  • 16
  • 50
  • 57
Haider Ghaleb
  • 83
  • 2
  • 12

1 Answers1

0

In my opinion a better approach for this is to write a servlet that will check for the user session and that, if there is no session, will redirect automatically to a dedicated page with a login portlet. Authenticating the user really isn't the task of a Velocity script...

p.mesotten
  • 1,402
  • 1
  • 14
  • 26
  • Thank you, i would like to know how can i make a servlet as you mentioned, i think your approach makes sense. Can you help in this? – Haider Ghaleb Sep 07 '12 at 15:37