From ad77da0f8792c61c9e9cff245a02d60605b9fdad Mon Sep 17 00:00:00 2001
From: Lionel Trebuchon
Date: Sun, 1 Dec 2019 16:52:39 +0100
Subject: [PATCH] Trial to trigger the registration confirmation per email
---
README.md | 4 ++--
amivapi/events/email_links.py | 10 ++++++----
amivapi/events/templates/unregister_event.html | 2 +-
amivapi/settings.py | 5 +++--
amivapi/tests/events/test_emails.py | 4 +++-
5 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index abffa755..bc22b349 100644
--- a/README.md
+++ b/README.md
@@ -191,7 +191,7 @@ variable `AMIVAPI_CONFIG` to specify the config path in the container.)
If you have installed AMIV API locally, you can use the CLI to start it.
First, change `MONGO_HOST = 'mongodb'` in `config.py` to `'MONGO_HOST = 'localhost'`.
-Then, in CLI:
+Then, in CLI (with the environment active):
```sh
amivapi run dev # Start development server
@@ -210,7 +210,7 @@ amivapi run --help
If you have docker installed you can simply run the tests in a Docker instance:
```sh
-./run_tests.sh
+./run_tests.sh # potentially try with sudo
```
By default, this will start a container with mongodb, and run
diff --git a/amivapi/events/email_links.py b/amivapi/events/email_links.py
index 78b51132..98da250d 100644
--- a/amivapi/events/email_links.py
+++ b/amivapi/events/email_links.py
@@ -11,7 +11,8 @@
from bson import ObjectId
from eve.methods.delete import deleteitem_internal
from eve.methods.patch import patch_internal
-from flask import Blueprint, current_app, redirect, request, make_response, render_template, g
+from flask import Blueprint, current_app, redirect, make_response,\
+ render_template
from itsdangerous import BadSignature, URLSafeSerializer
from amivapi.events.queue import update_waiting_list
@@ -78,7 +79,7 @@ def on_delete_signup(token):
query = {'_id': signup_id}
data_signup = current_app.data.driver.db['eventsignups'].find_one(query)
if data_signup is None:
- error_msg = "This event might not exist anymore, or the link is broken, or we made a mistake."
+ error_msg = "This event might not exist anymore or the link is broken."
user = data_signup['user']
if user is None:
user = data_signup['email']
@@ -95,7 +96,8 @@ def on_delete_signup(token):
if data_event["time_start"] is None:
event_date = "a yet undefined day."
else:
- event_date = datetime.strftime(data_event["time_start"], '%Y-%m-%d %H:%M')
+ event_date = datetime.strftime(data_event["time_start"],
+ '%Y-%m-%d %H:%M')
# Serve the unregister_event page
response = make_response(render_template("unregister_event.html",
user=user,
@@ -107,7 +109,7 @@ def on_delete_signup(token):
return response
-@email_blueprint.route('/delete_confirmed/', methods = ['POST'])
+@email_blueprint.route('/delete_confirmed/', methods=['POST'])
def on_delete_confirmed(token):
try:
s = URLSafeSerializer(get_token_secret())
diff --git a/amivapi/events/templates/unregister_event.html b/amivapi/events/templates/unregister_event.html
index 6a60dc31..b0b61142 100644
--- a/amivapi/events/templates/unregister_event.html
+++ b/amivapi/events/templates/unregister_event.html
@@ -33,7 +33,7 @@
Is that ok?
{% else %}
You clicked on a opt-out link of the AMIV at ETHZ student organization. We cannot process your request,
- because we either do {not} know the event you wish to unregister from, or your user name, or both.
+ because we either do not know the event you wish to unregister from, or your user name, or both.
{% endif %}
diff --git a/amivapi/settings.py b/amivapi/settings.py
index 657ca71c..9724606e 100644
--- a/amivapi/settings.py
+++ b/amivapi/settings.py
@@ -62,13 +62,14 @@
REMOTE_MAILING_LIST_ADDRESS = None
REMOTE_MAILING_LIST_KEYFILE = None
REMOTE_MAILING_LIST_DIR = './' # Use home directory on remote by default
-# Signups via email (@email_blueprint.route('/delete_signup/') in email_links.py)
+# Signups via email (@email_blueprint.route('/delete_signup/')
+# in email_links.py)
# DEFINITIVE_DELETE = ''
# SMTP server defaults
API_MAIL = 'api@amiv.ethz.ch'
API_MAIL_SUBJECT = "[AMIV] {subject}"
-SMTP_HOST = 'localhost' # None in case you want to accept that no mails get sent (local testing)
+SMTP_HOST = 'localhost'
SMTP_PORT = 587
SMTP_TIMEOUT = 10
diff --git a/amivapi/tests/events/test_emails.py b/amivapi/tests/events/test_emails.py
index 5a79215e..f7e87777 100644
--- a/amivapi/tests/events/test_emails.py
+++ b/amivapi/tests/events/test_emails.py
@@ -56,7 +56,9 @@ def test_email_signup_delete(self):
# With redirect set
self.app.config['SIGNUP_DELETED_REDIRECT'] = "somewhere"
- self.api.get('/delete_signup/%s' % token, status_code=302)
+ self.api.get('/eventsignups/%s' % signup['_id'], status_code=200) # sanity check
+ self.api.get('/delete_signup/%s' % token, status_code=200)
+ self.api.post('/delete_confirmed/%s' % token, status_code=200)
# Check that signup was deleted
self.api.get('/eventsignups/%s' % signup['_id'], status_code=404)