2015-07-18 07:09:17 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-07-12 05:32:07 +00:00
|
|
|
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):
|
2014-07-05 13:11:43 +00:00
|
|
|
|
2012-07-12 05:32:07 +00:00
|
|
|
form_class = symposion.forms.SignupForm
|
2012-08-14 08:48:39 +00:00
|
|
|
form_kwargs = {
|
|
|
|
"prefix": "signup",
|
|
|
|
}
|
2014-07-05 13:11:43 +00:00
|
|
|
|
2012-07-12 05:32:07 +00:00
|
|
|
def create_user(self, form, commit=True):
|
|
|
|
user_kwargs = {
|
|
|
|
"first_name": form.cleaned_data["first_name"],
|
|
|
|
"last_name": form.cleaned_data["last_name"]
|
|
|
|
}
|
2014-07-05 13:11:43 +00:00
|
|
|
return super(SignupView, self).create_user(form, commit=commit,
|
|
|
|
**user_kwargs)
|
2012-07-12 05:32:07 +00:00
|
|
|
|
|
|
|
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
|
2012-08-14 08:48:39 +00:00
|
|
|
form_kwargs = {
|
|
|
|
"prefix": "login",
|
|
|
|
}
|
2012-07-12 05:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def dashboard(request):
|
|
|
|
if request.session.get("pending-token"):
|
2014-07-05 13:11:43 +00:00
|
|
|
return redirect("speaker_create_token",
|
|
|
|
request.session["pending-token"])
|
2012-07-12 05:32:07 +00:00
|
|
|
return render(request, "dashboard.html")
|