Beispiel #1
0
def activate_secondary_email(request, key):
    """
    This is called when the activation link is clicked. We activate the secondary email
    for the requested user.
    """
    try:
        pending_secondary_email_change = PendingSecondaryEmailChange.objects.get(activation_key=key)
    except PendingSecondaryEmailChange.DoesNotExist:
        return render_to_response("invalid_email_key.html", {})

    try:
        account_recovery = pending_secondary_email_change.user.account_recovery
    except AccountRecovery.DoesNotExist:
        account_recovery = AccountRecovery(user=pending_secondary_email_change.user)

    try:
        account_recovery.update_recovery_email(pending_secondary_email_change.new_secondary_email)
    except ValidationError:
        return render_to_response("secondary_email_change_failed.html", {
            'secondary_email': pending_secondary_email_change.new_secondary_email
        })

    pending_secondary_email_change.delete()

    return render_to_response("secondary_email_change_successful.html")
    def handle(self, *args, **options):
        """
        Execute the command.
        """

        username = options['username']
        user_email = options['user_email']
        try:
            user = User.objects.get(username=username, email=user_email)
        except:
            error_message = (
                'Could not find a user with specified username and email '
                'address. Make sure you have everything correct before '
                'trying again')
            logger.error(error_message)
            raise CommandError(error_message)  # lint-amnesty, pylint: disable=raise-missing-from

        user_model = get_user_model()

        try:
            with transaction.atomic():
                # Add user to retirement queue.
                UserRetirementStatus.create_retirement(user)
                # Unlink LMS social auth accounts
                UserSocialAuth.objects.filter(user_id=user.id).delete()
                # Change LMS password & email
                user.email = get_retired_email_by_email(user.email)
                user.set_unusable_password()
                user.save()

                # TODO: Unlink social accounts & change password on each IDA.
                # Remove the activation keys sent by email to the user for account activation.
                Registration.objects.filter(user=user).delete()

                # Delete OAuth tokens associated with the user.
                retire_dot_oauth2_models(user)
                AccountRecovery.retire_recovery_email(user.id)
        except KeyError:
            error_message = 'Username not specified {}'.format(user)
            logger.error(error_message)
            raise CommandError(error_message)  # lint-amnesty, pylint: disable=raise-missing-from
        except user_model.DoesNotExist:
            error_message = 'The user "{}" does not exist.'.format(
                user.username)
            logger.error(error_message)
            raise CommandError(error_message)  # lint-amnesty, pylint: disable=raise-missing-from
        except Exception as exc:  # pylint: disable=broad-except
            error_message = '500 error deactivating account {}'.format(exc)
            logger.error(error_message)
            raise CommandError(error_message)  # lint-amnesty, pylint: disable=raise-missing-from

        logger.info("User succesfully moved to the retirment pipeline")
Beispiel #3
0
    def test_retire_recovery_email(self):
        """
        Assert that Account Record for a given user is deleted when `retire_recovery_email` is called
        """
        # Create user and associated recovery email record
        user = UserFactory()
        AccountRecoveryFactory(user=user)
        assert len(AccountRecovery.objects.filter(user_id=user.id)) == 1

        # Retire recovery email
        AccountRecovery.retire_recovery_email(user_id=user.id)

        # Assert that there is no longer an AccountRecovery record for this user
        assert len(AccountRecovery.objects.filter(user_id=user.id)) == 0
Beispiel #4
0
def create_retirement_request_and_deactivate_account(user):
    """
    Adds user to retirement queue, unlinks social auth accounts, changes user passwords
    and delete tokens and activation keys
    """
    # Add user to retirement queue.
    UserRetirementStatus.create_retirement(user)

    # Unlink LMS social auth accounts
    UserSocialAuth.objects.filter(user_id=user.id).delete()

    # Change LMS password & email
    user.email = get_retired_email_by_email(user.email)
    user.set_unusable_password()
    user.save()

    # TODO: Unlink social accounts & change password on each IDA.
    # Remove the activation keys sent by email to the user for account activation.
    Registration.objects.filter(user=user).delete()

    # Delete OAuth tokens associated with the user.
    retire_dot_oauth2_models(user)
    AccountRecovery.retire_recovery_email(user.id)