コード例 #1
0
class SignupMixin:

    activation_subject = 'aristotle_mdr/users_management/newuser/email/activation_subject.txt'
    activation_body = 'aristotle_mdr/users_management/newuser/email/activation_body.html'

    def __init__(self, *args, **kwargs):
        self.registration_backend = BaseBackend()
        super().__init__(*args, **kwargs)

    def send_activation(self, user):
        # Send Activation Email
        token = self.registration_backend.get_token(user)
        self.registration_backend.email_message(
            user,
            self.activation_subject,
            self.activation_body,
            token=token,
            user_id=user.id,
            accept_url_name=self.accept_url_name,
            config=fetch_aristotle_settings(),
            request=self.request
        ).send()

    def get_signup_settings(self, request):
        aristotle_settings = fetch_aristotle_settings()

        try:
            signup_settings = aristotle_settings['SELF_SIGNUP']
        except KeyError:
            signup_settings = None

        if signup_settings:
            # Check if user self signup is enabled
            self.signup_enabled = signup_settings.get('enabled', False)
            self.allowed_suffixes = signup_settings.get('emails', None)
        else:
            self.signup_enabled = False
            self.allowed_suffixes = None

        return self.signup_enabled

    def send_password_reset(self, user_email, request):

        if settings.ARISTOTLE_EMAIL_ACCOUNT_RECOVERY:
            from_email = settings.ARISTOTLE_EMAIL_ACCOUNT_RECOVERY
        else:
            from_email = settings.DEFAULT_FROM_EMAIL

        form = PasswordResetForm({'email': user_email})
        if form.is_valid():
            form.save(
                request=request,
                from_email=from_email,
                use_https=True
            )
            return True
        else:
            return False
コード例 #2
0
class SignupMixin:

    activation_subject = 'aristotle_mdr/users_management/newuser/email/activation_subject.txt'
    activation_body = 'aristotle_mdr/users_management/newuser/email/activation_body.html'

    def __init__(self, *args, **kwargs):
        self.registration_backend = BaseBackend()
        super().__init__(*args, **kwargs)

    def send_activation(self, user):
        # Send Activation Email
        token = self.registration_backend.get_token(user)
        self.registration_backend.email_message(
            user,
            self.activation_subject,
            self.activation_body,
            token=token,
            user_id=user.id,
            accept_url_name=self.accept_url_name,
            config=fetch_aristotle_settings(),
            request=self.request
        ).send()

    def get_signup_settings(self, request):
        aristotle_settings = fetch_aristotle_settings()

        try:
            signup_settings = aristotle_settings['SELF_SIGNUP']
        except KeyError:
            signup_settings = None

        if signup_settings:
            # Check if user self signup is enabled
            self.signup_enabled = signup_settings.get('enabled', False)
            self.allowed_suffixes = signup_settings.get('emails', None)
        else:
            self.signup_enabled = False
            self.allowed_suffixes = None

        return self.signup_enabled

    def send_password_reset(self, user_email, request):

        form = PasswordResetForm({'email': user_email})
        if form.is_valid():
            form.save(
                request=request,
                from_email=settings.DEFAULT_FROM_EMAIL,
                use_https=True
            )
            return True
        else:
            return False
コード例 #3
0
 def __init__(self, *args, **kwargs):
     self.registration_backend = BaseBackend()
     super().__init__(*args, **kwargs)
コード例 #4
0
 def test_generate_username(self):
     self.assertTrue(BaseBackend().get_username())
コード例 #5
0
 def __init__(self, *args, **kwargs):
     self.registration_backend = BaseBackend()
     super().__init__(*args, **kwargs)