diff --git a/src/authd/client.cr b/src/authd/client.cr index d5858ea..5e177ef 100644 --- a/src/authd/client.cr +++ b/src/authd/client.cr @@ -142,11 +142,8 @@ module AuthD ], read end - def mod_user(uid_or_login : UserID, password : String? = nil, email : String? = nil) - request = Request::ModUser.new uid_or_login - - request.password = password if password - request.email = email if email + def mod_user(uid_or_login : UserID, password : String? = nil, email : String? = nil, admin : Bool? = nil) + request = Request::ModUser.new uid_or_login, admin, password, email send_now request parse_message [ diff --git a/src/better-parser.cr b/src/better-parser.cr index 0f0ec30..340f91d 100644 --- a/src/better-parser.cr +++ b/src/better-parser.cr @@ -127,6 +127,18 @@ parser = OptionParser.new do |parser| unrecognized_args_to_context_args.call parser, 1 end + parser.on "change-password", "Change the password of a user (requires admin)." do + parser.banner = "Usage: user change-password userid" + Baguette::Log.info "Change the password of an account." + Context.command = "user-change-password" + opt_authd_login.call parser + opt_email.call parser + opt_profile.call parser + opt_help.call parser + # userid + unrecognized_args_to_context_args.call parser, 1 + end + parser.on "delete", "Remove user." do parser.banner = "Usage: user delete userid [opt]" Baguette::Log.info "Remove user." diff --git a/src/client.cr b/src/client.cr index 68c23e5..6cc46a4 100644 --- a/src/client.cr +++ b/src/client.cr @@ -53,6 +53,7 @@ class Actions def initialize(@authd) @the_call["user-registration"] = ->user_registration @the_call["user-validation"] = ->user_validation # Do not require authentication. + @the_call["user-change-password"] = ->user_change_password @the_call["user-recovery"] = ->user_recovery # Do not require authentication. @the_call["user-delete"] = ->user_deletion # Do not require admin priviledges. @the_call["user-get"] = ->user_get @@ -191,6 +192,19 @@ class Actions puts "error: #{e.message}" end + def user_change_password + args = Context.args.not_nil! + login = args[0] + + password : String? = nil + Baguette::Log.info "new password:" + password = Actions.ask_password + exit 1 unless password + + res = authd.mod_user login, password #, email, admin + puts res + end + # TODO def user_mod args = Context.args.not_nil! @@ -213,7 +227,7 @@ class Actions Baguette::Log.error "This function shouldn't be used for now." Baguette::Log.error "It is way too cumbersome." - # res = authd.add_user login, password, email, profile: profile + # res = authd.mod_user login, password, email, admin # puts res end