-
-
Save fndiaz/5984106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
######################################################################### | |
## Database initialization | |
######################################################################### | |
from images import THUMB #use PIL to create the photo thumb | |
from widgets import Radio, Upload, Checkbox | |
from customvalidators import IS_EMPTY_OR_MASK_OR | |
auth.settings.hmac_key = G.auth.security_key # before define_tables() | |
#auth table | |
# Custom Auth table definition | |
db.define_table(auth.settings.table_user_name, | |
Field('name', | |
requires=IS_NOT_EMPTY(error_message=auth.messages.is_empty), | |
length=128, | |
default='', | |
comment=T('Your full name'), | |
label=T('Your name')), | |
Field('email', | |
length=128, | |
default='', | |
unique=True, | |
comment=T('Your email address (used for login)'), | |
label=T('Email')), | |
Field('profilename', | |
length=128, | |
default='', #unique=True, | |
comment=T('This will be used as your unique url i.e: ansy.me/profilename'), | |
label=T('Profile username')), | |
Field('gender', | |
length=2, | |
requires=IS_EMPTY_OR(IS_IN_SET(['F','M'])), | |
comment=T('Your gender (optional)'), | |
label=T('Gender')), | |
Field('phone', | |
length=64, | |
default='', | |
comment=T('Your prefered telephone number (optional)'), | |
label=T('Phone')), | |
Field('homepage', | |
requires=IS_EMPTY_OR(IS_URL()), | |
comment=T('Have a site, a blog, a photo gallery?'), | |
label=T('website ou blog') ), | |
Field('bio', | |
'text', | |
default='', | |
label=T('About you'), | |
comment=T('Tell us something about you (short please!)') ), | |
Field('twitter', | |
comment=T('Your twitter username i.e: @animalsystem')), | |
Field('facebook', | |
comment=T('Your facebook url or username')), | |
Field('photo_source', | |
'integer', | |
requires=IS_EMPTY_OR(IS_IN_SET(G.auth.photo_sources)), | |
comment=T('Where we can take your profile picture from?'), | |
label=T('Photo source')), | |
Field('photo_url', | |
'string', | |
length=512, | |
readable=False,writable=False, | |
requires=IS_EMPTY_OR(IS_URL())), | |
Field('photo', | |
'upload', | |
widget = Upload.widget, | |
uploadfolder=request.folder+'static/uploads/userprofile', | |
requires=IS_EMPTY_OR(IS_IMAGE()), | |
label=T('Picture File'), | |
comment=T('Choose a file from your computer')), | |
Field('photo_thumb', | |
'upload', | |
writable=True, | |
readable = True, | |
compute=lambda r: THUMB(r['picture'])), | |
Field('password', | |
'password', | |
requires = [CRYPT(key=auth.settings.hmac_key)], | |
length=64, | |
readable=False, | |
comment=T('Your safe password'), | |
label=T('Password')), | |
Field('user_types', | |
'list:integer', | |
requires=IS_IN_SET(G.auth.user_types, multiple=True), | |
widget = Checkbox.widget, | |
default=[1], | |
label=T('Registration Type'), | |
comment=T('What is your relation with animals?')), | |
Field('birthdate', | |
'date', | |
label=T('Birthdate'), | |
comment=T('When did you came to this world?'), | |
requires=IS_EMPTY_OR_MASK_OR(IS_DATE(format=str(T('%Y-%m-%d')))) | |
), | |
Field('privacy', | |
'integer', | |
requires=IS_IN_SET(G.auth.privacy), | |
widget = Radio.widget, | |
default=1, | |
label=T('Privacy settings'), | |
comment=T('What do you want to share with friends?')), | |
Field('completed', | |
'boolean', | |
writable=False, | |
readable=False), | |
Field('confirmed', | |
'boolean', | |
writable=False, | |
readable=False), | |
Field('mailsent', | |
'boolean', | |
writable=False, | |
readable=False), | |
Field('registration_key', length=512, writable=False, readable=False, | |
default=''), | |
Field('reset_password_key', length=512, writable=False, readable=False, | |
default=''), | |
Field('registration_id', length=512, writable=False, readable=False, | |
default=''), | |
Field('record_created', 'datetime', default=request.now, writable=False, | |
readable=False), | |
Field('record_updated', 'datetime', default=request.now, | |
update=request.now, writable=False, readable=False), | |
migrate = G.db.migrate | |
) | |
custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table | |
custom_auth_table.email.requires = [ | |
IS_EMAIL(error_message=auth.messages.invalid_email), | |
IS_NOT_IN_DB(db, custom_auth_table.email)] | |
custom_auth_table.profilename.requires = IS_EMPTY_OR([ | |
IS_SLUG(error_message='invalid chars'), | |
IS_NOT_IN_DB(db, custom_auth_table.profilename, error_message=T('Already Taken'))]) | |
auth.settings.table_user = custom_auth_table | |
auth.define_tables(migrate = G.db.migrate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment