#NEWLINE# @ secure_required #NEWLINE# def activate( request , activation_key , template_name = 'userena/activate_fail.html' , retry_template_name = 'userena/activate_retry.html' , success_url = None , extra_context = None ) : #NEWLINE# #INDENT# '\n    Activate a user with an activation key.\n\n    The key is a SHA1 string. When the SHA1 is found with an\n    :class:`UserenaSignup`, the :class:`User` of that account will be\n    activated.  After a successful activation the view will redirect to\n    ``success_url``.  If the SHA1 is not found, the user will be shown the\n    ``template_name`` template displaying a fail message.\n    If the SHA1 is found but expired, ``retry_template_name`` is used instead,\n    so the user can proceed to :func:`activate_retry` to get a new activation key.\n\n    :param activation_key:\n        String of a SHA1 string of 40 characters long. A SHA1 is always 160bit\n        long, with 4 bits per character this makes it --160/4-- 40 characters\n        long.\n\n    :param template_name:\n        String containing the template name that is used when the\n        ``activation_key`` is invalid and the activation fails. Defaults to\n        ``userena/activate_fail.html``.\n\n    :param retry_template_name:\n        String containing the template name that is used when the\n        ``activation_key`` is expired. Defaults to\n        ``userena/activate_retry.html``.\n\n    :param success_url:\n        String containing the URL where the user should be redirected to after\n        a successful activation. Will replace ``%(username)s`` with string\n        formatting if supplied. If ``success_url`` is left empty, will direct\n        to ``userena_profile_detail`` view.\n\n    :param extra_context:\n        Dictionary containing variables which could be added to the template\n        context. Default to an empty dictionary.\n\n    ' #NEWLINE# try : #NEWLINE# #INDENT# if ( ( not UserenaSignup . objects . check_expired_activation ( activation_key ) ) or ( not userena_settings . USERENA_ACTIVATION_RETRY ) ) : #NEWLINE# #INDENT# user = UserenaSignup . objects . activate_user ( auth_user ) #NEWLINE# if user : #NEWLINE# #INDENT# auth_user = authenticate ( identification = user . email , check_password = False ) #NEWLINE# login ( request , auth_user ) #NEWLINE# if userena_settings . USERENA_USE_MESSAGES : #NEWLINE# #INDENT# messages . success ( request , _ ( 'Your account has been activated and you have been signed in.' ) , fail_silently = True ) #NEWLINE# #UNINDENT# if success_url : #NEWLINE# #INDENT# redirect_to = ( success_url % { #NEWLINE# #INDENT# 'username' : user . username , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# redirect_to = reverse ( 'userena_profile_detail' , kwargs = { #NEWLINE# #INDENT# 'username' : user . username , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return redirect ( redirect_to ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not extra_context ) : #NEWLINE# #INDENT# extra_context = dict ( ) #NEWLINE# #UNINDENT# return ExtraContextTemplateView . as_view ( template_name = template_name , extra_context = extra_context ) ( request ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not extra_context ) : #NEWLINE# #INDENT# extra_context = dict ( ) #NEWLINE# #UNINDENT# extra_context [ 'activation_key' ] = activation_key #NEWLINE# return ExtraContextTemplateView . as_view ( template_name = retry_template_name , extra_context = extra_context ) ( request ) #NEWLINE# #UNINDENT# #UNINDENT# except UserenaSignup . DoesNotExist : #NEWLINE# #INDENT# if ( not extra_context ) : #NEWLINE# #INDENT# extra_context = dict ( ) #NEWLINE# #UNINDENT# return ExtraContextTemplateView . as_view ( template_name = template_name , extra_context = extra_context ) ( request )