bring over forms and views form pycon for now
This commit is contained in:
parent
3ca56663a4
commit
d31953b544
2 changed files with 79 additions and 0 deletions
30
symposion/forms.py
Normal file
30
symposion/forms.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django import forms
|
||||
|
||||
import account.forms
|
||||
|
||||
|
||||
class SignupForm(account.forms.SignupForm):
|
||||
|
||||
first_name = forms.CharField()
|
||||
last_name = forms.CharField()
|
||||
email_confirm = forms.EmailField(label="Confirm Email")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SignupForm, self).__init__(*args, **kwargs)
|
||||
del self.fields["username"]
|
||||
self.fields.keyOrder = [
|
||||
"email",
|
||||
"email_confirm",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"password",
|
||||
"password_confirm"
|
||||
]
|
||||
|
||||
def clean_email_confirm(self):
|
||||
email = self.cleaned_data.get("email")
|
||||
email_confirm = self.cleaned_data["email_confirm"]
|
||||
if email:
|
||||
if email != email_confirm:
|
||||
raise forms.ValidationError("Email address must match previously typed email address")
|
||||
return email_confirm
|
49
symposion/views.py
Normal file
49
symposion/views.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import hashlib
|
||||
import random
|
||||
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
import account.views
|
||||
|
||||
import symposion.forms
|
||||
|
||||
|
||||
class SignupView(account.views.SignupView):
|
||||
|
||||
form_class = symposion.forms.SignupForm
|
||||
|
||||
def create_user(self, form, commit=True):
|
||||
user_kwargs = {
|
||||
"first_name": form.cleaned_data["first_name"],
|
||||
"last_name": form.cleaned_data["last_name"]
|
||||
}
|
||||
return super(SignupView, self).create_user(form, commit=commit, **user_kwargs)
|
||||
|
||||
def generate_username(self, form):
|
||||
def random_username():
|
||||
h = hashlib.sha1(form.cleaned_data["email"]).hexdigest()[:25]
|
||||
# don't ask
|
||||
n = random.randint(1, (10 ** (5 - 1)) - 1)
|
||||
return "%s%d" % (h, n)
|
||||
while True:
|
||||
try:
|
||||
username = random_username()
|
||||
User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
break
|
||||
return username
|
||||
|
||||
|
||||
class LoginView(account.views.LoginView):
|
||||
|
||||
form_class = account.forms.LoginEmailForm
|
||||
|
||||
|
||||
@login_required
|
||||
def dashboard(request):
|
||||
if request.session.get("pending-token"):
|
||||
return redirect("speaker_create_token", request.session["pending-token"])
|
||||
return render(request, "dashboard.html")
|
Loading…
Reference in a new issue