Authd: mailer options added.
This commit is contained in:
parent
ad7609a0f1
commit
2ed19632f2
72
src/main.cr
72
src/main.cr
@ -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,15 +231,23 @@ class AuthD::Service
|
|||||||
|
|
||||||
user.date_registration = Time.local
|
user.date_registration = Time.local
|
||||||
|
|
||||||
# Once the user is created and stored, we try to contact him
|
unless (mailer_activation_url = @mailer_activation_url).nil?
|
||||||
unless Process.run("activation-mailer", [
|
|
||||||
"-l", user.login,
|
mailer_field_subject = @mailer_field_subject.not_nil!
|
||||||
"-e", user.contact.email.not_nil!,
|
mailer_field_from = @mailer_field_from.not_nil!
|
||||||
"-t", "Activation email",
|
mailer_activation_url = @mailer_activation_url.not_nil!
|
||||||
"-f", "karchnu@localhost",
|
|
||||||
"-a", user.contact.activation_key.not_nil!
|
# Once the user is created and stored, we try to contact him
|
||||||
]).success?
|
unless Process.run("activation-mailer", [
|
||||||
return Response::Error.new "cannot contact the user (but still registered)"
|
"-l", user.login,
|
||||||
|
"-e", user.contact.email.not_nil!,
|
||||||
|
"-t", mailer_field_subject,
|
||||||
|
"-f", mailer_field_from,
|
||||||
|
"-u", mailer_activation_url,
|
||||||
|
"-a", user.contact.activation_key.not_nil!
|
||||||
|
]).success?
|
||||||
|
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
|
||||||
@ -346,15 +357,22 @@ class AuthD::Service
|
|||||||
|
|
||||||
@users_per_uid.update user.uid.to_s, user
|
@users_per_uid.update user.uid.to_s, user
|
||||||
|
|
||||||
# Once the user is created and stored, we try to contact him
|
unless (mailer_activation_url = @mailer_activation_url).nil?
|
||||||
unless Process.run("password-recovery-mailer", [
|
|
||||||
"-l", user.login,
|
mailer_field_from = @mailer_field_from.not_nil!
|
||||||
"-e", user.contact.email.not_nil!,
|
mailer_activation_url = @mailer_activation_url.not_nil!
|
||||||
"-t", "Password recovery email",
|
|
||||||
"-f", "karchnu@localhost",
|
# Once the user is created and stored, we try to contact him
|
||||||
"-a", user.password_renew_key.not_nil!
|
unless Process.run("password-recovery-mailer", [
|
||||||
]).success?
|
"-l", user.login,
|
||||||
return Response::Error.new "cannot contact the user for password recovery"
|
"-e", user.contact.email.not_nil!,
|
||||||
|
"-t", "Password recovery email",
|
||||||
|
"-f", mailer_field_from,
|
||||||
|
"-u", mailer_activation_url,
|
||||||
|
"-a", user.password_renew_key.not_nil!
|
||||||
|
]).success?
|
||||||
|
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
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user