Proposal to automatically login after registering

8 views
Skip to first unread message

nemik

unread,
Jan 12, 2009, 4:16:04 PM1/12/09
to web2py Web Framework
So on many sites I see when you register via a simple registration
form that doesn't require email confirmation, then it just logs you in
automatically after registering. Which is nice and cool.

So I added a quick little thing to T2's register() function to do
this. Let me know if you guys like it or have any plans to merge
upstream. Or if i did it wrong!

So below is my new register function. key changes are after the '#auto
login' comment

def register
(self,verification=False,sender='',next='login',onaccept=None,auto_login=False):
"""
To use, create a controller:

def register(): return t2.register()
"""
request,response,session,cache,T,db=self._globals()
def onaccept2(form):
db.t2_membership.insert(person_id=form.vars.id,\
group_id=db.t2_group.insert(name=form.vars.name),\
status='approved')
if auto_login and not verification:
#auto login
session.t2.person_id=form.vars.id
session.t2.person_name=form.vars.name
session.t2.person_email=form.vars.email
session.flash=self.messages.logged_in

if form.vars.registration_key:
body=self.messages.register_email_body % dict
(form.vars)
if not self.email(sender=sender,to=form.vars.email,\

subject=self.messages.register_email_subject,
message=body):
self.redirect
(flash=self.messages.unable_to_send_email)
session.flash=self.messages.email_sent
if onaccept: onaccept(form)
vars={'registration_key': str(uuid.uuid4()) if verification
else ''}
return self.create(self.db.t2_person,vars=vars,\
onaccept=onaccept2,next=next)


Thanks,
Nemanja

mdipierro

unread,
Jan 12, 2009, 5:56:57 PM1/12/09
to web2py Web Framework
thank you. I will include it asap.

nemik

unread,
Jan 13, 2009, 10:15:57 AM1/13/09
to web2py Web Framework
Cool, thank you Massimo!
Reply all
Reply to author
Forward
0 new messages