def activation_key_expired(self):
        """
        Determine whether this ``RegistrationProfile``'s activation
        key has expired, returning a boolean -- ``True`` if the key
        has expired.
        Key expiration is determined by a two-step process:
        1. If the user has already activated, the key will have been
        reset to the string constant ``ACTIVATED``. Re-activating
        is not permitted, and so this method returns ``True`` in
        this case.

        2. Otherwise, the date the user signed up is incremented by
        the number of days specified in the setting
        ``REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS`` (which should be
        the number of days after signup during which a user is allowed
        to activate their account); if the result is less than or
        equal to the current date, the key has expired and this method
        returns ``True``.

        """

        # utils imported here to avoid circular import
        from registration_api import utils

        expiration_date = datetime.timedelta(
            days=utils.get_settings('REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS'))
        date_joined=datetime.datetime(*(self.user.date_joined.timetuple()[:6])).replace(tzinfo=datetime_now().tzinfo)
        return self.activation_key == self.ACTIVATED or \
               (date_joined + expiration_date <= datetime_now())
Example #2
0
    def activation_key_expired(self):
        """
        Determine whether this ``RegistrationProfile``'s activation
        key has expired, returning a boolean -- ``True`` if the key
        has expired.
        Key expiration is determined by a two-step process:
        1. If the user has already activated, the key will have been
        reset to the string constant ``ACTIVATED``. Re-activating
        is not permitted, and so this method returns ``True`` in
        this case.

        2. Otherwise, the date the user signed up is incremented by
        the number of days specified in the setting
        ``REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS`` (which should be
        the number of days after signup during which a user is allowed
        to activate their account); if the result is less than or
        equal to the current date, the key has expired and this method
        returns ``True``.

        """

        # utils imported here to avoid circular import
        from registration_api import utils

        expiration_date = datetime.timedelta(days=utils.get_settings(
            'REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS'))
        return self.activation_key == self.ACTIVATED or \
            (self.user.date_joined + expiration_date <= datetime_now())
def activate(request, activation_key=None):
    """
    Given an an activation key, look up and activate the user
    account corresponding to that key (if possible).

    """
    utils.activate_user(activation_key)
    # if not activated
    success_url = utils.get_settings('REGISTRATION_API_ACTIVATION_SUCCESS_URL')
    if success_url is not None:
        return HttpResponseRedirect(success_url)
Example #4
0
def activate(request, activation_key=None):
    """
    Given an an activation key, look up and activate the user
    account corresponding to that key (if possible).

    """
    utils.activate_user(activation_key)
    # if not activated
    success_url = utils.get_settings('REGISTRATION_API_ACTIVATION_SUCCESS_URL')
    if success_url is not None:
        return render(request,
                      'mainRest/activation.html',
                      status=status.HTTP_200_OK)
    def test_activate(self):
        user = utils.create_inactive_user(**VALID_DATA)
        request = MockHttpRequest()

        response = activate(
            request, activation_key=user.registrationprofile.activation_key)
        user = get_user_model().objects.get(pk=user.pk)

        self.assertTrue(user.is_active)
        self.assertEqual(user.registrationprofile.activation_key,
                         RegistrationProfile.ACTIVATED)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(
            response['location'],
            utils.get_settings('REGISTRATION_API_ACTIVATION_SUCCESS_URL'))
    def test_activate(self):
        user = utils.create_inactive_user(**VALID_DATA)
        request = MockHttpRequest()

        response = activate(
            request,
            activation_key=user.api_registration_profile.activation_key)
        user = get_user_model().objects.get(pk=user.pk)

        self.assertTrue(user.is_active)
        self.assertEqual(user.api_registration_profile.activation_key,
                         RegistrationProfile.ACTIVATED)
        self.assertEqual(response.status_code,
                         status.HTTP_302_FOUND)
        self.assertEqual(response['location'],
                         utils.get_settings('REGISTRATION_API_ACTIVATION_SUCCESS_URL'))
    def test_get_settings(self):
        value = utils.get_settings('REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS')

        self.assertEqual(
            value,
            utils.DEFAULT_SETTINGS['REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS'])
    def test_get_settings(self):
        value = utils.get_settings('REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS')

        self.assertEqual(
            value,
            utils.DEFAULT_SETTINGS['REGISTRATION_API_ACCOUNT_ACTIVATION_DAYS'])