<s> from django . contrib import auth <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . forms import UserCreationForm <EOL> from django import forms <EOL> from django . template import RequestContext <EOL> from django . shortcuts import render_to_response <EOL> class UserCreationFormWithEmail ( UserCreationForm ) : <EOL> email = forms . EmailField ( ) <EOL> def clean_email ( self ) : <EOL> email = self . cleaned_data [ '<STR_LIT:email>' ] <EOL> try : <EOL> u = User . objects . get ( email = email ) <EOL> except User . DoesNotExist : <EOL> pass <EOL> else : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> def save ( self , commit = True ) : <EOL> user = super ( UserCreationFormWithEmail , self ) . save ( commit = False ) <EOL> user . email = self . cleaned_data [ '<STR_LIT:email>' ] <EOL> if commit : <EOL> user . save ( ) <EOL> return user <EOL> def register ( request ) : <EOL> ctx = RequestContext ( request , { } ) <EOL> if request . user . is_authenticated ( ) : <EOL> return render_to_response ( "<STR_LIT>" , { } , ctx ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = UserCreationFormWithEmail ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> user = form . save ( ) <EOL> user = auth . authenticate ( username = user . username , password = request . POST [ "<STR_LIT>" ] ) <EOL> auth . login ( request , user ) <EOL> return render_to_response ( "<STR_LIT>" , { } , ctx ) <EOL> else : <EOL> form = UserCreationFormWithEmail ( ) <EOL> return render_to_response ( "<STR_LIT>" , { "<STR_LIT>" : form } , ctx ) </s>
