From 194abdd1f9188cc0b101994f2324314543292ddd Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 13 Oct 2020 17:42:28 +0200 Subject: [PATCH] recovery get search validate --- src/authd.cr | 4 ++-- utils/authc.cr | 29 +++++++++++++++++++--------- utils/better-parser.cr | 43 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/authd.cr b/src/authd.cr index 906922a..fa98c10 100644 --- a/src/authd.cr +++ b/src/authd.cr @@ -496,8 +496,8 @@ module AuthD end end - def ask_password_recovery(uid_or_login : String | Int32) - send Request::AskPasswordRecovery.new uid_or_login + def ask_password_recovery(uid_or_login : String | Int32, email : String) + send Request::AskPasswordRecovery.new uid_or_login, email response = Response.from_ipc read case response diff --git a/utils/authc.cr b/utils/authc.cr index 0a8095a..cb56d4a 100644 --- a/utils/authc.cr +++ b/utils/authc.cr @@ -69,6 +69,10 @@ class Actions @the_call["user-mod"] = ->user_mod @the_call["user-registration"] = ->user_registration # Do not require admin priviledges. @the_call["user-delete"] = ->user_deletion # Do not require admin priviledges. + @the_call["user-get"] = ->user_get # Do not require authentication. + @the_call["user-validation"] = ->user_validation # Do not require authentication. + @the_call["user-recovery"] = ->user_recovery # Do not require authentication. + @the_call["user-search"] = ->user_search # Do not require authentication. @the_call["permission-set"] = ->permission_set @the_call["permission-check"] = ->permission_check @@ -148,18 +152,25 @@ class Actions puts res end - # TODO - def validate - # pp! r = authd.validate_user login.not_nil!, activation_key.not_nil! + def user_validation + args = Context.args.not_nil! + login, activation_key = args[0..1] + pp! authd.validate_user login, activation_key end - def search - # pp! r = authd.search_user login.not_nil! + def user_search + args = Context.args.not_nil! + login = args[0] + pp! authd.search_user login end - def get - # pp! authd.get_user? login + def user_get + args = Context.args.not_nil! + login = args[0] + pp! authd.get_user? login end - def ask_password_recovery - # pp! authd.ask_password_recovery login + def user_recovery + args = Context.args.not_nil! + login, email = args[0..1] + pp! authd.ask_password_recovery login, email end def permission_check diff --git a/utils/better-parser.cr b/utils/better-parser.cr index 37ac85d..f6263ca 100644 --- a/utils/better-parser.cr +++ b/utils/better-parser.cr @@ -82,7 +82,7 @@ parser = OptionParser.new do |parser| end parser.on "user", "Operations on users." do - parser.banner = "Usage: user [add | mod | delete]" + parser.banner = "Usage: user [add | mod | delete | validate | search | get | recover | register ]" parser.on "add", "Adding a user to the DB." do parser.banner = "usage: user add login email phone [-P profile] [opt]" @@ -122,6 +122,47 @@ parser = OptionParser.new do |parser| unrecognized_args_to_context_args.call parser, 1 end + parser.on "validate", "Validate user." do + parser.banner = "Usage: user validate login activation-key [opt]" + Baguette::Log.info "Validate user." + Context.command = "user-validate" + # No need to be authenticated. + opt_help.call parser + # login activation-key + unrecognized_args_to_context_args.call parser, 2 + end + + parser.on "get", "Get user info." do + parser.banner = "Usage: user get login [opt]" + Baguette::Log.info "Get user info." + Context.command = "user-get" + # No need to be authenticated. + opt_help.call parser + # login + unrecognized_args_to_context_args.call parser, 1 + end + + parser.on "search", "Search user." do + parser.banner = "Usage: user recover login [opt]" + Baguette::Log.info "Search user." + Context.command = "user-search" + # No need to be authenticated. + opt_help.call parser + # login + unrecognized_args_to_context_args.call parser, 1 + end + + parser.on "recover", "Recover user password." do + parser.banner = "Usage: user recover login email [opt]" + Baguette::Log.info "Recover user password." + Context.command = "user-recovery" + # No need to be authenticated. + opt_help.call parser + # login email + unrecognized_args_to_context_args.call parser, 2 + end + + # Do not require to be admin. parser.on "register", "Register a user (requires activation)." do parser.banner = "Usage: user register login email phone [-P profile] [opt]"