Merge branch 'master' of ssh://git.baguette.netlib.re:2299/Baguette/authd

ipc07
Karchnu 2020-05-08 14:51:10 +02:00
commit 7b14d4a971
3 changed files with 28 additions and 20 deletions

View File

@ -55,9 +55,10 @@ class AuthD::Response
end end
class Token < Response class Token < Response
property uid : Int32
property token : String property token : String
initialize :token initialize :token, :uid
end end
class User < Response class User < Response
@ -223,14 +224,10 @@ class AuthD::Request
end end
class ValidateUser < Request class ValidateUser < Request
# Only clients that have the right shared key will be allowed
# to validate users.
property shared_key : String
property login : String property login : String
property activation_key : String property activation_key : String
initialize :shared_key, :login, :activation_key initialize :login, :activation_key
end end
class GetUser < Request class GetUser < Request
@ -323,6 +320,13 @@ class AuthD::Request
initialize :user initialize :user
end end
class EditProfile < Request
property token : String
property new_profile : JSON::Any
initialize :token, :new_profile
end
# This creates a Request::Type enumeration. One entry for each request type. # This creates a Request::Type enumeration. One entry for each request type.
{% begin %} {% begin %}
enum Type enum Type
@ -452,10 +456,7 @@ module AuthD
end end
def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception
send Request::ValidateUser.new login, activation_key
pp! login
pp! activation_key
send Request::ValidateUser.new @key, login, activation_key
response = Response.from_ipc read response = Response.from_ipc read

View File

@ -74,7 +74,7 @@ class AuthD::Service
# change the date of the last connection # change the date of the last connection
@users_per_uid.update user.uid.to_s, user @users_per_uid.update user.uid.to_s, user
Response::Token.new token.to_s @jwt_key Response::Token.new (token.to_s @jwt_key), user.uid
when Request::AddUser when Request::AddUser
# No verification of the users' informations when an admin adds it. # No verification of the users' informations when an admin adds it.
# No mail address verification. # No mail address verification.
@ -109,10 +109,6 @@ class AuthD::Service
Response::UserAdded.new user.to_public Response::UserAdded.new user.to_public
when Request::ValidateUser when Request::ValidateUser
if request.shared_key != @jwt_key
return Response::Error.new "invalid authentication key"
end
user = @users_per_login.get? request.login user = @users_per_login.get? request.login
if user.nil? if user.nil?
@ -127,7 +123,7 @@ class AuthD::Service
if user.contact.activation_key == request.activation_key if user.contact.activation_key == request.activation_key
user.contact.activation_key = nil user.contact.activation_key = nil
else else
return Response::Error.new "Wrong activation key" return Response::Error.new "wrong activation key"
end end
@users_per_uid.update user.uid.to_s, user @users_per_uid.update user.uid.to_s, user
@ -410,7 +406,6 @@ class AuthD::Service
users = @users.to_a users = @users.to_a
users.each do |u| users.each do |u|
# pp! u
if pattern =~ u.login if pattern =~ u.login
puts "#{u.login} matches #{pattern}" puts "#{u.login} matches #{pattern}"
matching_users << u.to_public matching_users << u.to_public
@ -420,13 +415,23 @@ class AuthD::Service
end end
Response::MatchingUsers.new matching_users Response::MatchingUsers.new matching_users
when Request::EditProfile
user = get_user_from_token request.token
return Response::Error.new "invalid user" unless user
user.profile = request.new_profile
@users_per_uid.update user.uid.to_s, user
Response::User.new user.to_public
else else
Response::Error.new "unhandled request type" Response::Error.new "unhandled request type"
end end
end end
def get_user_from_token(token : String) def get_user_from_token(token : String)
token_payload = Token.from_s(token, @jwt_key) token_payload = Token.from_s(@jwt_key, token)
@users_per_uid.get? token_payload.uid.to_s @users_per_uid.get? token_payload.uid.to_s
end end

View File

@ -63,12 +63,14 @@ class AuthD::User
property uid : Int32 property uid : Int32
property profile : JSON::Any? property profile : JSON::Any?
def initialize(@uid, @login, @profile) property date_registration : Time?
def initialize(@uid, @login, @profile, @date_registration)
end end
end end
def to_public : Public def to_public : Public
Public.new @uid, @login, @profile Public.new @uid, @login, @profile, @date_registration
end end
end end