Beispiel #1
0
Datei: email.py Projekt: g10f/sso
def send_account_created_email(user, request, token_generator=default_pwd_reset_token_generator,
                               email_template_name='accounts/email/account_created_email.txt',
                               subject_template_name='accounts/email/account_created_email_subject.txt',
                               apply_async=None,
                               countdown=0
                               ):
    use_https = request.is_secure()
    current_site = get_current_site(request)
    site_name = settings.SSO_SITE_NAME
    domain = current_site.domain
    user_primary_email = request.user.primary_email()
    reply_to = [user_primary_email.email] if user_primary_email else None
    expiration_date = now() + datetime.timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
    email = user.primary_email()
    c = {
        'email': email,
        'first_name': user.first_name,
        'username': user.username,
        'domain': domain,
        'site_name': site_name,
        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
        'token': token_generator.make_token(user),
        'protocol': use_https and 'https' or 'http',
        'expiration_date': expiration_date
    }
    # use the user language or the default language (en-us)
    language = user.language if user.language else settings.LANGUAGE_CODE
    message, subject = i18n_email_msg_and_subj(c, email_template_name, subject_template_name, language)

    user.email_user(subject, message, reply_to=reply_to, fail_silently=settings.DEBUG, apply_async=apply_async,
                    countdown=countdown, bcc=reply_to)
Beispiel #2
0
def get_set_password_email_message(
        user,
        request,
        token_generator=default_pwd_reset_token_generator,
        email_template_name='registration/email/set_password_email.txt',
        subject_template_name='registration/email/set_password_subject.txt'):
    use_https = request.is_secure()
    current_site = get_current_site(request)
    site_name = settings.SSO_SITE_NAME
    domain = current_site.domain
    expiration_date = now() + datetime.timedelta(
        seconds=settings.PASSWORD_RESET_TIMEOUT)

    c = {
        'email': user.primary_email(),
        'username': user.username,
        'domain': domain,
        'site_name': site_name,
        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
        'token': token_generator.make_token(user),
        'protocol': use_https and 'https' or 'http',
        'expiration_date': expiration_date
    }
    # use the user language or the default language (en-us)
    language = user.language if user.language else settings.LANGUAGE_CODE
    return i18n_email_msg_and_subj(c, email_template_name,
                                   subject_template_name, language)
Beispiel #3
0
def send_validation_email(
        registration_profile,
        request,
        token_generator=default_token_generator,
        email_template_name='registration/email/validation_email.txt',
        subject_template_name='registration/email/validation_email_subject.txt'
):
    use_https = request.is_secure()
    current_site = get_current_site(request)
    site_name = settings.SSO_SITE_NAME
    domain = current_site.domain
    expiration_date = now() + datetime.timedelta(
        settings.REGISTRATION.get('TOKEN_EXPIRATION_DAYS', 7))

    c = {
        'domain': domain,
        'site_name': site_name,
        'protocol': use_https and 'https' or 'http',
        'token': token_generator.make_token(registration_profile),
        'uid': urlsafe_base64_encode(force_bytes(registration_profile.pk)),
        'expiration_date': expiration_date
    }
    # use the user language or the current language from the browser
    language = registration_profile.user.language
    message, subject = i18n_email_msg_and_subj(c, email_template_name,
                                               subject_template_name, language)
    registration_profile.user.email_user(subject, message, None)
Beispiel #4
0
Datei: email.py Projekt: g10f/sso
def get_email_message(user, request, reply_to_email, email_template_name,
                      subject_template_name):
    use_https = request.is_secure()
    current_site = get_current_site(request)
    site_name = settings.SSO_SITE_NAME
    domain = current_site.domain

    c = {
        'user': user,
        'sender': request.user,
        'reply_to_email': reply_to_email,
        'brand': settings.SSO_BRAND,
        'email': user.primary_email(),
        'username': user.username,
        'domain': domain,
        'site_name': site_name,
        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
        'protocol': use_https and 'https' or 'http',
    }
    # use the user language or the default language (en-us)
    language = user.language if user.language else settings.LANGUAGE_CODE
    return i18n_email_msg_and_subj(c, email_template_name,
                                   subject_template_name, language)
Beispiel #5
0
Datei: forms.py Projekt: g10f/sso
def send_user_request_extended_access(
        admins,
        access_request,
        message,
        email_template_name='access_requests/email/access_request_email.txt',
        subject_template_name='access_requests/email/access_request_email_subject.txt',
        apply_async=False):
    recipients = [force_str(admin.primary_email()) for admin in admins]
    if len(recipients) > 0:
        domain = settings.SSO_DOMAIN
        use_https = settings.SSO_USE_HTTPS
        site_name = settings.SSO_SITE_NAME
        user = access_request.user
        c = {
            'message':
            message,
            'protocol':
            use_https and 'https' or 'http',
            'domain':
            domain,
            'update_user_url':
            reverse("access_requests:extend_access_accept",
                    args=(access_request.pk, )),
            'user':
            user,
            'site_name':
            site_name,
            'days_since_access_request':
            (now() - access_request.last_modified).days,
        }
        message, subject = i18n_email_msg_and_subj(c, email_template_name,
                                                   subject_template_name)
        send_mail(subject,
                  message,
                  recipient_list=recipients,
                  reply_to=[user.primary_email()],
                  apply_async=apply_async)
Beispiel #6
0
Datei: email.py Projekt: g10f/sso
def send_useremail_confirmation(user_email, request, token_generator=email_confirm_token_generator,
                                email_template_name='accounts/email/useremail_confirm_email.txt',
                                subject_template_name='accounts/email/useremail_confirm_email_subject.txt'
                                ):
    use_https = request.is_secure()
    current_site = get_current_site(request)
    site_name = settings.SSO_SITE_NAME
    domain = current_site.domain
    expiration_date = now() + datetime.timedelta(minutes=settings.SSO_EMAIL_CONFIRM_TIMEOUT_MINUTES)
    user = user_email.user
    c = {
        'user_email': user_email.email,
        'first_name': user.first_name,
        'username': user.username,
        'domain': domain,
        'site_name': site_name,
        'uid': urlsafe_base64_encode(force_bytes(user_email.pk)),
        'token': token_generator.make_token(user_email),
        'protocol': use_https and 'https' or 'http',
        'expiration_date': expiration_date
    }
    # use the user language or the current language from the browser
    message, subject = i18n_email_msg_and_subj(c, email_template_name, subject_template_name, user.language)
    send_mail(subject, message, recipient_list=[user_email.email], fail_silently=settings.DEBUG)