From 67adb6ef51bcea01f01b2f8b6f989e8b63f12dfd Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 12 Jun 2023 23:24:49 +0200 Subject: [PATCH] Removing "phone" and EditContact message (ModUser could be used instead). --- src/authd/client.cr | 9 +++------ src/authd/user.cr | 8 +++++--- src/better-parser.cr | 26 ++++++-------------------- src/client.cr | 12 +++++------- src/requests/admin.cr | 11 ++--------- src/requests/contact.cr | 30 +----------------------------- src/requests/register.cr | 5 ++--- src/responses/contact.cr | 3 +-- 8 files changed, 25 insertions(+), 79 deletions(-) diff --git a/src/authd/client.cr b/src/authd/client.cr index acf0843..de2e9f6 100644 --- a/src/authd/client.cr +++ b/src/authd/client.cr @@ -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 diff --git a/src/authd/user.cr b/src/authd/user.cr index 121319e..962e2d6 100644 --- a/src/authd/user.cr +++ b/src/authd/user.cr @@ -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 diff --git a/src/better-parser.cr b/src/better-parser.cr index f7c626f..6562aa4 100644 --- a/src/better-parser.cr +++ b/src/better-parser.cr @@ -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 diff --git a/src/client.cr b/src/client.cr index e7e952a..87ec462 100644 --- a/src/client.cr +++ b/src/client.cr @@ -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 diff --git a/src/requests/admin.cr b/src/requests/admin.cr index 494d028..e972110 100644 --- a/src/requests/admin.cr +++ b/src/requests/admin.cr @@ -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 diff --git a/src/requests/contact.cr b/src/requests/contact.cr index 12497b1..db9ccf1 100644 --- a/src/requests/contact.cr +++ b/src/requests/contact.cr @@ -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 diff --git a/src/requests/register.cr b/src/requests/register.cr index ca162b6..9383452 100644 --- a/src/requests/register.cr +++ b/src/requests/register.cr @@ -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 diff --git a/src/responses/contact.cr b/src/responses/contact.cr index 8fb3285..cc6409e 100644 --- a/src/responses/contact.cr +++ b/src/responses/contact.cr @@ -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