Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add welcome email, send email when user is created #143

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bothub/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.template.loader import render_to_string
from django.conf import settings
from django.core.exceptions import ValidationError
from django.dispatch import receiver


user_nickname_re = _lazy_re_compile(r'^[-a-zA-Z0-9_]+\Z')
Expand Down Expand Up @@ -101,6 +102,21 @@ class Meta:
def token_generator(self):
return PasswordResetTokenGenerator()

def send_welcome_email(self):
context = {
'name': self.name,
}
send_mail(
_('Welcome to Bothub'),
render_to_string(
'authentication/emails/welcome.txt',
context),
None,
[self.email],
html_message=render_to_string(
'authentication/emails/welcome.html',
context))

def make_password_reset_token(self):
return self.token_generator.make_token(self)

Expand All @@ -126,3 +142,9 @@ def send_reset_password_email(self):

def check_password_reset_token(self, token):
return self.token_generator.check_token(self, token)


@receiver(models.signals.post_save, sender=User)
def send_welcome_email(instance, created, **kwargs):
if created:
instance.send_welcome_email()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions bothub/authentication/templates/authentication/emails/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'bothub/emails/base.html' %}

{% load staticfiles i18n %}

{% block before-content %}
<tr>
<td align="center" style="padding-top: 20px;">
<img src="{% static 'authentication/emails/welcome.png' %}" alt="{% trans 'Welcome to Bothub' %}" width="100%" style="max-width: 388px; display: block;" />
<h1 style="font-size: 24px;">{% trans 'Welcome to Bothub' %}</h1>
</td>
</tr>
{% endblock %}

{% block main-content %}
<p style="margin: 32px 0; text-align: center;"><b>{% blocktrans %}Hello, {{ name }}!{% endblocktrans %}</b></p>
<p align="justify">{% trans 'You\'ve successfully signed up for Bothub and now you can start creating, improving and translating bots on the platform.' %}</p>
<p align="justify">{% trans 'We are happy to have you with us and hope you enjoy Bothub.' %}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}{% trans 'Welcome to Bothub' %}

{% blocktrans %}Hello, {{ name }}!{% endblocktrans %}
{% trans 'You\'ve successfully signed up for Bothub and now you can start creating, improving and translating bots on the platform.' %}
{% trans 'We are happy to have you with us and hope you enjoy Bothub.' %}
19 changes: 19 additions & 0 deletions bothub/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from rest_framework.documentation import include_docs_urls

from bothub.api.routers import router as bothub_api_routers


urlpatterns = [
path('api/', include(bothub_api_routers.urls)),
path('docs/', include_docs_urls(title='API Documentation')),
path('admin/', admin.site.urls),
]

if settings.DEBUG:
def render_template(template_name, **kwargs):
def wrapper(request):
from django.shortcuts import render
return render(request, template_name, kwargs)
return wrapper

urlpatterns += [
path('emails/', include([
path(
'welcome/',
render_template(
'authentication/emails/welcome.html',
name='Douglas')),
])),
]