#NEWLINE# @ csrf_protect #NEWLINE# @ never_cache #NEWLINE# def register( request , template_name = 'users/registration_form.html' , activation_email_template_name = 'users/activation_email.html' , activation_email_subject_template_name = 'users/activation_email_subject.html' , activation_email_html_template_name = None , registration_form = RegistrationForm , registered_user_redirect_to = None , post_registration_redirect = None , activation_from_email = None , current_app = None , extra_context = None ) : #NEWLINE# #INDENT# if ( registered_user_redirect_to is None ) : #NEWLINE# #INDENT# registered_user_redirect_to = getattr ( settings , 'LOGIN_REDIRECT_URL' ) #NEWLINE# #UNINDENT# if request . user . is_authenticated ( ) : #NEWLINE# #INDENT# return redirect ( registered_user_redirect_to ) #NEWLINE# #UNINDENT# if ( not settings . USERS_REGISTRATION_OPEN ) : #NEWLINE# #INDENT# return redirect ( reverse ( 'users_registration_closed' ) ) #NEWLINE# #UNINDENT# if ( post_registration_redirect is None ) : #NEWLINE# #INDENT# post_registration_redirect = reverse ( 'users_registration_complete' ) #NEWLINE# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = registration_form ( request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# user = form . save ( ) #NEWLINE# if settings . USERS_AUTO_LOGIN_AFTER_REGISTRATION : #NEWLINE# #INDENT# user . backend = 'django.contrib.auth.backends.ModelBackend' #NEWLINE# login ( request , user ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not user . is_active ) and settings . USERS_VERIFY_EMAIL ) : #NEWLINE# #INDENT# opts = { #NEWLINE# #INDENT# 'user' : user , #NEWLINE# 'request' : request , #NEWLINE# 'from_email' : activation_from_email , #NEWLINE# 'email_template' : activation_email_template_name , #NEWLINE# 'subject_template' : activation_email_subject_template_name , #NEWLINE# 'html_email_template' : activation_email_html_template_name , #NEWLINE# #UNINDENT# } #NEWLINE# send_activation_email ( ** opts ) #NEWLINE# user_registered . send ( sender = activation_from_email . __class__ , request = request , user = user ) #NEWLINE# #UNINDENT# #UNINDENT# return redirect ( post_registration_redirect ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = registration_form ( ) #NEWLINE# #UNINDENT# current_site = get_current_site ( request ) #NEWLINE# context = { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# 'site' : current_site , #NEWLINE# 'site_name' : current_site . name , #NEWLINE# 'title' : _ ( 'Register' ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( extra_context is not None ) : #NEWLINE# #INDENT# context . update ( extra_context ) #NEWLINE# #UNINDENT# return TemplateResponse ( request , template_name , context , current_app = current_app )