I am a 100% new user for tapestry. Currently I'm working on 5.0.5, but I got
stuck from the just beginning.

I want to implement a kind of user access controller. All the pages, excepts
for the login page, can be accessed by authenticated users only. users who
hasn't passed the authentication will be redirected to the login page to
input their user name and password, and then, if the user name and password
are correct, they will see the page they want

I think this is a very very simple thing to do.But after a few days working,
I am very frustrated.

Firstly, I've tried the onActivate method. My code looks like below:

class BasePage {
    @ApplicationState
     private UserIdentity _userIdentity;
     private boolean _userIdentityExists;

    Object onActivate() {
      
         if( !_userIdentityExists)
             return "Login"; //Login is my login page

         return null;
    }
}

And the I visited http://localhost:8080/myapp(default page is start), I got
a blank empty page. There is nothing at all on the browser. But I can see
the login page when I went to http://localhost:8080/myapp/login

After that I saw an article at
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher. According
to this, I created my dispatcher. But I found ASO doesn't work in my
dispatcher class.
And if I contribute it use "before:PageRender", the dispatch method would
not be invoked then I visit the default start page. I had to use
"before:RootPath". Following it my dispatcher class code:

public class SessionController implements Dispatcher {

        @ApplicationState
        private MyIdentity _myIdentity;
        private boolean _myIdentityExists;
        
        public SessionController() {
                System.out.println("SessionController: SessionController 
created.");
        }

        public boolean dispatch(Request request, Response response) throws
IOException {
                System.out.println("Requesting " + request.getPath());

                if (! _myIdentityExists ) {
                        if( _myIdentity == null ) {
//                              _myIdentity = new MyIdentity();
                                System.out.println("SessionController: Identity 
does not exist.");
                               //return true;
                        }else
                                System.out.println("SessionController: Identity 
exists.");
                }
                
                return false;
        }
}

and here is the code in AppModule:
    public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher>
configuration,
                @InjectService("SessionController") Dispatcher
sessionController) {
                configuration.add("SessionController", sessionController,
"before:PageRender");
        }


before:PageRender doesn't call dispatch method, before:RootPath or
before:Asset does
-- 
View this message in context: 
http://www.nabble.com/T5-how-to-control-login-state-tf4744201.html#a13566324
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to