diff --git a/src/authd.cr b/src/authd.cr index 4823c7e..5d00cf8 100644 --- a/src/authd.cr +++ b/src/authd.cr @@ -180,9 +180,11 @@ class AuthD::Request property login : String property password : String + property email : String? + property phone : String? property profile : JSON::Any? - initialize :shared_key, :login, :password, :profile + initialize :shared_key, :login, :password, :email, :phone, :profile end class GetUser < Request @@ -211,9 +213,11 @@ class AuthD::Request class Request::Register < Request property login : String property password : String + property email : String? + property phone : String? property profile : JSON::Any? - initialize :login, :password, :profile + initialize :login, :password, :email, :phone, :profile end class Request::UpdatePassword < Request @@ -355,8 +359,12 @@ module AuthD end # FIXME: Extra options may be useful to implement here. - def add_user(login : String, password : String, profile : JSON::Any?) : ::AuthD::User::Public | Exception - send Request::AddUser.new @key, login, password, profile + def add_user(login : String, password : String, + email : String?, + phone : String?, + profile : JSON::Any?) : ::AuthD::User::Public | Exception + + send Request::AddUser.new @key, login, password, email, phone, profile response = Response.from_ipc read diff --git a/src/main.cr b/src/main.cr index b842de8..aec7c9d 100644 --- a/src/main.cr +++ b/src/main.cr @@ -12,6 +12,7 @@ extend AuthD class AuthD::Service property registrations_allowed = false + property require_email = false @users_per_login : DODB::Index(User) @users_per_uid : DODB::Index(User) @@ -69,11 +70,17 @@ class AuthD::Service return Response::Error.new "login already used" end + if @require_email && request.email.nil? + return Response::Error.new "email required" + end + password_hash = hash_password request.password uid = new_uid user = User.new uid, request.login, password_hash + user.contact.email = request.email + user.contact.phone = request.phone unless request.phone.nil? request.profile.try do |profile| user.profile = profile @@ -272,6 +279,7 @@ end authd_storage = "storage" authd_jwt_key = "nico-nico-nii" authd_registrations = false +authd_require_email = false begin OptionParser.parse do |parser| @@ -289,6 +297,10 @@ begin authd_registrations = true end + parser.on "-E", "--require-email" do + authd_require_email = true + end + parser.on "-h", "--help", "Show this help" do puts parser @@ -298,6 +310,7 @@ begin AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd| authd.registrations_allowed = authd_registrations + authd.require_email = authd_require_email end.run rescue e : OptionParser::Exception STDERR.puts e.message diff --git a/src/storage.cr b/src/storage.cr deleted file mode 100644 index e37d44e..0000000 --- a/src/storage.cr +++ /dev/null @@ -1,52 +0,0 @@ -require "json" - -class AuthD::User - include JSON::Serializable - - property login : String - property password_hash : String? - property uid : Int32 - - property mail_address : String - - # FIXME: How would this profile be extended, replaced, checked? - property profile : Profile - - class Profile - include JSON::Serializable - - property full_name : String? - property description : String? - property avatar : String? - property website : String? - end - - property registration_date : Time - - property groups : Array(String) - - # application name => configuration object - property configuration : Hash(String, JSON::Any) -end - -class AuthD::Group - include JSON::Serializable - - property name : String - property gid : Int32 - property members : Array(String) -end - -class AuthD::Storage - # FIXME: Create new groups and users, generate their ids. - def initialize(@storage_root) - @users = DODB::Hash(Int32, User).new "#{@storage_root}/users" - @users_by_login = @users.new_index "login", &.login - @users_by_group = @users.new_tags "groups", &.groups - - @groups = DODB::Hash(Int32, Group).new "#{@storage_root}/groups" - @groups_by_name = new_index "name", &.name - @groups_by_member = new_tags "members", &.members - end -end - diff --git a/src/user.cr b/src/user.cr index 5501df3..9c48aa0 100644 --- a/src/user.cr +++ b/src/user.cr @@ -16,13 +16,25 @@ class AuthD::User end end + class Contact + include JSON::Serializable + + property email : String? + property phone : String? + + def initialize(@email = nil, @phone = nil) + end + end + # Public. property login : String property uid : Int32 property profile : JSON::Any? # Private. + property contact : Contact property password_hash : String + # service => resource => permission level property permissions : Hash(String, Hash(String, PermissionLevel)) property configuration : Hash(String, Hash(String, JSON::Any)) @@ -31,6 +43,7 @@ class AuthD::User end def initialize(@uid, @login, @password_hash) + @contact = Contact.new @permissions = Hash(String, Hash(String, PermissionLevel)).new @configuration = Hash(String, Hash(String, JSON::Any)).new end