Deletion: WIP
This commit is contained in:
parent
c3d5aef951
commit
90ccd50c80
30
src/authd.cr
30
src/authd.cr
@ -344,6 +344,19 @@ class AuthD::Request
|
||||
property phone : String?
|
||||
end
|
||||
|
||||
class Delete < Request
|
||||
# Deletion can be triggered by either an admin or the user.
|
||||
property shared_key : String?
|
||||
|
||||
property login : String?
|
||||
property password : String?
|
||||
|
||||
property user : String | Int32
|
||||
|
||||
initialize :user, :login, :password
|
||||
initialize :user, :shared_key
|
||||
end
|
||||
|
||||
# This creates a Request::Type enumeration. One entry for each request type.
|
||||
{% begin %}
|
||||
enum Type
|
||||
@ -608,6 +621,23 @@ module AuthD
|
||||
raise Exception.new "unexpected response"
|
||||
end
|
||||
end
|
||||
|
||||
def delete(user : Int32 | String, key : String)
|
||||
send Request::Delete.new user, key
|
||||
delete_
|
||||
end
|
||||
def delete(user : Int32 | String, login : String, pass : String)
|
||||
send Request::Delete.new user, login, pass
|
||||
delete_
|
||||
end
|
||||
def delete_
|
||||
response = Response.from_ipc read
|
||||
case response
|
||||
when Response::Error
|
||||
raise Exception.new response.reason
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -79,15 +79,8 @@ class Actions
|
||||
# For all functions: the number of arguments is already tested.
|
||||
#
|
||||
|
||||
def user_registration
|
||||
# pp! authd.register login, password.not_nil!, email, phone, profile: profile
|
||||
rescue e : AuthD::Exception
|
||||
puts "error: #{e.message}"
|
||||
end
|
||||
def user_deletion
|
||||
end
|
||||
|
||||
def user_add
|
||||
puts "User add!!!"
|
||||
args = Context.args.not_nil!
|
||||
login, email, phone = args[0..2]
|
||||
profile = Context.user_profile
|
||||
@ -100,6 +93,20 @@ class Actions
|
||||
puts "error: #{e.message}"
|
||||
end
|
||||
|
||||
def user_registration
|
||||
args = Context.args.not_nil!
|
||||
login, email, phone = args[0..2]
|
||||
profile = Context.user_profile
|
||||
|
||||
password = Actions.ask_password
|
||||
exit 1 unless password
|
||||
|
||||
res = authd.register login, password.not_nil!, email, phone, profile: profile
|
||||
puts res
|
||||
rescue e : AuthD::Exception
|
||||
puts "error: #{e.message}"
|
||||
end
|
||||
|
||||
# TODO
|
||||
def user_mod
|
||||
args = Context.args.not_nil!
|
||||
@ -127,6 +134,20 @@ class Actions
|
||||
# puts res
|
||||
end
|
||||
|
||||
def user_deletion
|
||||
args = Context.args.not_nil!
|
||||
userid = args[0]
|
||||
|
||||
# Check if the request comes from an admin or the user.
|
||||
res = if Context.shared_key.nil?
|
||||
authd.delete userid, Context.authd_login, Context.authd_pass
|
||||
else
|
||||
authd.delete userid, Context.shared_key
|
||||
end
|
||||
|
||||
puts res
|
||||
end
|
||||
|
||||
# TODO
|
||||
def validate
|
||||
# pp! r = authd.validate_user login.not_nil!, activation_key.not_nil!
|
||||
|
@ -111,13 +111,15 @@ parser = OptionParser.new do |parser|
|
||||
end
|
||||
|
||||
parser.on "delete", "Remove user." do
|
||||
parser.banner = "Usage: user delete -u userid [opt]"
|
||||
parser.banner = "Usage: user delete userid [opt]"
|
||||
Baguette::Log.info "Remove user."
|
||||
Context.command = "delete"
|
||||
# You can either be the owner of the account, or an admin.
|
||||
opt_authd_login.call parser
|
||||
opt_authd_admin.call parser
|
||||
opt_help.call parser
|
||||
# userid
|
||||
unrecognized_args_to_context_args.call parser, 1
|
||||
end
|
||||
|
||||
# Do not require to be admin.
|
||||
|
Loading…
Reference in New Issue
Block a user