session.flash after registration?

49 views
Skip to first unread message

JimK

unread,
Jan 10, 2010, 5:19:56 AM1/10/10
to web2py-users
I can't seem to figure out how to display a session.flash message on
the following page after a registration. I think the answer will have
something to do with auth.settings.register_onaccept but I'm not sure
how to pass the form object to this setting. Any help would be
appreciated.

Thanks,

Jim

Mengu

unread,
Jan 10, 2010, 8:55:05 AM1/10/10
to web2py-users
http://mdp.cti.depaul.edu/examples/default/tools

See the "Custom Authentication" section.

JimK

unread,
Jan 10, 2010, 8:57:56 PM1/10/10
to web2py-users
Hello Massimo,

First off, I'd like to tell you how much I love the web2py framework!
Thanks for the time and effort, it was well worth it!

Now to my issue:
I'm just not getting it. I added
auth.messages.registration_successful = 'some string' to my db.py
model but I'm not sure what it is that I need to do get the message to
display on my view after registering a new account. The example that
was given stated that 'Views are handled the usual web2py way' which I
assume to mean that I need to pass the text from the controller to the
view. But I'm a bit fuzzy on what the 'messages' objects actually
do. If there's some documentation on this, please point me to it. If
not, a brief explanation would be appreciated.

Thanks again,

Jim

mdipierro

unread,
Jan 10, 2010, 10:48:30 PM1/10/10
to web2py-users
Hi Jim,

thanks for your comments.

Assuming you are registering using the default user() action,
depending on your settings

auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False

web2py should display one of the following messages:

auth.messages.unable_send_email
auth.messages.email_sent
auth.messages.registration_pending
auth.messages.registration_successful

How does your auth.settings look like?

JimK

unread,
Jan 10, 2010, 11:45:54 PM1/10/10
to web2py-users
After registration, I'm redirected to the account page with a flash
message stating 'Logged In' instead of my 'Registration Successful' as
defined below. I can of course override the Logged In message by
adding a 'response.flash = auth.messages.registration_successful' but
then the user will always see that message when they navigate to my
account page. I'm sure there's something simple that I'm missing but
it keeps eluding me.

This is probably more detail than you need but it's easier to send it
all once than going back and forth over specific lines of code:

from gluon.tools import *
auth=Auth(globals(),db)

auth_table=db.define_table(
'person',
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True),
Field('password', 'password', length=128, readable=False,
label='Password'),
Field('registration_key', length=128, default= '', writable=False,
readable=False),
Field('company_name', length=128, default=''),
Field('account_name', length=30, default=''),
Field('accepts_eula', 'boolean'),
Field('offer_code', length=50, default=''),
Field('referral_code', length=50, default=''),
Field('server', length=10, default='web01'),
Field('htaccess', default='')
)

auth_table.first_name.requires=[
IS_NOT_EMPTY(error_message=auth.messages.is_empty),
IS_ALPHANUMERIC()]
auth_table.last_name.requires=[
IS_NOT_EMPTY(error_message=auth.messages.is_empty),
IS_ALPHANUMERIC()]
auth_table.password.requires=[IS_STRONG(),CRYPT()]
auth_table.email.requires=[
IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, auth_table.email)]
auth_table.account_name.requires=[
IS_NOT_EMPTY(error_message=auth.messages.is_empty),
IS_ALPHANUMERIC(),
IS_NOT_IN_DB(db, auth_table.account_name, error_message='That
account name is not available')]
auth_table.accepts_eula.requires=[
IS_NOT_EMPTY(error_message='You must accept the terms of use to
register'),
IS_MATCH('[on]', error_message='You must accept the terms of use to
register')]

auth.settings.table_user_name='person'
auth.settings.hmac_key='<some key>'

auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False

auth.settings.table_user=auth_table
auth.settings.register_next = URL(r=request, c='default', f='account')
auth.settings.logged_url = URL(r=request, c='default', f='account')
auth.settings.login_next = URL(r=request, c='default', f='account')
auth.settings.logout_next = URL(r=request, c='default', f='index')
auth.settings.retrieve_username_next = URL(r=request, c='default',
f='user', a='login')
auth.settings.retrieve_password_next = URL(r=request, c='default',
f='user', a='login')
auth.settings.change_password_next = URL(r=request, c='default',
f='account')

auth.messages.registration_successful = 'Registration successful'

auth.define_tables()

crud=Crud(globals(),db)
service=Service(globals())
# crud.settings.auth=auth

if auth.is_logged_in():
USERID = auth.user.id
else:
USERID = None


Also, I'm using Version 1.74.4 (2009-12-23 10:12:11).

mdipierro

unread,
Jan 11, 2010, 8:43:58 AM1/11/10
to web2py-users
The problem is that unless you have

auth.settings.registration_requires_verification = True

the user is automatically logged in after registration so the login
flash overrides the registration flash.
If you change the above setting, users will get the registration flash
"email sent" which is the one you probably you want to edit.

Massimo

JimK

unread,
Jan 11, 2010, 11:48:57 AM1/11/10
to web2py-users
That makes sense. I should have figured that out myself.

After I finish my project and verify that all of the parts are in
working order, I'll package a couple things up as modules or plugins
to share with the community. I'm working on a PayPal IPN verification
system with a way of handling PayPal subscription payments. I'm also
building a secure way of communicating from one web2py app to another
on different machines (e.g. app1 is the master that sends commands to
app2).

Thanks for the help!

Jim

Reply all
Reply to author
Forward
0 new messages