[Grok-dev] megrok.login

Mats mats at ronin-group.org
Mon May 23 15:34:32 EDT 2011


I'm trying to authenticate using megrok.login but it doesn't
authenticate my user.  It does authenticate using the session login
form against my admin username and password from the grok install.

I created a register form as so:

class Register(base.PageForm):
    grok.context(interface.Interface)

    fields = base.Fields(IRegister)
    ignoreContext = True

    @base.button.buttonAndHandler(u'Register')
    def handle_registration(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        username = data['username']
        password = data['password']

        auth = component.getUtility(IAuthentication)
        pf = auth['principals']
        pf[username] = InternalPrincipal(username, password, username)
        pm = IPrincipalPermissionManager(grok.getSite())
        pm.grantPermissionToPrincipal('iport.Registered', username)
        self.redirect('index')

My login form looks like this:

class Login(Page):
    def update(self, camefrom=None, SUBMIT=None):
        self.camefrom = camefrom
        if SUBMIT is not None and camefrom is not None:
            self.redirect(camefrom)
        return

The registration does seem to work correctly as it adds the principal
to site._sm['megrok_login_pau']['principals'] but authentication gives
me nothing but displaying the login form again and user staying as
'zope.anybody'.

What am I doing wrong?


Thanks,

Mats


More information about the Grok-dev mailing list