<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt">On Mon, 23 May 2011 12:34:32 -0700 Mats <<a ymailto="mailto:mats@ronin-group.org" href="mailto:mats@ronin-group.org">mats@ronin-group.org</a>> wrote:<br><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br><div style="margin-left: 40px;">I'm trying to authenticate using megrok.login but it doesn't<br>authenticate my user. It does authenticate using the session login<br>form against my admin username and password from the grok install.<br><br>I created a register form as so:<br><br>class Register(base.PageForm):<br> grok.context(interface.Interface)<br><br> fields = base.Fields(IRegister)<br> ignoreContext = True<br><br>
@base.button.buttonAndHandler(u'Register')<br> def handle_registration(self, action):<br> data, errors = self.extractData()<br> if errors:<br> self.status = self.formErrorsMessage<br> return<br> username = data['username']<br> password = data['password']<br><br> auth = component.getUtility(IAuthentication)<br> pf = auth['principals']<br> pf[username] = InternalPrincipal(username, password, username)<br> pm = IPrincipalPermissionManager(grok.getSite())<br> pm.grantPermissionToPrincipal('iport.Registered', username)<br> self.redirect('index')<br><br>My login form looks like this:<br><br>class
Login(Page):<br> def update(self, camefrom=None, SUBMIT=None):<br> self.camefrom = camefrom<br> if SUBMIT is not None and camefrom is not None:<br> self.redirect(camefrom)<br> return<br><br>The registration does seem to work correctly as it adds the principal<br>to site._sm['megrok_login_pau']['principals'] but authentication gives<br>me nothing but displaying the login form again and user staying as<br>'zope.anybody'.<br><br>What am I doing wrong?<br><br><br>Thanks,<br><br>Mats<br></div><br>The magic of the megrok.login authentication is performed by the code in loginform.py ( check the LoginForm class' __call__ method).<br>In my code I dropped the self.index() in the last line and used a grok.View.__call__(self) instead (you should use Page.__call__).<br><br>class Login(grok.View):<br>
<br> grok.context(Interface)<br> grok.require('zope.Public')<br> <br> def __call__(self):<br> request = self.request<br> principal = request.principal<br><br> unauthenticated = IUnauthenticatedPrincipal.providedBy(principal)<br> self.unauthenticated = unauthenticated<br> <br> camefrom = request.get('camefrom')<br> if isinstance(camefrom, list):<br> # this can happen on python2.6, as it changed the<br> # behaviour of cgi.FieldStorage a
bit.<br> camefrom = camefrom[0]<br> self.camefrom = camefrom<br> <br> if (not unauthenticated) and ('SUBMIT' in request):<br> # authenticated by submitting<br> request.response.redirect(camefrom or '.')<br> return ''<br> <br> return grok.View.__call__(self)<br> <br> def update(self, camefrom=None, SUBMIT=None):<br> self.camefrom = camefrom<br> if
SUBMIT is not None and camefrom is not None:<br> # The credentials were entered. Go back. If the entered<br> # credentials are not valid, another redirect will happen<br> # to this view.<br> self.redirect(camefrom)<br> self.baseurl = self.url(self.context)<br> return<br></div></div>
</div></body></html>