Add mail feature to password reset

Message ID 20171101185418.10946-1-jonatan.schlag@ipfire.org
State New
Headers show
Series
  • Add mail feature to password reset
Related show

Commit Message

Jonatan Schlag Nov. 2, 2017, 5:54 a.m. UTC
We can now send an email with an reset code.

Fixes: #10095

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 Makefile.am                                          |  3 ++-
 src/buildservice/users.py                            |  5 ++---
 src/templates/messages/users/password-reset.markdown | 10 ++++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 src/templates/messages/users/password-reset.markdown

Patch

diff --git a/Makefile.am b/Makefile.am
index cf6c610..918178e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -255,7 +255,8 @@  templates_messages_jobsdir = $(templates_messagesdir)/jobs
 
 dist_templates_messages_users_DATA = \
 	src/templates/messages/users/account-activation.markdown \
-	src/templates/messages/users/email-activation.markdown
+	src/templates/messages/users/email-activation.markdown \
+	src/templates/messages/users/password-reset.markdown
 
 templates_messages_usersdir = $(templates_messagesdir)/users
 
diff --git a/src/buildservice/users.py b/src/buildservice/users.py
index a886b82..01cf497 100644
--- a/src/buildservice/users.py
+++ b/src/buildservice/users.py
@@ -474,9 +474,8 @@  class User(base.DataObject):
 		# Add a recovery code to the database and a timestamp when this code expires
 		self.password_recovery_code = generate_random_string(64)
 
-		# XXX
-		# We should send an email with the activation code
-
+		# Send an email with the activation code
+		self.send_template("messages/users/password-reset", user=self)
 
 	@property
 	def activated(self):
diff --git a/src/templates/messages/users/password-reset.markdown b/src/templates/messages/users/password-reset.markdown
new file mode 100644
index 0000000..b4f9fdf
--- /dev/null
+++ b/src/templates/messages/users/password-reset.markdown
@@ -0,0 +1,10 @@ 
+Subject: {{ _("Password Reset") }}
+
+{{ _("You, or somebody else has requested a password reset for the Pakfire Build Service.") }}
+
+{{ _("To reset your password, please click on the link below:") }}
+
+  {{ baseurl }}/password-reset?code={{ user.password_recovery_code }}
+
+Sincerely,  
+-The Pakfire Build Service