We just had a similar requirement for Liferay6.
A simplified way of detecting whether the user is logged in from within the web content and doing certain action without engaging Velocity Templates mechanism is below.
Stick the following javascript at the bottom of the web content article located on a page where you want to have this action.
This particular script will redirect the user to another page in 3 seconds if user is signed in.
1
2<script type="text/javascript">
3(function($) {
4 $(document).ready(function() {
5 if(document.cookie.indexOf("COMPANY_ID") != -1) { setTimeout("redirectToProject()", 3000); }
6 });
7})(jQuery);
8
9function redirectToProject()
10{
11document.location.href = "/group/integration-project";
12}
13</script>
It assumes that you have jQuery, modify script if you do not use it. Cookie such as COMPANY_ID is set by the portal for any signed in user.
Why 3 seconds delay? In case you want to modify the page while you are signed in. It will give enough time to click on X button to stop javascript running.
In case when in your version of portal COMPANY_ID cookie is not being set, you can use run-time detection of some content on the page, e.g. if Sign In portlet (portlet_58) displays the message "You are signed in as...";
1<script type="text/javascript">
2 $(document).ready(function() {
3window.alert('looking for signin portlet');
4var signinPortlet = document.getElementById("portlet_58");
5if(signinPortlet != null)
6{
7if(signinPortlet.innerHTML.indexOf("You are signed in as") > 0)
8{
9 setTimeout("redirectToProject()", 3000);
10}
11} else
12{
13window.alert('sign-in portlet not found');
14}
15});
16
17function redirectToProject()
18{
19window.alert("redirecting...");
20document.location.href = "/group/integration-project";
21}
22</script>
Firmi prego dentro per inbandierare questo come inadeguato.