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

View File

@ -19,11 +19,13 @@ class AuthD::User
include JSON::Serializable include JSON::Serializable
# the activation key is removed once the user is validated # the activation key is removed once the user is validated
property activation_key : String? property activation_key : String? = nil
property email : String? 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 @activation_key = UUID.random.to_s
end end
end end

View File

@ -33,13 +33,6 @@ opt_profile = -> (parser : OptionParser) {
end 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) { opt_email = -> (parser : OptionParser) {
parser.on "-e email", "--email address", "Email address." do |email| parser.on "-e email", "--email address", "Email address." do |email|
Context.email = email Context.email = email
@ -49,7 +42,7 @@ opt_email = -> (parser : OptionParser) {
# Unrecognized parameters are used to create commands with multiple arguments. # 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. # Here, login and email are unrecognized arguments.
# Still, the "user add" command expect them. # Still, the "user add" command expect them.
unrecognized_args_to_context_args = -> (parser : OptionParser, n_expected_args : Int32) { unrecognized_args_to_context_args = -> (parser : OptionParser, n_expected_args : Int32) {
@ -92,20 +85,17 @@ parser = OptionParser.new do |parser|
Context.command = "user-add" Context.command = "user-add"
opt_authd_admin.call parser opt_authd_admin.call parser
opt_profile.call parser opt_profile.call parser
opt_email.call parser
opt_phone.call parser
opt_help.call parser opt_help.call parser
# login email phone # login email
unrecognized_args_to_context_args.call parser, 2 unrecognized_args_to_context_args.call parser, 2
end end
parser.on "mod", "Modify a user account." do 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." Baguette::Log.info "Modify a user account."
Context.command = "user-mod" Context.command = "user-mod"
opt_authd_admin.call parser opt_authd_admin.call parser
opt_email.call parser opt_email.call parser
opt_phone.call parser
opt_profile.call parser opt_profile.call parser
opt_help.call parser opt_help.call parser
# userid # userid
@ -167,17 +157,13 @@ parser = OptionParser.new do |parser|
# Do not require to be admin. # Do not require to be admin.
parser.on "register", "Register a user (requires activation)." do 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)." Baguette::Log.info "Register a user (requires activation)."
Context.command = "user-registration" 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_profile.call parser
opt_help.call parser opt_help.call parser
# login email phone # login email
unrecognized_args_to_context_args.call parser, 3 unrecognized_args_to_context_args.call parser, 2
end end
end end

View File

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

View File

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

View File

@ -1,32 +1,4 @@
class AuthD::Request 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 IPC::JSON.message GetContacts, 18 do
def initialize() def initialize()
end end
@ -36,7 +8,7 @@ class AuthD::Request
return Response::Error.new "you must be logged" if logged_user.nil? return Response::Error.new "you must be logged" if logged_user.nil?
_c = logged_user.contact _c = logged_user.contact
Response::Contacts.new logged_user.uid, _c.email, _c.phone Response::Contacts.new logged_user.uid, _c.email
end end
end end
AuthD.requests << GetContacts AuthD.requests << GetContacts

View File

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

View File

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