#NEWLINE# def activate_user( self , activation_key , request = None ) : #NEWLINE# #INDENT# '\n        Validate an activation key and activate the corresponding\n        ``User`` if valid.\n\n        If the key is valid and has not expired, return the ``User``\n        after activating.\n\n        If the key is not valid or has expired, return ``False``.\n        ' #NEWLINE# if SHA1_RE . search ( activation_key ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# profile = self . get ( activation_key = activation_key ) #NEWLINE# #UNINDENT# except self . model . DoesNotExist : #NEWLINE# #INDENT# profile = None #NEWLINE# statsd . incr ( 'user.activate-error.does-not-exist' ) #NEWLINE# reason = 'key not found' #NEWLINE# #UNINDENT# if profile : #NEWLINE# #INDENT# if ( not profile . activation_key_expired ( ) ) : #NEWLINE# #INDENT# user = profile . user #NEWLINE# user . is_active = True #NEWLINE# user . save ( ) #NEWLINE# profile . delete ( ) #NEWLINE# if user . groups . filter ( name = CONTRIBUTOR_GROUP ) : #NEWLINE# #INDENT# self . _send_email ( confirmation_profile = profile , url = None , subject = _ ( 'Welcome to SUMO!' ) , text_template = 'users/email/contributor.ltxt' , html_template = 'users/email/contributor.html' , send_to = user . email , contributor = user ) #NEWLINE# #UNINDENT# return user #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# statsd . incr ( 'user.activate-error.expired' ) #NEWLINE# reason = 'key expired' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# statsd . incr ( 'user.activate-error.invalid-key' ) #NEWLINE# reason = 'invalid key' #NEWLINE# #UNINDENT# log . warning ( 'User activation failure ({r}): {k}' . format ( r = reason , k = activation_key ) ) #NEWLINE# return False