auth.py 1.92 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
""" authentication
3

4
    user identification and role
LE GAC Renaud's avatar
LE GAC Renaud committed
5

6 7 8 9 10 11 12 13 14 15
"""
from gluon.tools import Auth


#
# User logging
# Approval is required for newly registered users
#
auth = Auth(db, hmac_key=Auth.get_or_create_key())

16
auth.define_tables(migrate=MIGRATE_USER)
17 18 19 20 21 22 23
auth.settings.create_user_groups = False
auth.settings.mailer = None
auth.settings.registration_requires_approval = True
auth.settings.registration_requires_verification = False
auth.settings.remember_me_form = False
auth.settings.reset_password_requires_verification = True

LE GAC Renaud's avatar
LE GAC Renaud committed
24
# go to the login page after change password, logout and registration
25 26
auth.settings.change_password_next = URL('user', args='login')
auth.settings.logout_next = URL('user', args='login')
27 28 29 30 31 32 33 34 35 36 37 38 39 40
auth.settings.register_next = URL('user', args='login')

# create user and admin groups
if not db(db.auth_group.id).count():
    db.auth_group.insert(id=ID_ADMIN, role=ADMIN, description=T(DEF_ADMIN))
    db.auth_group.insert(id=ID_USER, role=USER, description=T(DEF_USER))

# Newly registered users go in the user group
auth.settings.everybody_group_id = ID_USER

# The first user is auto approved and get all privilege (admin)
if not db(db.auth_user.id).count():
    auth.settings.everybody_group_id = ID_ADMIN
    auth.settings.registration_requires_approval = False
LE GAC Renaud's avatar
LE GAC Renaud committed
41

42 43 44 45 46 47 48 49 50
# tune authentication fields for the extJS interface
db.auth_user.registration_key.readable = True
db.auth_user.registration_key.writable = True

db.auth_membership.user_id.label = 'User'
db.auth_membership.group_id.label = 'Group'

db.auth_membership.user_id.requires = \
IS_IN_DB(db, 'auth_user.last_name')
51 52 53 54 55

# HACK
# JSON conversion of datetime failed in the action plugin_dbui.dbui_conf
# Convert the date in advance help
# TODO: implement a proper datetime conversion when running json.dumps()
LE GAC Renaud's avatar
LE GAC Renaud committed
56
db.auth_event.time_stamp.default = db.auth_event.time_stamp.default.isoformat()
57 58
db.auth_cas.created_on.default = db.auth_cas.created_on.default.isoformat()