Client can now register users.

master
Philippe Pittoli 2023-06-15 00:41:22 +02:00
parent 719e47a28d
commit 03b0b7a95b
2 changed files with 38 additions and 6 deletions

View File

@ -100,7 +100,14 @@ module AuthD
profile : Hash(String, ::JSON::Any)?)
send_now Request::Register.new login, password, email, profile
parse_message [Response::UserAdded], read
parse_message [Response::UserAdded,
Response::ErrorRegistrationsClosed,
Response::ErrorAlreadyUsedLogin,
Response::ErrorInvalidLoginFormat,
Response::ErrorMailRequired,
Response::ErrorInvalidEmailFormat,
Response::ErrorCannotContactUser,
Response::ErrorPasswordTooShort], read
end
def mod_user(uid_or_login : UserID, password : String? = nil, email : String? = nil)

View File

@ -74,7 +74,6 @@ class Actions
#
def user_add
puts "User add!!!"
args = Context.args.not_nil!
login, email = args[0..1]
profile = Context.user_profile
@ -82,8 +81,6 @@ class Actions
password = Actions.ask_password
exit 1 unless password
# TODO: login.
# By default: not admin.
pp! authd.add_user login, password.not_nil!, false, email, profile: profile
rescue e : AuthD::Exception
@ -96,10 +93,38 @@ class Actions
profile = Context.user_profile
password = Actions.ask_password
exit 1 unless password
unless password
Baguette::Log.error "no password!"
exit 1
end
res = authd.register login, password.not_nil!, email, profile: profile
puts res
case res
when Response::UserAdded
Baguette::Log.info "User registered, mail sent"
exit 0
when Response::ErrorRegistrationsClosed
Baguette::Log.error "ErrorRegistrationsClosed"
exit 1
when Response::ErrorAlreadyUsedLogin
Baguette::Log.error "ErrorAlreadyUsedLogin"
exit 1
when Response::ErrorMailRequired
Baguette::Log.error "ErrorMailRequired"
exit 1
when Response::ErrorInvalidEmailFormat
Baguette::Log.error "ErrorInvalidEmailFormat"
exit 1
when Response::ErrorCannotContactUser
Baguette::Log.error "ErrorCannotContactUser"
exit 1
when Response::ErrorInvalidLoginFormat
Baguette::Log.warning "Invalid login!"
exit 1
when Response::ErrorPasswordTooShort
Baguette::Log.warning "Password too short!"
exit 1
end
rescue e
puts "error: #{e.message}"
end