OK try this:
def invitation():
form = SQLFORM.factory(Field('email',requires=IS_EMAIL()))
if form.accepts(request):
db.invitation.insert(token = form.vars.email)
MESSAGE = 'click %s to register'
url = URL('user/register',host=request.env.http_host)
mail.send(to=form.vars.email, message=MESSAGE % url)
redirect('success_invitation'))
return dict(message=('Invitation to be sent'),
form=form,address=form.vars.email)
auth.settings.register_onvalidation.append(lambda form:
db.invitation(token=form.vars.email) or
form.errors.update({'email','not allowed'}))
auth.settings.register_onaccept.append(lambda form:
db(db.invitation.token==form.vars.email).delete())
On Jun 4, 9:28 am, Dwayne Blind <[email protected]> wrote:
> Can somebody please help me ? I would really want this to work.
>
> I customized db.auth_user, as described in the book, to add a 'token'
> field. I just added : Field('token', writable=False, readable=False,
> default='').
>
> Then, in the controllers, I modified default.py :
>
> def user():
> db.auth_user.insert(token=request.args(1))
> return dict(form=auth())
>
> Then in the models, I modified db.py :
>
> def my_auth_processing(form):
> if db(db.auth_user.token!='')
> (db.invitation.token==db.auth_user.token):
> return True
> else :
> return False
>
> auth.settings.register_onvalidation.append(lambda form:
> my_auth_processing(form))
>
> But unfortunately no one is prevented from registering... So this does
> not work.
>
> Dwayne
>
> On 2 juin, 02:31, pbreit <[email protected]> wrote:
>
>
>
>
>
>
>
> > Oops. For registration, you use
> > this:http://web2py.com/book/default/chapter/08?search=register_onvalidation