Hi Anthony,

Thanks for looking into this.

The model code I am using is as follows:


## use PostgreSQL on localhost

db = DAL("postgres://cyan:123456@localhost:5432/mydb")

#####################################
## web2py authentication utilities ##
#####################################
from gluon.tools import Auth
auth = Auth(db, hmac_key=Auth.get_or_create_key())

## configure email
mail = auth.settings.mailer
mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = 'login.n...@gmail.com'
mail.settings.login = 'login.name:123456'

## for the use of reCAPTCHA (with publicly visible site only)
#auth.settings.captcha = Recaptcha(request, 'PUBLIC_KEY', 'PRIVATE_KEY', 
option="theme:'clean', lang:'en'")

## re-name the authentication tables
auth.settings.table_user_name = "user_login"
auth.settings.table_group_name = "user_group"
auth.settings.table_membership_name = "user_membership"
auth.settings.table_permission_name = "user_permission"
auth.settings.table_event_name = "user_event"

## disable the default group creation behavior upon each user creation
auth.settings.create_user_groups = False

## turn on email verification upon registration and pwd reset
auth.settings.registration_requires_verification = True
auth.settings.reset_password_requires_verification = True
auth.settings.registration_requires_approval = False

## set the content of the verification email
auth.messages.verify_email = 'Please click on the link: http://' + \
request.env.http_host + \ URL(r=request,c='account',f='verify_email') + \
'/%(key)s to verify your email address'

## create all tables needed by Auth
auth.define_tables()

## customize the Auth tables
## abandon (but not remove) 'first_name' and 'last_name' from user_login 
table
db.user_login.first_name.writable = db.user_login.last_name.writable = False
db.user_login.first_name.readable = db.user_login.last_name.readable = False

## set the email requirement
db.user_login.email.requires = [IS_NOT_EMPTY(), IS_EMAIL(forced='^.*\.edu
(|\..*)$', error_message='Email must be .edu address'),IS_NOT_IN_DB(db, 
'user_login.email')]

## set the password requirement
db.user_login.password.requires = [IS_NOT_EMPTY(), IS_STRONG(min=7, special=
0, upper=0, number=0, error_message='Minimum 7 characters'), CRYPT()]

## setup the user group structure
auth.add_group('students', 'students')
auth.add_group('teachers', 'teachers')


######################
## Custom DB tables ##
######################
db.define_table('student', Field('login_id', db.user_login, 
readable=False,writable
=False), Field('first_name', length=128, required=True), 
Field('last_name',length
=128, required=True), Field('sex', required=True), Field('dob', 'date'), 
Field('country'), format='%(first_name)s %(last_name)s')

db.participant.sex.requires = IS_IN_SET(['male','female'])
db.participant.country.requires = IS_IN_SET(['United States','United 
Kingdom'])
db.participant.login_id.requires = IS_IN_DB(db, db.user_login.id, 
'%(email)s')


You may comment out the line: auth.settings.create_user_groups = False if 
you're getting the table-not-exist error and that should fix it.

As you can see above, I also setup the email account credentials (though 
dummy ones in the code above) in the model, and have tested those 
credentials against actual Gmail login. I have not explicitly tested it 
using Web2py, but expect them to work given the description in the manual. 
Thanks!

On Monday, April 16, 2012 6:39:43 PM UTC-4, Anthony wrote:
>
> 1. when I set *auth.settings.create_user_groups = False*, I suspect that 
>> 'auth_group' table is not created at all after calling 
>> 'auth.define_tables()'. Because if I do a 'auth.add_group(...)' after 
>> 'auth.define_tables()' in a model file, web2py will throw error saying that 
>> 'auth_group' table does not exist when trying to do the insert. However, if 
>> I leave *auth.settings.create_user_groups = True *(by default),  no such 
>> error is thrown. If this is the case, I wonder why. Surely, I would still 
>> want the table 'auth_group' created even if I don't want a new group 
>> created for each new user.
>>
>
> I can't reproduce this problem with a fresh app using SQLite. Can you show 
> the exact code you're using?
>  
>
>>
>> 2. according to the manual, if we set 
>> *auth.settings.registration_requires_verification 
>> = True*, then an email will be sent to the user when she registers. I 
>> set it True, but nothing is sent after a user is registered.
>>
>
> Have you configured the mailer with your mail account credentials and 
> confirmed that it works?
>
> Anthony
>
>>

Reply via email to