掲示板

velocity: how to redirect the user in login page when he is not logged in

7年前 に Nikos Samaras によって更新されました。

velocity: how to redirect the user in login page when he is not logged in

Junior Member 投稿: 29 参加年月日: 16/01/14 最新の投稿
Hello,

I have created my theme for my project. The goal is to redirect the user in login page if he/she is not logged in.

As I know in my theme I can draw the menu withouth providing functionality in it. So when the user clicks on it liferay goes directry to login page.

Here is my source code that draw the pages and set the urls ( href="$nav_child.getURL()") that opens when the user clicks on it.

<li class="$nav_child_css_class" id="layout_$nav_child.getLayoutId()" $nav_child_attr_selected role="presentation">
				<a aria-labelledby="layout_$nav_child.getLayoutId()" href="$nav_child.getURL()" $nav_child.gettarget() role="menuitem">$nav_child.getName()</a>
</li>


Thank you
Nikos
7年前 に Deependra Singh によって更新されました。

RE: velocity: how to redirect the user in login page when he is not logged

New Member 投稿: 19 参加年月日: 13/11/13 最新の投稿
Hi,

We can redirect the user If he is not logged in the system. Try to write this code navigation vm file in theme and test.
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
if(!Liferay.ThemeDisplay.isSignedIn()){
//redirect user to sign in page
window.onload=function(){window.location.href = 'sign in page';};
}
});
</script>


or Use the below code

#if(!$is_signed_in)

//redirect user to sign in page

#else

//do nothing
#end
7年前 に Nikos Samaras によって更新されました。

RE: velocity: how to redirect the user in login page when he is not logged

Junior Member 投稿: 29 参加年月日: 16/01/14 最新の投稿
Thank you for the answer .

To my understanding you propose that

#if(!$is_signed_in) 
		<li class="$nav_child_css_class" id="layout_$nav_child.getLayoutId()" $nav_child_attr_selected role="presentation">
				<a aria-labelledby="layout_$nav_child.getLayoutId()" href="$sign_in_url_theme" $nav_child.gettarget() role="menuitem">$nav_child.getName()</a>							
 </li>
#end


I think that it is not the best approach!!!

If the user copies the url of a page and paste it in the browser then he will have access to that page.
That source code works only in case that the user clicks on the menu.

Thank you
Nikos
7年前 に Deependra Singh によって更新されました。

RE: velocity: how to redirect the user in login page when he is not logged

New Member 投稿: 19 参加年月日: 13/11/13 最新の投稿
Hi,

I am suggesting the below approach.
We need to test the condition for user login and then as per our requirement we can write code in that condition.
In you portal_normal.vm file paste the below code and test. It should redirect the user on your login page if he is not logged in :

#if(!$is_signed_in)
<script>
window.location.href="you login Page";
</script>
#end
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: velocity: how to redirect the user in login page when he is not logged

Liferay Legend 投稿: 6400 参加年月日: 08/09/23 最新の投稿
Nikos Samaras:
If the user copies the url of a page and paste it in the browser then he will have access to that page.


If you want to protect content, don't mess around with frontend redirects. Rather use the proper permissions on the content as well as on the pages. If you try to access a page that you don't have access to, you'll be redirected to the login screen automatically. Private Pages by default are only accessible to members of the site they're in. Start there, rather than worrying about redirects.