Removing "phone" and EditContact message (ModUser could be used instead).

master
Philippe Pittoli 2023-06-12 23:24:49 +02:00
parent 641d89dd43
commit 67adb6ef51
8 changed files with 25 additions and 79 deletions

View File

@ -80,10 +80,9 @@ module AuthD
def add_user(login : String, password : String,
admin : Bool,
email : String?,
phone : String?,
profile : Hash(String, ::JSON::Any)?) : ::AuthD::User::Public | Exception
send_now Request::AddUser.new login, password, admin, email, phone, profile
send_now Request::AddUser.new login, password, admin, email, profile
response = AuthD.responses.parse_ipc_json read
@ -145,10 +144,9 @@ module AuthD
def register(login : String,
password : String,
email : String?,
phone : String?,
profile : Hash(String, ::JSON::Any)?) : ::AuthD::User::Public?
send_now Request::Register.new login, password, email, phone, profile
send_now Request::Register.new login, password, email, profile
response = AuthD.responses.parse_ipc_json read
case response
@ -158,12 +156,11 @@ module AuthD
end
end
def mod_user(uid_or_login : Int32 | String, password : String? = nil, email : String? = nil, phone : String? = nil) : Bool | Exception
def mod_user(uid_or_login : Int32 | String, password : String? = nil, email : String? = nil) : Bool | Exception
request = Request::ModUser.new uid_or_login
request.password = password if password
request.email = email if email
request.phone = phone if phone
send_now request

View File

@ -19,11 +19,13 @@ class AuthD::User
include JSON::Serializable
# the activation key is removed once the user is validated
property activation_key : String?
property activation_key : String? = nil
property email : String?
property phone : String?
def initialize(@email = nil, @phone = nil)
def initialize(@email = nil)
end
def new_activation_key
@activation_key = UUID.random.to_s
end
end

View File

