Commit 73c3efb1 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch 'ExpandSignUp'

Conflicts:
	go/go/forms.py
parents bb8ea5a8 89d4c392
......@@ -7,7 +7,7 @@ class URLAdmin(admin.ModelAdmin):
class RegisteredUserAdmin(admin.ModelAdmin):
list_display = ("username", "full_name", "approved")
list_display = ("username", "full_name", "organization", "approved")
admin.site.register(URL, URLAdmin)
admin.site.register(RegisteredUser, RegisteredUserAdmin)
from django import forms
from go.models import URL, RegisteredUser
from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Submit, HTML, Div, Field
from crispy_forms.bootstrap import StrictButton, PrependedText, Accordion, AccordionGroup
......@@ -146,7 +147,7 @@ class SignupForm(forms.ModelForm):
username = forms.CharField(
required=True,
label='Mason NetID',
label='Mason NetID (Required)',
max_length=30,
validators=[validate_username],
widget=forms.TextInput(attrs={
......@@ -154,11 +155,18 @@ class SignupForm(forms.ModelForm):
)
full_name = forms.CharField(
required=True,
label='Full Name',
label='Full Name (Required)',
max_length=100,
widget=forms.TextInput(attrs={
}),
)
organization = forms.CharField(
required=True,
label='Organization (Required)',
max_length=100,
widget=forms.TextInput(attrs={
})
)
description = forms.CharField(
required=False,
label='Description (Optional)',
......@@ -166,6 +174,28 @@ class SignupForm(forms.ModelForm):
widget=forms.Textarea(attrs={
}),
)
tos_box = forms.BooleanField(
required=True,
# Need to add a Terms of Service Page and replace the href below
label = mark_safe('Do you accept the <a href="#" target="_blank">Terms of Service</a>?'),
)
def clean_username(self):
# Prevent hax: (non-staff) Users cannot signup for other users
cleaned_data = super(SignupForm, self).clean()
data_username = cleaned_data.get("username")
if not self.request.user.is_staff:
if self.request.user.username not in data_username:
self.add_error('username', "This is not your NetID!")
return data_username
def __init__(self, request, *args, **kwargs):
# Necessary to call request in forms.py, is otherwise restricted to views.py and models.py
self.request = request
super(SignupForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(form=self)
self.helper.form_method = 'POST'
def clean_username(self):
# Prevent hax: (non-staff) Users cannot signup for other users
......@@ -182,6 +212,27 @@ class SignupForm(forms.ModelForm):
self.request = request
super(SignupForm, self).__init__(*args, **kwargs)
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-md-4'
self.helper.field_class = 'col-md-6'
self.helper.layout = Layout(
Fieldset(
'',
Div(
Div(
'username',
'full_name',
'organization',
'description',
'tos_box',
css_class='well',
),
StrictButton('Submit',css_class='btn btn-primary btn-md col-md-4', type='submit'),
css_class='col-md-6',
),
)
)
class Meta:
model = RegisteredUser
fields = '__all__'
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-03-15 21:23
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('go', '0003_auto_20160107_1418'),
]
operations = [
migrations.AddField(
model_name='registereduser',
name='organization',
field=models.CharField(default=datetime.datetime(2016, 3, 15, 21, 23, 13, 628051, tzinfo=utc), max_length=100),
preserve_default=False,
),
]
......@@ -68,6 +68,11 @@ class RegisteredUser(models.Model):
max_length=100,
)
organization = models.CharField(
blank=False,
max_length=100,
)
description = models.TextField(blank=True)
approved = models.BooleanField()
......
{% extends 'layouts/base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Go - Signup
Go - Apply
{% endblock %}
......@@ -11,119 +11,25 @@ Go - Signup
<div class="row">
<div class="col-md-12">
<h1><strong>Signup</strong></h1>
<h1><strong>Apply to Go</strong></h1>
</div>
</div>
</div>
<div class="row">
{% if not registered %}
<div class="col-md-12">
<p>
In order to succesfully provide this service, users must be manually
approved. This prevents misuse of the URL shortener. Please indicate below
if you are interested.
<br/><br/>
</p>
</div>
<div class="col-md-8">
<div class="well">
<form class="form-horizontal" method="post" action="{% url 'signup' %}">
{% csrf_token %}
<fieldset>
{% if form.non_field_errors %}
<div class="form-group has-error">
<div class="col-md-12">
{% for error in form.non_field_errors %}
<span class="help-block">{{ error }}</p>
{% endfor %}
</div>
</div>
{% endif %}
{% if form.username.errors %}
<div class="form-group has-error">
{% else %}
<div class="form-group">
{% endif %}
<div class="col-md-4">
<label class="control-label" for="{{ form.username.id_for_label }}">
{{ form.username.label }}</label>
</div>
<div class="col-md-8">
{{ form.username }}
{% for error in form.username.errors %}
<span class="help-block">{{error}}</span>
{% endfor %}
</div>
</div>
{% if form.full_name.errors %}
<div class="form-group has-error">
{% else %}
<div class="form-group">
{% endif %}
<div class="col-md-4">
<label class="control-label" for="{{ form.full_name.id_for_label }}">
{{ form.full_name.label }}</label>
</div>
<div class="col-md-8">
{{ form.full_name }}
{% for error in form.full_name.errors %}
<span class="help-block">{{error}}</span>
{% endfor %}
</div>
</div>
{% if form.description.errors %}
<div class="form-group has-error">
{% else %}
<div class="form-group">
{% endif %}
<div class="col-md-4">
<label class="control-label" for="{{ form.description.id_for_label }}">
{{ form.description.label }}</label>
</div>
<p>
In order to prevent abuse of the URL Shortner, users must be manually approved.
<br></br>
You will need to list the organization you represent and, while optional, we would like
<br />
to know why you would like to use Go and
some examples where you would use this service.
<br></br>
Please indicate below if you are interested.
</p>
<br />
<legend></legend>
{% crispy form %}
<div class="col-md-8">
{{ form.description }}
{% for error in form.description.errors %}
<span class="help-block">{{error}}</span>
{% endfor %}
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="submit" value="Submit"
class="btn btn-primary btn-lg btn-block" />
</div>
</div>
</fieldset>
</form>
</div>
</div>
{% else %}
{% if not approved %}
<div class="col-md-12">
<p>You have already submitted a request for approval to use Go.</p>
</div>
{% else %}
<div class="col-md-12">
<p>You are already approved to use Go.</p>
</div>
{% endif %}
{% endif %}
</div>
{% endblock %}
......@@ -247,7 +247,8 @@ def signup(request):
username = signup_form.cleaned_data.get('username')
full_name = signup_form.cleaned_data.get('full_name')
description = signup_form.cleaned_data.get('description')
organization = signup_form.cleaned_data.get('organization')
# Only send mail if we've defined the mailserver
if settings.EMAIL_HOST and settings.EMAIL_PORT:
# TODO rewrite see #14
......
# Create a new file 'secret.py' and copy these contents into that file
# Please be sure to keep these variables secret in production
# You can generate a secret key from the following link: http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = ""
# Use the values from the database configuration
DB_NAME = ""
DB_USER = ""
# Remember to use a strong password in production
DB_PASSWORD = ""
# Often left blank
DB_HOST = ""
# Set piwik server site id (piwik can track multiple websites)
PIWIK_SITE_ID = ""
# Point to the piwik url
PIWIK_URL = ""
# Email configuration, if necessary
EMAIL_HOST = ""
EMAIL_PORT = ""
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
# Create a new file 'settings.py' and copy these contents into that file
import secret
import os
AUTH_MODE = "CAS"
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = False
ADMINS = ()
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': '',
}
}
# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
ALLOWED_HOSTS = ['127.0.0.1']
# Peoplefinder API
PF_URL = "http://api.srct.gmu.edu/pf/v1/"
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_URL = '/media/'
MEDIA_ROOT = ''
MEDIAFILES_DIRS = (
os.path.join(BASE_DIR, 'media/'),
)
STATIC_URL = '/static/'
STATIC_ROOT = ''
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
SECRET_KEY = secret.SECRET_KEY
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.request'
],
'loaders': [
'django.template.loaders.app_directories.Loader'
],
'debug': DEBUG
}
}
]
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',
)
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',
# 'django.contrib.comments',
'go',
'piwik',
'django.contrib.admin',
'qrcode',
'crispy_forms',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
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',
)
if AUTH_MODE.lower() == 'ldap':
import ldap
AUTHENTICATION_BACKENDS += (
'django_auth_ldap.backend.LDAPBackend',
)
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.
ldap.OPT_X_TLS: ldap.OPT_X_TLS_DEMAND,
ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER,
}
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
elif AUTH_MODE.lower() == 'cas':
CAS_SERVER_URL = "https://login.gmu.edu"
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (
'cas.backends.CASBackend',
)
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
INSTALLED_APPS += (
'cas',
)
MIDDLEWARE_CLASSES += (
'cas.middleware.CASMiddleware',
)
PIWIK_SITE_ID = secret.PIWIK_SITE_ID
PIWIK_URL = secret.PIWIK_URL
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# 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"
......@@ -23,3 +23,6 @@ body {
vertical-align: middle;
line-height: normal;
}
.asteriskField {
display: none;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment