#NEWLINE# @ secure_required #NEWLINE# @ permission_required_or_403 ( 'change_user' , ( get_user_model ( ) , 'username' , 'username' ) ) #NEWLINE# def email_change( request , username , email_form = ChangeEmailForm , template_name = 'userena/email_form.html' , success_url = None , extra_context = None ) : #NEWLINE# #INDENT# '\n    Change email address\n\n    :param username:\n        String of the username which specifies the current account.\n\n    :param email_form:\n        Form that will be used to change the email address. Defaults to\n        :class:`ChangeEmailForm` supplied by userena.\n\n    :param template_name:\n        String containing the template to be used to display the email form.\n        Defaults to ``userena/email_form.html``.\n\n    :param success_url:\n        Named URL where the user will get redirected to when successfully\n        changing their email address.  When not supplied will redirect to\n        ``userena_email_complete`` URL.\n\n    :param extra_context:\n        Dictionary containing extra variables that can be used to render the\n        template. The ``form`` key is always the form supplied by the keyword\n        argument ``form`` and the ``user`` key by the user whose email address\n        is being changed.\n\n    **Context**\n\n    ``form``\n        Form that is used to change the email address supplied by ``form``.\n\n    ``account``\n        Instance of the ``Account`` whose email address is about to be changed.\n\n    **Todo**\n\n    Need to have per-object permissions, which enables users with the correct\n    permissions to alter the email address of others.\n\n    ' #NEWLINE# user = get_object_or_404 ( get_user_model ( ) , username__iexact = username ) #NEWLINE# prev_email = user . email #NEWLINE# form = email_form ( user ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = email_form ( user , request . POST , request . FILES ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# form . save ( ) #NEWLINE# if success_url : #NEWLINE# #INDENT# userena_signals . email_change . send ( sender = None , user = user , prev_email = prev_email , new_email = user . email ) #NEWLINE# redirect_to = extra_context #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# redirect_to = reverse ( 'userena_email_change_complete' , kwargs = { #NEWLINE# #INDENT# 'username' : user . username , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return redirect ( redirect_to ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not extra_context ) : #NEWLINE# #INDENT# extra_context = dict ( ) #NEWLINE# #UNINDENT# extra_context [ 'form' ] = form #NEWLINE# extra_context [ 'profile' ] = get_user_profile ( user = user ) #NEWLINE# return ExtraContextTemplateView . as_view ( template_name = template_name , extra_context = extra_context ) ( request )