My model file :

db.define_table('image',
   Field('title'),
   Field('file', 'upload'),
   Field('description', 'text'),
   Field('date', 'datetime', default=request.now),
   Field('user', db.auth_user, default=auth.user_id),
   Field('rating', default=0))

db.define_table('comment',
   Field('image_id', db.image),
   Field('user', db.auth_user, default=auth.user_id),
   Field('body', 'text'))

db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.image.file.requires = IS_NOT_EMPTY()
db.image.description.requires = IS_NOT_EMPTY()
db.image.file.requires = IS_NOT_EMPTY()
db.image.date.writable = db.image.date.readable = False

db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
db.comment.user.writable = db.comment.user.readable = False
db.comment.body.requires = IS_NOT_EMPTY()

db.comment.image_id.writable = db.comment.image_id.readable = False

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


mail=Mail()
## specify your SMTP server
mail.settings.server = 'smtp.gmail.com:25'
## specify your email address
mail.settings.sender = 'dri***@gmail.com'
## optional: specify the username and password for SMTP
mail.settings.login = 'dri***:***'

## optional: require email verification for registration
auth.settings.mailer = mail
## optional: if you require captcha verification for registration
# auth.settings.captcha =
Recaptcha(request,public_key='RECAPTCHA_PUBLIC_KEY',private_key='RECAPTCHA_PRIVATE_KEY')


db.define_table(
    auth.settings.table_user_name,
    Field('first_name', length=128, default=''),
    Field('last_name', length=128, default=''),
    Field('username', length=128, default=''),
    Field('email', length=128, default='', unique=True),
    Field('password', 'password', length=512,
          readable=False, label='Password'),
    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=''))

custom_auth_table = db[auth.settings.table_user_name] # get the
custom_auth_table
custom_auth_table.first_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
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.username.requires = IS_NOT_IN_DB(db,
custom_auth_table.username)

auth.settings.table_user = custom_auth_table # tell auth to use
custom_auth_table


auth.define_tables()


On Jun 13, 4:39 pm, pbreit <[email protected]> wrote:
> I guess that means you are not using authentication. How did you set up your
> application in the first place? Can you delete it and start over with a "New
> simple application"?
>
> If you don't want to start over, make sure you have these lines in a model
> file.
>
> from gluon.tools import Mail, Auth
> mail = Mail()                                  # mailer
> auth = Auth(db)                                #
> authentication/authorization
>
> mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
> mail.settings.sender = '[email protected]'         # your email
> mail.settings.login = 'username:password'      # your credentials or None
>
> auth.settings.hmac_key = '<your secret key>'   # before define_tables()
> auth.define_tables()                           # creates all needed tables
> auth.settings.mailer = mail                    # for user email verification

Reply via email to