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
    form_kwargs = {
        "prefix": "signup",
    }

    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
    form_kwargs = {
        "prefix": "login",
    }


@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")

@@ -4,30 +4,99 @@
 ort 
-hashlib%0Aimport random%0A
+random%0A%0Afrom django.core.exceptions import ValidationError%0Afrom django.conf import settings
 %0Afro
@@ -245,53 +245,173 @@
 red%0A
-%0Aimport account.views%0A%0Aimport symposion.forms
+from django.utils.translation import ugettext_lazy as _%0A%0Aimport account.views%0A%0Aimport symposion.forms%0A%0AUNIQUE_EMAIL = getattr(settings, 'ACCOUNT_UNIQUE_EMAIL', True)
 %0A%0A%0Ac
@@ -973,25 +973,12 @@
     
-h
+m
  = 
-hashlib.sha1(
 form
@@ -1003,26 +1003,8 @@
 il%22%5D
-).hexdigest()%5B:25%5D
 %0A   
@@ -1112,22 +1112,23 @@
  %25 (
-h
+m
 , n)%0A
+%0A
         
 whil
@@ -1127,41 +1127,483 @@
     
-while True:%0A            try:%0A    
+# username = email in most case.%0A        username = form.cleaned_data%5B%22email%22%5D%0A        if not User.objects.filter(username=username):%0A            return username%0A%0A        if UNIQUE_EMAIL:%0A            # wish not to happen but will happen%0A            # when user change its email and%0A            # re-use it when another singup%0A            # It is nothing to do special%0A            pass%0A%0A        # fall back to add random number%0A        for i in range(1, 2 * (10 ** (5 - 1))):%0A
     
@@ -1651,19 +1651,22 @@
         
-   
+if not
  User.ob
@@ -1671,19 +1671,22 @@
 objects.
-get
+filter
 (usernam
@@ -1696,16 +1696,17 @@
 sername)
+:
 %0A       
@@ -1714,34 +1714,130 @@
     
-except User.DoesNotExist:%0A
+    return username%0A%0A        # no way%0A        raise ValidationError(_(%22Cannot process your signup request properly. %22%0A    
     
@@ -1852,22 +1852,16 @@
     
-break%0A
         
 retu
@@ -1856,31 +1856,71 @@
         
-return username
+    %22Please signup again with another email address.%22))
 %0A%0A%0Aclass

use email as account username in default