Contact informations.

This commit is contained in:
Philippe PITTOLI 2020-01-22 01:55:57 +01:00
parent c69eda0ed3
commit bef2e73fff
4 changed files with 38 additions and 56 deletions

View File

@ -180,9 +180,11 @@ class AuthD::Request
property login : String property login : String
property password : String property password : String
property email : String?
property phone : String?
property profile : JSON::Any? property profile : JSON::Any?
initialize :shared_key, :login, :password, :profile initialize :shared_key, :login, :password, :email, :phone, :profile
end end
class GetUser < Request class GetUser < Request
@ -211,9 +213,11 @@ class AuthD::Request
class Request::Register < Request class Request::Register < Request
property login : String property login : String
property password : String property password : String
property email : String?
property phone : String?
property profile : JSON::Any? property profile : JSON::Any?
initialize :login, :password, :profile initialize :login, :password, :email, :phone, :profile
end end
class Request::UpdatePassword < Request class Request::UpdatePassword < Request
@ -355,8 +359,12 @@ module AuthD
end end
# FIXME: Extra options may be useful to implement here. # FIXME: Extra options may be useful to implement here.
def add_user(login : String, password : String, profile : JSON::Any?) : ::AuthD::User::Public | Exception def add_user(login : String, password : String,
send Request::AddUser.new @key, login, password, profile 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 response = Response.from_ipc read

View File

@ -12,6 +12,7 @@ extend AuthD
class AuthD::Service class AuthD::Service
property registrations_allowed = false property registrations_allowed = false
property require_email = false
@users_per_login : DODB::Index(User) @users_per_login : DODB::Index(User)
@users_per_uid : DODB::Index(User) @users_per_uid : DODB::Index(User)
@ -69,11 +70,17 @@ class AuthD::Service
return Response::Error.new "login already used" return Response::Error.new "login already used"
end end
if @require_email && request.email.nil?
return Response::Error.new "email required"
end
password_hash = hash_password request.password password_hash = hash_password request.password
uid = new_uid uid = new_uid
user = User.new uid, request.login, password_hash 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| request.profile.try do |profile|
user.profile = profile user.profile = profile
@ -272,6 +279,7 @@ end
authd_storage = "storage" authd_storage = "storage"
authd_jwt_key = "nico-nico-nii" authd_jwt_key = "nico-nico-nii"
authd_registrations = false authd_registrations = false
authd_require_email = false
begin begin
OptionParser.parse do |parser| OptionParser.parse do |parser|
@ -289,6 +297,10 @@ begin
authd_registrations = true authd_registrations = true
end end
parser.on "-E", "--require-email" do
authd_require_email = true
end
parser.on "-h", "--help", "Show this help" do parser.on "-h", "--help", "Show this help" do
puts parser puts parser
@ -298,6 +310,7 @@ begin
AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd| AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd|
authd.registrations_allowed = authd_registrations authd.registrations_allowed = authd_registrations
authd.require_email = authd_require_email
end.run end.run
rescue e : OptionParser::Exception rescue e : OptionParser::Exception
STDERR.puts e.message STDERR.puts e.message

View File

@ -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

View File

@ -16,13 +16,25 @@ class AuthD::User
end end
end end
class Contact
include JSON::Serializable
property email : String?
property phone : String?
def initialize(@email = nil, @phone = nil)
end
end
# Public. # Public.
property login : String property login : String
property uid : Int32 property uid : Int32
property profile : JSON::Any? property profile : JSON::Any?
# Private. # Private.
property contact : Contact
property password_hash : String property password_hash : String
# service => resource => permission level
property permissions : Hash(String, Hash(String, PermissionLevel)) property permissions : Hash(String, Hash(String, PermissionLevel))
property configuration : Hash(String, Hash(String, JSON::Any)) property configuration : Hash(String, Hash(String, JSON::Any))
@ -31,6 +43,7 @@ class AuthD::User
end end
def initialize(@uid, @login, @password_hash) def initialize(@uid, @login, @password_hash)
@contact = Contact.new
@permissions = Hash(String, Hash(String, PermissionLevel)).new @permissions = Hash(String, Hash(String, PermissionLevel)).new
@configuration = Hash(String, Hash(String, JSON::Any)).new @configuration = Hash(String, Hash(String, JSON::Any)).new
end end