Skip to content

Commit 5942bbf

Browse files
authored
Merge pull request doccano#504 from CatalystCode/enhancement/verification-emails-on-azure
Enhancement/Verification emails on Azure
2 parents ed388db + dc2e264 commit 5942bbf

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

app/app/settings.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@
296296
'endpoint': env('AZURE_APPINSIGHTS_ENDPOINT', None),
297297
}
298298

299-
## necessary for email verification setup
300-
# EMAIL_USE_TLS = True
301-
# EMAIL_HOST = 'smtp.gmail.com'
302-
# EMAIL_HOST_USER = '[email protected]'
303-
# EMAIL_HOST_PASSWORD = 'gfds6jk#4ljIr%G8%'
304-
# EMAIL_PORT = 587
305-
#
306-
## During development only
307-
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
299+
# necessary for email verification of new accounts
300+
EMAIL_USE_TLS = env.bool('EMAIL_USE_TLS', False)
301+
EMAIL_HOST = env('EMAIL_HOST', None)
302+
EMAIL_HOST_USER = env('EMAIL_HOST_USER', None)
303+
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD', None)
304+
EMAIL_PORT = env.int('EMAIL_PORT', 587)
305+
306+
if not EMAIL_HOST:
307+
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% autoescape off %}
22
Hi {{ user.username }},
3-
Please click on the link to confirm your email,
4-
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
3+
Please click on the link to confirm your email and activate your Doccano account:
4+
{{ scheme }}://{{ domain }}{% url 'activate' uidb64=uid token=token %}
55
{% endautoescape %}

app/authentification/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def post(self, request, *args, **kwargs):
3939
message = render_to_string('acc_active_email.html', {
4040
'user': user,
4141
'domain': current_site.domain,
42+
'scheme': request.scheme,
4243
'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
4344
'token': account_activation_token.make_token(user),
4445
})

azuredeploy.json

+55
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"adminPassword": {
3434
"type": "securestring",
3535
"minLength": 16,
36+
"maxLength": 50,
3637
"metadata": {
3738
"description": "The password for the admin account."
3839
}
@@ -52,6 +53,21 @@
5253
"description": "The SKU of the webapp hosting tier."
5354
}
5455
},
56+
"sendgridSku": {
57+
"type": "string",
58+
"defaultValue": "free",
59+
"allowedValues": [
60+
"free",
61+
"bronze",
62+
"silver",
63+
"gold",
64+
"platinum",
65+
"premier"
66+
],
67+
"metadata": {
68+
"description": "The SKU of the Sendgrid email account."
69+
}
70+
},
5571
"databaseCores": {
5672
"type": "int",
5773
"defaultValue": 2,
@@ -124,11 +140,29 @@
124140
"databaseUserCredentials" : "[concat(uriComponent(concat(parameters('adminUserName'), '@', variables('databaseServerName'))), ':', parameters('adminPassword'))]",
125141
"databaseFqdn" : "[concat( variables('databaseServerName'), '.postgres.database.azure.com:', variables('databaseServerPort'))]",
126142
"databaseConnectionString": "[concat('pgsql://', variables('databaseUserCredentials'), '@', variables('databaseFqdn'), '/', parameters('databaseName'))]",
143+
"sendgridAccountName": "[concat(parameters('appName'),'-email')]",
127144
"appServicePlanName": "[concat(parameters('appName'),'-hosting')]",
128145
"analyticsName": "[concat(parameters('appName'),'-analytics')]",
129146
"appFqdn": "[concat(parameters('appName'),'.azurewebsites.net')]"
130147
},
131148
"resources": [
149+
{
150+
"name": "[variables('sendgridAccountName')]",
151+
"type": "Sendgrid.Email/accounts",
152+
"apiVersion": "2015-01-01",
153+
"location": "[variables('location')]",
154+
"plan": {
155+
"name": "[parameters('sendgridSku')]",
156+
"publisher": "Sendgrid",
157+
"product": "sendgrid_azure",
158+
"promotionCode": ""
159+
},
160+
"properties": {
161+
"acceptMarketingEmails": false,
162+
"email": "[parameters('adminContactEmail')]",
163+
"password": "[parameters('adminPassword')]"
164+
}
165+
},
132166
{
133167
"type": "Microsoft.Insights/components",
134168
"apiVersion": "2015-05-01",
@@ -207,6 +241,7 @@
207241
"kind": "app,linux,container",
208242
"location": "[variables('location')]",
209243
"dependsOn": [
244+
"[resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))]",
210245
"[resourceId('Microsoft.DBforPostgreSQL/servers/', variables('databaseServerName'))]",
211246
"[resourceId('Microsoft.Insights/components', variables('analyticsName'))]",
212247
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
@@ -261,6 +296,26 @@
261296
"name": "ADMIN_PASSWORD",
262297
"value": "[parameters('adminPassword')]"
263298
},
299+
{
300+
"name": "EMAIL_USE_TLS",
301+
"value": "True"
302+
},
303+
{
304+
"name": "EMAIL_HOST",
305+
"value": "[reference(resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))).smtpServer]"
306+
},
307+
{
308+
"name": "EMAIL_HOST_USER",
309+
"value": "[reference(resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))).username]"
310+
},
311+
{
312+
"name": "EMAIL_HOST_PASSWORD",
313+
"value": "[parameters('adminPassword')]"
314+
},
315+
{
316+
"name": "EMAIL_PORT",
317+
"value": "587"
318+
},
264319
{
265320
"name": "DEBUG",
266321
"value": "False"

0 commit comments

Comments
 (0)