Authd: mailer options added.

This commit is contained in:
Karchnu 2020-05-08 14:50:15 +02:00
parent ad7609a0f1
commit 2ed19632f2

View File

@ -16,6 +16,9 @@ extend AuthD
class AuthD::Service class AuthD::Service
property registrations_allowed = false property registrations_allowed = false
property require_email = false property require_email = false
property mailer_activation_url : String? = nil
property mailer_field_from : String? = nil
property mailer_field_subject : String? = nil
@users_per_login : DODB::Index(User) @users_per_login : DODB::Index(User)
@users_per_uid : DODB::Index(User) @users_per_uid : DODB::Index(User)
@ -228,16 +231,24 @@ class AuthD::Service
user.date_registration = Time.local user.date_registration = Time.local
unless (mailer_activation_url = @mailer_activation_url).nil?
mailer_field_subject = @mailer_field_subject.not_nil!
mailer_field_from = @mailer_field_from.not_nil!
mailer_activation_url = @mailer_activation_url.not_nil!
# Once the user is created and stored, we try to contact him # Once the user is created and stored, we try to contact him
unless Process.run("activation-mailer", [ unless Process.run("activation-mailer", [
"-l", user.login, "-l", user.login,
"-e", user.contact.email.not_nil!, "-e", user.contact.email.not_nil!,
"-t", "Activation email", "-t", mailer_field_subject,
"-f", "karchnu@localhost", "-f", mailer_field_from,
"-u", mailer_activation_url,
"-a", user.contact.activation_key.not_nil! "-a", user.contact.activation_key.not_nil!
]).success? ]).success?
return Response::Error.new "cannot contact the user (but still registered)" return Response::Error.new "cannot contact the user (but still registered)"
end end
end
# add the user only if we were able to send the confirmation mail # add the user only if we were able to send the confirmation mail
@users << user @users << user
@ -346,16 +357,23 @@ class AuthD::Service
@users_per_uid.update user.uid.to_s, user @users_per_uid.update user.uid.to_s, user
unless (mailer_activation_url = @mailer_activation_url).nil?
mailer_field_from = @mailer_field_from.not_nil!
mailer_activation_url = @mailer_activation_url.not_nil!
# Once the user is created and stored, we try to contact him # Once the user is created and stored, we try to contact him
unless Process.run("password-recovery-mailer", [ unless Process.run("password-recovery-mailer", [
"-l", user.login, "-l", user.login,
"-e", user.contact.email.not_nil!, "-e", user.contact.email.not_nil!,
"-t", "Password recovery email", "-t", "Password recovery email",
"-f", "karchnu@localhost", "-f", mailer_field_from,
"-u", mailer_activation_url,
"-a", user.password_renew_key.not_nil! "-a", user.password_renew_key.not_nil!
]).success? ]).success?
return Response::Error.new "cannot contact the user for password recovery" return Response::Error.new "cannot contact the user for password recovery"
end end
end
Response::PasswordRecoverySent.new user.to_public Response::PasswordRecoverySent.new user.to_public
when Request::PasswordRecovery when Request::PasswordRecovery
@ -461,6 +479,9 @@ authd_storage = "storage"
authd_jwt_key = "nico-nico-nii" authd_jwt_key = "nico-nico-nii"
authd_registrations = false authd_registrations = false
authd_require_email = false authd_require_email = false
activation_url : String? = nil
field_subject : String? = nil
field_from : String? = nil
begin begin
OptionParser.parse do |parser| OptionParser.parse do |parser|
@ -482,6 +503,18 @@ begin
authd_require_email = true authd_require_email = true
end end
parser.on "-t subject", "--subject title", "Subject of the email." do |s|
field_subject = s
end
parser.on "-f from-email", "--from email", "'From:' field to use in activation email." do |f|
field_from = f
end
parser.on "-u", "--activation-url url", "Activation URL." do |opt|
activation_url = opt
end
parser.on "-h", "--help", "Show this help" do parser.on "-h", "--help", "Show this help" do
puts parser puts parser
@ -492,6 +525,9 @@ begin
AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd| AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd|
authd.registrations_allowed = authd_registrations authd.registrations_allowed = authd_registrations
authd.require_email = authd_require_email authd.require_email = authd_require_email
authd.mailer_activation_url = activation_url
authd.mailer_field_subject = field_subject
authd.mailer_field_from = field_from
end.run end.run
rescue e : OptionParser::Exception rescue e : OptionParser::Exception
STDERR.puts e.message STDERR.puts e.message