settings.py.template 4.34 KB
Newer Older
1
# Create a new file 'settings.py' and copy these contents into that file
2
3
import secret
import os
4

5
AUTH_MODE = "CAS"
6

7
8
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

9
10
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
11
12
13
DEBUG = False
TEMPLATE_DEBUG = DEBUG

14
ADMINS = ()
15
16
17
18
19
20
21
22
23
24
25
26
27
MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': secret.DB_NAME,
        'USER': secret.DB_USER,
        'PASSWORD': secret.DB_PASSWORD,
        'HOST': secret.DB_HOST,
        'PORT': '',
    }
}

28
29
# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
30
31
32
33
34
35
36
37
38
39
40
ALLOWED_HOSTS = ['127.0.0.1']


TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True

MEDIA_URL = '/media/'
41
MEDIA_ROOT = ''
42
MEDIAFILES_DIRS = (
43
  (os.path.join(BASE_DIR, 'media/'),
44
45
46
)

STATIC_URL = '/static/'
47
STATIC_ROOT = ''
48
STATICFILES_DIRS = (
49
  os.path.join(BASE_DIR, 'static/'),
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

SECRET_KEY = secret.SECRET_KEY

TEMPLATE_LOADERS = (
    'django.template.loaders.app_directories.Loader',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.contrib.auth.context_processors.auth',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
74
    'cas.middleware.CASMiddleware',
75
76
77
78
79
80
81
82
83
84
85
86
87
)

ROOT_URLCONF = 'settings.urls'

WSGI_APPLICATION = 'settings.wsgi.application'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
88
    # 'django.contrib.comments',
89
90
91
92
    'go',
    'piwik',
    'django.contrib.admin',
    'qrcode',
93
    'captcha',
94
    'cas',
95
96
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}


LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
)


135
136
if AUTH_MODE.lower() == 'ldap':
    import ldap
137

138
139
140
    AUTHENTICATION_BACKENDS += (
        'django_auth_ldap.backend.LDAPBackend',
    )
141

142
143
144
145
146
    AUTH_LDAP_SERVER_URI = "ldaps://directory.gmu.edu:636"  # server url
    AUTH_LDAP_BIND_DN = "ou=people,o=gmu.edu"               # bind DN
    AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True            # use the user
    AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=people,o=gmu.edu"
    AUTH_LDAP_GLOBAL_OPTIONS = {                            # ignore UAC cert.
147
148
        ldap.OPT_X_TLS: ldap.OPT_X_TLS_DEMAND,
        ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER,
149
150
151
152
153
154
155
    }
    AUTH_LDAP_USER_ATTR_MAP = {
        "first_name": "givenName",
        "last_name": "sn",
        "email": "mail"
    }
    AUTH_LDAP_ALWAYS_UPDATE_USER = True
156

157
158
159
160
elif AUTH_MODE.lower() == 'cas':
    CAS_SERVER_URL = "https://login.gmu.edu"
    CAS_LOGOUT_COMPLETELY = True
    CAS_PROVIDE_URL_TO_LOGOUT = True
161

162
163
164
    AUTHENTICATION_BACKENDS += (
        'cas.backends.CASBackend',
    )
165

166
167
168
    CAS_RESPONSE_CALLBACKS = (
        'go.cas_callbacks.create_user',
    )
169
170
171

PIWIK_SITE_ID = secret.PIWIK_SITE_ID
PIWIK_URL = secret.PIWIK_URL
172
173
174
175
176
177
178
179
180


# Mail settings
EMAIL_HOST = secret.EMAIL_HOST
EMAIL_PORT = secret.EMAIL_PORT
EMAIL_HOST_USER = secret.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = secret.EMAIL_HOST_PASSWORD
EMAIL_FROM = "example@example.com"
EMAIL_TO = "to@example.com"