From e789a16ac6476ad0f172296fb5ce7443226f26d1 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Thu, 23 Jan 2020 15:45:05 +0100
Subject: [PATCH] Run the activation-mailer.
---
src/main.cr | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/main.cr b/src/main.cr
index 572fac0..08e8203 100644
--- a/src/main.cr
+++ b/src/main.cr
@@ -82,14 +82,24 @@ class AuthD::Service
user.contact.email = request.email
user.contact.phone = request.phone unless request.phone.nil?
- pp! user
-
request.profile.try do |profile|
user.profile = profile
end
@users << user
+ # Once the user is created and stored, we try to contact him
+ # TODO: send a mail
+ unless Process.run("activation-mailer", [
+ "-l", user.login,
+ "-e", user.contact.email.not_nil!,
+ "-t", "Activation email",
+ "-f", "karchnu@localhost",
+ "-a", user.contact.activation_key.not_nil!
+ ]).success?
+ return Response::Error.new "cannot contact the user"
+ end
+
Response::UserAdded.new user.to_public
when Request::ValidateUser
if request.shared_key != @jwt_key
@@ -102,6 +112,10 @@ class AuthD::Service
return Response::Error.new "user not found"
end
+ if user.contact.activation_key.nil?
+ return Response::Error.new "user already validated"
+ end
+
# remove the user contact activation key: the email is validated
if user.contact.activation_key == request.activation_key
user.contact.activation_key = nil