User password can be given on cli for automatic user creation.
This commit is contained in:
parent
810c224fae
commit
ad7609a0f1
1 changed files with 15 additions and 8 deletions
|
@ -8,6 +8,7 @@ profile_file : String? = nil
|
||||||
register = false
|
register = false
|
||||||
email = nil
|
email = nil
|
||||||
phone = nil
|
phone = nil
|
||||||
|
password : String? = nil
|
||||||
|
|
||||||
OptionParser.parse do |parser|
|
OptionParser.parse do |parser|
|
||||||
parser.unknown_args do |args|
|
parser.unknown_args do |args|
|
||||||
|
@ -24,6 +25,10 @@ OptionParser.parse do |parser|
|
||||||
profile_file = file
|
profile_file = file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on "-X user-password", "--user-password pass", "Read the new user password." do |pass|
|
||||||
|
password = pass
|
||||||
|
end
|
||||||
|
|
||||||
parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
|
parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
|
||||||
key_file = file
|
key_file = file
|
||||||
end
|
end
|
||||||
|
@ -55,13 +60,15 @@ profile = profile_file.try do |file|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
STDOUT << "password: "
|
if password.nil?
|
||||||
STDOUT << `stty -echo`
|
STDOUT << "password: "
|
||||||
STDOUT.flush
|
STDOUT << `stty -echo`
|
||||||
password = STDIN.gets.try &.chomp
|
STDOUT.flush
|
||||||
|
password = STDIN.gets.try &.chomp
|
||||||
|
|
||||||
STDOUT << '\n'
|
STDOUT << '\n'
|
||||||
STDOUT << `stty echo`
|
STDOUT << `stty echo`
|
||||||
|
end
|
||||||
|
|
||||||
exit 1 unless password
|
exit 1 unless password
|
||||||
|
|
||||||
|
@ -72,13 +79,13 @@ phone = nil if phone == ""
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if register
|
if register
|
||||||
pp! authd.register login, password, email, phone, profile: profile
|
pp! authd.register login, password.not_nil!, email, phone, profile: profile
|
||||||
else
|
else
|
||||||
key_file.try do |file| # FIXME: fail if missing?
|
key_file.try do |file| # FIXME: fail if missing?
|
||||||
authd.key = File.read(file).chomp
|
authd.key = File.read(file).chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
pp! authd.add_user login, password, email, phone, profile: profile
|
pp! authd.add_user login, password.not_nil!, email, phone, profile: profile
|
||||||
end
|
end
|
||||||
rescue e : AuthD::Exception
|
rescue e : AuthD::Exception
|
||||||
puts "error: #{e.message}"
|
puts "error: #{e.message}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue