Announcement Announcement Module
Collapse
No announcement yet.
new user: missing the point with a login flow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • new user: missing the point with a login flow

    Hi ,

    I am a brand new user of webflow (long time spring user) i am trying to get my head around how to do a simple login process with webflow.

    The flow looks like

    1) Present form to user and collect user details
    2) validate form (user/pass != "")
    3) authenticator.login(user,pass) if this succeeds it returns a key which needs to be put in the session cookie/store - if the auth fails go back to (1) displaying a error message.

    I tried to take the phonebook example and make mods and ended up with this work flow.

    Code:
    	<start-state idref="enterLoginDetails" />
    
    	<view-state id="enterLoginDetails" view="enterLoginDetails">
    		<render-actions>
    			<action bean="loginFormAction" method="setupForm" />
    		</render-actions>
    
    		<transition on="login" to="showLoginResult">
    			<action bean="loginFormAction" method="bindAndValidate" />
    		</transition>
    	</view-state>
    	<view-state id="showLoginResult" view="showLoginResult"/>
    which works ok - the authenticator.login is done in the validate method of the formaction validator.

    But this doesnt seem right..i attempted to make the next state to be an action-state but couldnt get it (on failure) to pass any error messages back to the enterLoginDetails state.

    I am missing something here and i know its simple... can someone post and example or show me where i have missed the bus?


    Cheers
    Ross - getting frustrated by my ability to not quite get it!

  • #2
    You need an action state that invokes your authenticator. You can either invoke it directly using a bean-action or as part of an action method (for example, by extending the FormAction class). Since you need to likely handle an exceptional authentication situation by recording validation errors for exposing to your login form view, I would recommend the latter: Define an action method that invokes your Authenticator, catchs an AuthenticationException and adds error context then returns an error event...

    Keith
    Last edited by Keith Donald; May 4th, 2007, 03:58 PM.

    Comment


    • #3
      Just to clarify you would do ..
      <transition on="login" to="showLoginResult">
      <action bean="loginFormAction" method="bindAndValidate" />
      <action bean="loginAuthenticator" method="login" />
      </transition>


      and leave the flow much the same?

      Would i not want to use a <action-state>?

      And that all being said how do i now add a variable to the session context?

      Ross

      Comment


      • #4
        Code:
        <flow>
            <start-state idref="enterLoginDetails" />
        
            <view-state id="enterLoginDetails" view="enterLoginDetails">
                <render-actions>
                    <action bean="loginFormAction" method="setupForm" />
                </render-actions>
        
                <transition on="login" to="performLogin">
                    <action bean="loginFormAction" method="bindAndValidate" />
                </transition>
            </view-state>
        
            <action-state id="performLogin">
                <action bean="loginFormAction" method="performLogin"/>
                <transition on="success" to="showLoginResult"/>
                <transition on="error" to="enterLoginDetails"/>
            </action-state>
         
            <view-state id="showLoginResult" view="showLoginResult"/>
        
        </flow>
        Code:
        public class LoginFormAction extends FormAction {
            private Authenticator authenticator;
        
            public LoginFormAction(Authenticator authenticator) {
                this.authenticator = authenticator;
            }
        
            public Event performLogin(RequestContext context) {
                try {
                    Credentials credentials = (Credentials)getFormObject(context);            
                    authenticator.authenticate(credentials);
                    return success();
                } catch (InvalidCredentialsException e) {
                    getFormErrors(context).reject("invalid.credentials");
                    return error();
                }        
            }
        }
        Hopefully this gets the general idea/pattern across. The reference manual and FormAction JavaDoc API would be another good resource.

        Comment


        • #5
          thanks a lot!!!!

          the bit i was missing was
          getFormErrors(context).reject("invalid.credentials ");

          i couldnt get how to get the errors back into the scope to report on them in the flow.

          Thanks for the quick and helpful help

          Likeing webflow already!!!!

          Ross

          Comment

          Working...
          X