1 | # -*- coding: utf-8 -*- |
---|
2 | # this file is released under public domain and you can use without limitations |
---|
3 | |
---|
4 | if MULTI_USER_MODE: |
---|
5 | db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB |
---|
6 | from gluon.tools import * |
---|
7 | auth = Auth( |
---|
8 | globals(), db) # authentication/authorization |
---|
9 | crud = Crud( |
---|
10 | globals(), db) # for CRUD helpers using auth |
---|
11 | service = Service( |
---|
12 | globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc |
---|
13 | plugins = PluginManager() |
---|
14 | |
---|
15 | mail = auth.settings.mailer |
---|
16 | mail.settings.server = EMAIL_SERVER |
---|
17 | mail.settings.sender = EMAIL_SENDER |
---|
18 | mail.settings.login = EMAIL_LOGIN |
---|
19 | |
---|
20 | auth.settings.extra_fields['auth_user'] = \ |
---|
21 | [Field('is_manager', 'boolean', default=False, writable=False)] |
---|
22 | auth.define_tables() # creates all needed tables |
---|
23 | auth.settings.registration_requires_verification = False |
---|
24 | auth.settings.registration_requires_approval = True |
---|
25 | auth.settings.reset_password_requires_verification = True |
---|
26 | |
---|
27 | db.define_table('app', Field('name'), Field('owner', db.auth_user)) |
---|
28 | |
---|
29 | if not session.authorized and MULTI_USER_MODE: |
---|
30 | if auth.user and not request.function == 'user': |
---|
31 | session.authorized = True |
---|
32 | elif not request.function == 'user': |
---|
33 | redirect(URL('default', 'user/login')) |
---|
34 | |
---|
35 | |
---|
36 | def is_manager(): |
---|
37 | if not MULTI_USER_MODE: |
---|
38 | return True |
---|
39 | elif auth.user and (auth.user.id == 1 or auth.user.is_manager): |
---|
40 | return True |
---|
41 | else: |
---|
42 | return False |
---|