Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Haider Ghaleb
Liferay set session on specific web content structure
September 7, 2012 2:47 AM
Answer

Haider Ghaleb

Rank: New Member

Posts: 10

Join Date: July 25, 2012

Recent Posts

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, if not it will appear password input, and user should insert the password.

In the page structure also i want to add next, finish and cancel buttons, so if i finish or cancel it will destroy the session and if a user is trying to access the page, he will be for the password.

I'm trying to do it from the web content template .VM

That's the code i 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>
<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 you 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.
Ray Augé
RE: Liferay set session on specific web content structure
September 7, 2012 8:00 AM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1171

Join Date: February 7, 2005

Recent Posts

You can't check to see if a the session is there for login, because in a Java web app, there is always a session, even when not authenticated.

However, if what you want is to identify if the client is authenticated, you only need to do:

1#if ($permissionChecker.isSignedIn())
2    .. do something cool
3#else
4    .. hey, you must sign in!
5#end


However, make sure to uncheck "Cacheable" for your template, otherwise it won't be request scoped execution.
Haider Ghaleb
RE: Liferay set session on specific web content structure
September 7, 2012 8:27 AM
Answer

Haider Ghaleb

Rank: New Member

Posts: 10

Join Date: July 25, 2012

Recent Posts

Thank you Ray. What i'm trying to do is

The user will have to sign in the system at first then he want to access this specific page let's say it's name is "Restricted", once he click on it, it will ask him to enter his second password, if the password is right and for now it's a constant value "1234". It will start a new session let's say "second_password" and this session can be manipulated in specific pages which only can read session "second_password". Inside the page, i want to have finish process, once i click on it, session "second_password" will be destroyed and if he tried to access "Restricted" page again he will be asked for the password.

I made with the velocity the asking for the password, by defining structure and template for the web content.



The code is up in the first message.

What do you think i should do? i would really appreciate if you can help me in this.