@ -33,13 +33,6 @@ opt_profile = -> (parser : OptionParser) {
end
}
opt_phone = -> (parser : OptionParser) {
parser.on "-n phone", "--phone-number num", "Phone number." do |phone|
Context.phone = phone
Baguette::Log.info "Reading the user phone number: #{Context.phone}."
end
}
opt_email = -> (parser : OptionParser) {
parser.on "-e email", "--email address", "Email address." do |email|
Context.email = email
@ -49,7 +42,7 @@ opt_email = -> (parser : OptionParser) {
# Unrecognized parameters are used to create commands with multiple arguments.
# Example: user add _login email
# Example: user add login email
# Here, login and email are unrecognized arguments.
# Still, the "user add" command expect them.
unrecognized_args_to_context_args = -> (parser : OptionParser, n_expected_args : Int32) {
@ -92,20 +85,17 @@ parser = OptionParser.new do |parser|
Context.command = "user-add"
opt_authd_admin.call parser
opt_profile.call parser
opt_email.call parser
opt_phone.call parser
opt_help.call parser
# login email phone
# login email
unrecognized_args_to_context_args.call parser, 2
end
parser.on "mod", "Modify a user account." do
parser.banner = "Usage: user mod userid [-e email|-n phone|-P profile] [opt]"
parser.banner = "Usage: user mod userid [-e email|-P profile] [opt]"
Baguette::Log.info "Modify a user account."
Context.command = "user-mod"
opt_authd_admin.call parser
opt_email.call parser
opt_phone.call parser
opt_profile.call parser
opt_help.call parser
# userid
@ -167,17 +157,13 @@ parser = OptionParser.new do |parser|
# 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]"
parser.banner = "Usage: user register login email [-P profile] [opt]"
Baguette::Log.info "Register a user (requires activation)."
Context.command = "user-registration"
# These options shouldn't be used here,
# email and phone parameters are mandatory.
# opt_email.call parser
# opt_phone.call parser
opt_profile.call parser
opt_help.call parser
# login email phone
unrecognized_args_to_context_args.call parser, 3
# login email
unrecognized_args_to_context_args.call parser, 2
end
end

View File

@ -18,7 +18,6 @@ class Context
class_property command = "not-implemented"
class_property user_profile : Hash(String,JSON::Any)?
class_property phone : String?
class_property email : String?
# Will be parsed later, with a specific parser.
@ -82,21 +81,21 @@ class Actions
# TODO: login.
# By default: no phone, not admin.
pp! authd.add_user login, password.not_nil!, false, email, nil, profile: profile
# By default: not admin.
pp! authd.add_user login, password.not_nil!, false, email, profile: profile
rescue e : AuthD::Exception
puts "error: #{e.message}"
end
def user_registration
args = Context.args.not_nil!
login, email, phone = args[0..2]
login, email = args[0..1]
profile = Context.user_profile
password = Actions.ask_password
exit 1 unless password
res = authd.register login, password.not_nil!, email, phone, profile: profile
res = authd.register login, password.not_nil!, email, profile: profile
puts res
rescue e
puts "error: #{e.message}"
@ -120,14 +119,13 @@ class Actions
end
email = Context.email
phone = Context.phone
# TODO: login.
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, phone, profile: profile
# res = authd.add_user login, password, email, profile: profile
# puts res
end

View File

@ -4,10 +4,9 @@ class AuthD::Request
property password : String
property admin : Bool = false
property email : String? = nil
property phone : String? = nil
property profile : Hash(String, JSON::Any)? = nil
def initialize(@login, @password, @admin, @email, @phone, @profile)
def initialize(@login, @password, @admin, @email, @profile)
end
def handle(authd : AuthD::Service, fd : Int32)
@ -32,7 +31,6 @@ class AuthD::Request
user = User.new uid, @login, password_hash
user.contact.email = @email unless @email.nil?
user.contact.phone = @phone unless @phone.nil?
user.admin = @admin
@profile.try do |profile|
@ -54,9 +52,8 @@ class AuthD::Request
property admin : Bool? = nil
property password : String? = nil
property email : String? = nil
property phone : String? = nil
def initialize(@user, @admin, @password, @email, @phone)
def initialize(@user, @admin, @password, @email)
end
def handle(authd : AuthD::Service, fd : Int32)
@ -85,10 +82,6 @@ class AuthD::Request
user.contact.email = email
end
@phone.try do |phone|
user.contact.phone = phone
end
authd.users_per_uid.update user.uid.to_s, user
Response::UserEdited.new user.uid

View File

@ -1,32 +1,4 @@
class AuthD::Request
IPC::JSON.message EditContacts, 16 do
property email : String? = nil
property phone : String? = nil
def initialize(@email, @phone)
end
def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd
return Response::Error.new "you must be logged" if logged_user.nil?
if email = @email
# FIXME: This *should* require checking the new mail, with
# a new activation key and everything else.
logged_user.contact.email = email
end
if phone = @phone
logged_user.contact.phone = phone
end
authd.users_per_uid.update logged_user
Response::UserEdited.new logged_user.uid
end
end
AuthD.requests << EditContacts
IPC::JSON.message GetContacts, 18 do
def initialize()
end
@ -36,7 +8,7 @@ class AuthD::Request
return Response::Error.new "you must be logged" if logged_user.nil?
_c = logged_user.contact
Response::Contacts.new logged_user.uid, _c.email, _c.phone
Response::Contacts.new logged_user.uid, _c.email
end
end
AuthD.requests << GetContacts

View File

@ -3,10 +3,9 @@ class AuthD::Request
property login : String
property password : String
property email : String? = nil
property phone : String? = nil
property profile : Hash(String, JSON::Any)? = nil
def initialize(@login, @password, @email, @phone, @profile)
def initialize(@login, @password, @email, @profile)
end
def handle(authd : AuthD::Service, fd : Int32)
@ -43,7 +42,7 @@ class AuthD::Request
user = User.new uid, @login, password
user.contact.email = @email unless @email.nil?
user.contact.phone = @phone unless @phone.nil?
user.contact.new_activation_key
@profile.try do |profile|
user.profile = profile

View File

@ -2,8 +2,7 @@ class AuthD::Response
IPC::JSON.message Contacts, 12 do
property user : Int32
property email : String? = nil
property phone : String? = nil
def initialize(@user, @email, @phone)
def initialize(@user, @email)
end
end
AuthD.responses << Contacts