You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Allex Juang <al...@nyquest.com.tw> on 2008/12/10 08:31:29 UTC

Redirect before page render

Hi,

I have a Login page, and user will navigate to, say, Work page after 
success authenticate process.
But when an authenticated user access Login page, I wish to just 
redirect to Work page.
How can I do that?

Allex J.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect before page render

Posted by Otho <ta...@googlemail.com>.
If you use Spring Security you can also check against the SecurityContext.

Regards,
Otho

2008/12/11 Allex Juang <al...@nyquest.com.tw>

> Thanks Peter, It works.
>
> Allex J.
>
> Peter Stavrinides 提到:
>
>> Use an application state object (it is session scoped), so on your login
>> page you could have:
>>
>> @ApplicationState
>> private UserStateTracker stateTracker;
>>
>> @InjectPage
>> private Home homePage;
>>
>> Object onActivate(){
>>  if(stateTracker.isSignedIn()){
>>  //user is already signed in so redirect
>>  return homePage;
>>  }
>> }
>>
>>
>> If you need something slightly more complex (i.e.:filtering per request)
>> then you need to implement a request filter and do the checking there:
>>
>> public class PageAccessController implements RequestFilter {
>>
>>      public PageAccessController(ApplicationStateManager asm) {
>>                asm_ = asm;
>>      }
>>
>>      public boolean service(Request request, Response response,
>>                        RequestHandler handler) throws IOException {
>>             UserStateTracker stateTracker =
>> asm_.get(UserStateTracker.class);
>>
>>       if(!stateTracker.isSignedIn())
>>           //user is not signed in so redirect him to the login page
>>
>>      }
>>
>>
>> }
>>
>> You also will need a contribution in your AppModule:
>> public static void contributeRequestHandler(
>>                        OrderedConfiguration<RequestFilter> configuration,
>>                        @InjectService("TimingFilter") RequestFilter
>> filter,                        @InjectService("PageAccessController")
>> RequestFilter pageAccessController) {
>>                configuration.add("Timing", filter);
>>                configuration.add("PageAccessController",
>> pageAccessController,
>>                                "before:PageRender");
>>        }
>>
>> cheers,
>> Peter
>>
>> ----- Original Message -----
>> From: "Allex Juang" <al...@nyquest.com.tw>
>> To: "Tapestry users" <us...@tapestry.apache.org>
>> Sent: Wednesday, 10 December, 2008 9:31:29 AM GMT +02:00 Athens, Beirut,
>> Bucharest, Istanbul
>> Subject: Redirect before page render
>>
>> Hi,
>>
>> I have a Login page, and user will navigate to, say, Work page after
>> success authenticate process.
>> But when an authenticated user access Login page, I wish to just redirect
>> to Work page.
>> How can I do that?
>>
>> Allex J.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>> __________ NOD32 3680 (20081210) Information __________
>>
>> This message was checked by NOD32 antivirus system.
>> http://www.eset.com
>>
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Redirect before page render

Posted by Allex Juang <al...@nyquest.com.tw>.
Thanks Peter, It works.

Allex J.

Peter Stavrinides 提到:
> Use an application state object (it is session scoped), so on your login page you could have:
>
> @ApplicationState
> private UserStateTracker stateTracker;
>
> @InjectPage
> private Home homePage;
>
> Object onActivate(){
>  if(stateTracker.isSignedIn()){
>   //user is already signed in so redirect
>   return homePage;
>  }
> }
>
>
> If you need something slightly more complex (i.e.:filtering per request) then you need to implement a request filter and do the checking there:
>
> public class PageAccessController implements RequestFilter {
>
>       public PageAccessController(ApplicationStateManager asm) {
> 		asm_ = asm;
>       }
>
>       public boolean service(Request request, Response response,
> 			RequestHandler handler) throws IOException {
>        
>        UserStateTracker stateTracker = asm_.get(UserStateTracker.class);
>
>        if(!stateTracker.isSignedIn())
>            //user is not signed in so redirect him to the login page
>
>       }
>
>
> }
>
> You also will need a contribution in your AppModule:
> public static void contributeRequestHandler(
> 			OrderedConfiguration<RequestFilter> configuration,
> 			@InjectService("TimingFilter") RequestFilter filter, 
> 			@InjectService("PageAccessController") RequestFilter pageAccessController) {
> 		configuration.add("Timing", filter);
> 		configuration.add("PageAccessController", pageAccessController,
> 				"before:PageRender");
> 	}
>
> cheers,
> Peter
>
> ----- Original Message -----
> From: "Allex Juang" <al...@nyquest.com.tw>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Wednesday, 10 December, 2008 9:31:29 AM GMT +02:00 Athens, Beirut, Bucharest, Istanbul
> Subject: Redirect before page render
>
> Hi,
>
> I have a Login page, and user will navigate to, say, Work page after 
> success authenticate process.
> But when an authenticated user access Login page, I wish to just 
> redirect to Work page.
> How can I do that?
>
> Allex J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> __________ NOD32 3680 (20081210) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect before page render

Posted by Peter Stavrinides <P....@albourne.com>.
Use an application state object (it is session scoped), so on your login page you could have:

@ApplicationState
private UserStateTracker stateTracker;

@InjectPage
private Home homePage;

Object onActivate(){
 if(stateTracker.isSignedIn()){
  //user is already signed in so redirect
  return homePage;
 }
}


If you need something slightly more complex (i.e.:filtering per request) then you need to implement a request filter and do the checking there:

public class PageAccessController implements RequestFilter {

      public PageAccessController(ApplicationStateManager asm) {
		asm_ = asm;
      }

      public boolean service(Request request, Response response,
			RequestHandler handler) throws IOException {
       
       UserStateTracker stateTracker = asm_.get(UserStateTracker.class);

       if(!stateTracker.isSignedIn())
           //user is not signed in so redirect him to the login page

      }


}

You also will need a contribution in your AppModule:
public static void contributeRequestHandler(
			OrderedConfiguration<RequestFilter> configuration,
			@InjectService("TimingFilter") RequestFilter filter, 
			@InjectService("PageAccessController") RequestFilter pageAccessController) {
		configuration.add("Timing", filter);
		configuration.add("PageAccessController", pageAccessController,
				"before:PageRender");
	}

cheers,
Peter

----- Original Message -----
From: "Allex Juang" <al...@nyquest.com.tw>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Wednesday, 10 December, 2008 9:31:29 AM GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Redirect before page render

Hi,

I have a Login page, and user will navigate to, say, Work page after 
success authenticate process.
But when an authenticated user access Login page, I wish to just 
redirect to Work page.
How can I do that?

Allex J.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org