Hi, Ian.

On 20/04/10 15:40, Ian Stevens wrote:
> Thanks Gustavo. The version of FriendlyForm I'm using, 1.0.4, does not 
> implement IAuthenticator. I get the following error:
>
>       ValueError: form: An object has failed to implement interface 
> <InterfaceClass repoze.who.interfaces.IAuthenticator>
>       The authenticate attribute was not provided.
>   

I'm sorry about that typo...

On 19/04/10 22:00, Gustavo Narea wrote:
> It sounds like you've not added the plugin to the authenticators in
> repoze.who.
>
> Make sure to add "form" to both the identifiers and challengers.
>   

... I meant to say "challengers" instead of "authenticators" in the
first paragraph.

> With form in only identifiers and challengers, the login counter does not 
> increment. Any ideas?
>
> Here are the relevant sections of my altered who.ini, with form in both 
> identifiers and challengers:
>
> [[ CONFIG HIDDEN ]]
>   

That looks good to me.

Have you made sure your login template is passing the counter over?
That'd be a good explanation for the behavior you're getting.

For example, this is what I have in a Genshi template:
>   <form action="${h.url_for('/login_handler', came_from=c.came_from,
> __logins=c.login_counter)}"
>         method="POST">
>     <label for="login">Username:</label><input type="text" id="login"
> name="login" /><br/>
>     <label for="password">Password:</label><input type="password"
> id="password" name="password" />
>     <input type="submit" value="Login" />
>   </form>

It'd generate a form whose action would look like
/login_handler?came_from=/admin/&__logins=3

That's critical for the login counter to work. It needs to receive the
counter, or it'll fallback to 0.

Just in case, these are the methods that handle pre-login, post-login
and logouts, respectively, in this project:

>     def login(self):
>         """Pre-login"""
>         login_counter = request.environ['repoze.who.logins']
>         if login_counter > 0:
>             notificator('Wrong credentials', status="error")
>         c.login_counter = unicode(login_counter)
>         c.came_from = request.params.get('came_from') or url_for('/')
>         return render('login.html')
>     
>     def welcome_back(self):
>         """Post-login"""
>         identity = request.environ.get('repoze.who.identity')
>         came_from = str(request.params.get('came_from', '')) or
> url_for('/')
>         if not identity:
>             login_counter = request.environ['repoze.who.logins'] + 1
>             redirect_to(url_for('/login', came_from=came_from,
>                                 __logins=login_counter))
>         userid = identity['repoze.who.userid']
>         notificator('Welcome back, %s!' % userid)
>         redirect_to(url_for(came_from))
>
>     def see_you_later(self):
>         """Post-logout"""
>         notificator('We hope to see you soon!')
>         came_from = str(request.params.get('came_from', '')) or
> url_for('/')
>         redirect_to(url_for(came_from))

You're not using post-login actions, so you can ignore the second method.

On the other hand, I've double checked the login action in your initial
email:
> def login(self):
>     identity = request.environ.get('repoze.who.identity')
>     if identity is not None:
>         came_from = request.params.get('came_from', None)
>         if came_from:
>             redirect_to(str(came_from))
>    
>     return render('/login.mako').encode('utf8')

That method wouldn't be called upon successful login, so there's nothing
to do with "came_from" just yet. In fact, you don't have to redirect to
"came_from" because FriendlyForm will do it for you because you're not
using a post-login action.

So, your login() should look like:
>     def login(self):
>         login_counter = request.environ['repoze.who.logins']
>         c.login_counter = unicode(login_counter)
>         c.came_from = request.params.get('came_from') or url_for('/')
>         return render('/login.mako').encode('utf8')

Sorry I didn't spot that earlier.

HTH.

-- 
Gustavo Narea <xri://=Gustavo>.

_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to