Helpers to get user information and to validate it.
This commit is contained in:
parent
d8181f9926
commit
353443cd13
3 changed files with 83 additions and 4 deletions
|
@ -11,15 +11,12 @@ phone = nil
|
||||||
|
|
||||||
OptionParser.parse do |parser|
|
OptionParser.parse do |parser|
|
||||||
parser.unknown_args do |args|
|
parser.unknown_args do |args|
|
||||||
if args.size == 0 || args.size > 3
|
if args.size != 3
|
||||||
puts "usage: #{PROGRAM_NAME} <login> <email> <phone> [options]"
|
puts "usage: #{PROGRAM_NAME} <login> <email> <phone> [options]"
|
||||||
puts parser
|
puts parser
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "coucou"
|
|
||||||
pp! args
|
|
||||||
|
|
||||||
cli_login, email, phone = args[0..2]
|
cli_login, email, phone = args[0..2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
42
utils/authd-user-get.cr
Normal file
42
utils/authd-user-get.cr
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
require "option_parser"
|
||||||
|
|
||||||
|
require "../src/authd.cr"
|
||||||
|
|
||||||
|
key_file : String? = nil
|
||||||
|
cli_login : String? = nil
|
||||||
|
|
||||||
|
OptionParser.parse do |parser|
|
||||||
|
parser.unknown_args do |args|
|
||||||
|
if args.size != 1
|
||||||
|
puts "usage: #{PROGRAM_NAME} <login> [options]"
|
||||||
|
puts parser
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
cli_login = args[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
|
||||||
|
key_file = file
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-h", "--help", "Prints this help message." do
|
||||||
|
puts "usage: #{PROGRAM_NAME} <login> <email> <phone> [options]"
|
||||||
|
puts parser
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
authd = IPC::Connection.new "auth"
|
||||||
|
|
||||||
|
authd = AuthD::Client.new
|
||||||
|
authd.key = File.read(key_file.not_nil!).chomp
|
||||||
|
|
||||||
|
login = cli_login.not_nil!
|
||||||
|
|
||||||
|
pp! authd.get_user? login
|
||||||
|
rescue e
|
||||||
|
puts "Error: #{e}"
|
||||||
|
exit 1
|
||||||
|
end
|
40
utils/authd-user-validate.cr
Normal file
40
utils/authd-user-validate.cr
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require "option_parser"
|
||||||
|
|
||||||
|
require "../src/authd.cr"
|
||||||
|
|
||||||
|
key_file : String? = nil
|
||||||
|
login : String? = nil
|
||||||
|
activation_key : String? = nil
|
||||||
|
|
||||||
|
OptionParser.parse do |parser|
|
||||||
|
parser.unknown_args do |args|
|
||||||
|
if args.size != 2
|
||||||
|
puts "usage: #{PROGRAM_NAME} login activation_key [options]"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
login, activation_key = args[0..1]
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
|
||||||
|
key_file = file
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-h", "--help", "Prints this help message." do
|
||||||
|
puts "usage: #{PROGRAM_NAME} <login> <email> <phone> [options]"
|
||||||
|
puts parser
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
authd = IPC::Connection.new "auth"
|
||||||
|
|
||||||
|
authd = AuthD::Client.new
|
||||||
|
authd.key = File.read(key_file.not_nil!).chomp
|
||||||
|
|
||||||
|
pp! r = authd.validate_user login.not_nil!, activation_key.not_nil!
|
||||||
|
rescue e
|
||||||
|
puts "Error: #{e}"
|
||||||
|
exit 1
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue