2019-05-29 15:30:23 +02:00
|
|
|
require "json"
|
|
|
|
|
2019-12-15 23:38:49 +01:00
|
|
|
require "./token.cr"
|
|
|
|
|
|
|
|
class AuthD::User
|
|
|
|
include JSON::Serializable
|
|
|
|
|
|
|
|
enum PermissionLevel
|
|
|
|
None
|
|
|
|
Read
|
|
|
|
Edit
|
|
|
|
Admin
|
|
|
|
|
|
|
|
def to_json(o)
|
|
|
|
to_s.downcase.to_json o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-22 01:55:57 +01:00
|
|
|
class Contact
|
|
|
|
include JSON::Serializable
|
|
|
|
|
|
|
|
property email : String?
|
|
|
|
property phone : String?
|
|
|
|
|
|
|
|
def initialize(@email = nil, @phone = nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-15 23:38:49 +01:00
|
|
|
# Public.
|
|
|
|
property login : String
|
|
|
|
property uid : Int32
|
|
|
|
property profile : JSON::Any?
|
|
|
|
|
|
|
|
# Private.
|
2020-01-22 01:55:57 +01:00
|
|
|
property contact : Contact
|
2019-12-15 23:38:49 +01:00
|
|
|
property password_hash : String
|
2020-01-22 01:55:57 +01:00
|
|
|
# service => resource => permission level
|
2019-12-15 23:38:49 +01:00
|
|
|
property permissions : Hash(String, Hash(String, PermissionLevel))
|
|
|
|
property configuration : Hash(String, Hash(String, JSON::Any))
|
|
|
|
|
|
|
|
def to_token
|
|
|
|
Token.new @login, @uid
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(@uid, @login, @password_hash)
|
2020-01-22 01:55:57 +01:00
|
|
|
@contact = Contact.new
|
2019-12-15 23:38:49 +01:00
|
|
|
@permissions = Hash(String, Hash(String, PermissionLevel)).new
|
|
|
|
@configuration = Hash(String, Hash(String, JSON::Any)).new
|
|
|
|
end
|
|
|
|
|
|
|
|
class Public
|
|
|
|
include JSON::Serializable
|
|
|
|
|
|
|
|
property login : String
|
|
|
|
property uid : Int32
|
|
|
|
property profile : JSON::Any?
|
|
|
|
|
|
|
|
def initialize(@uid, @login, @profile)
|
|
|
|
end
|
2019-06-29 03:55:40 +02:00
|
|
|
end
|
|
|
|
|
2019-12-15 23:38:49 +01:00
|
|
|
def to_public : Public
|
|
|
|
Public.new @uid, @login, @profile
|
2018-09-22 21:23:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|