Validate an activation key and activate the corresponding
    ``User`` if valid.
    If the key is valid and has not expired, return the ``User``
    after activating.
    If the key is not valid or has expired, return ``False``.
    If the key is valid but the ``User`` is already active,
    return ``False``.
    To prevent reactivation of an account which has been
    deactivated by site administrators, the activation key is
    reset to the string constant ``RegistrationProfile.ACTIVATED``
    after successful activation.

def activate_user(activation_key):
    """
    Validate an activation key and activate the corresponding
    ``User`` if valid.
    If the key is valid and has not expired, return the ``User``
    after activating.
    If the key is not valid or has expired, return ``False``.
    If the key is valid but the ``User`` is already active,
    return ``False``.
    To prevent reactivation of an account which has been
    deactivated by site administrators, the activation key is
    reset to the string constant ``RegistrationProfile.ACTIVATED``
    after successful activation.

    """
    # Make sure the key we're trying conforms to the pattern of a
    # SHA1 hash; if it doesn't, no point trying to look it up in
    # the database.
    if SHA1_RE.search(activation_key):
        try:
            profile = RegistrationProfile.objects.get(
                activation_key=activation_key)
        except RegistrationProfile.DoesNotExist:
            return False
        if not profile.activation_key_expired():
            user = profile.user
            user.is_active = True
            user.save()
            profile.activation_key = RegistrationProfile.ACTIVATED
            profile.save()
            return user
    return False