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
class Token < Response
property uid : Int32
property token : String
initialize :token
initialize :token, :uid
end
class User < Response
@ -223,14 +224,10 @@ class AuthD::Request
end
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 activation_key : String
initialize :shared_key, :login, :activation_key
initialize :login, :activation_key
end
class GetUser < Request
@ -323,6 +320,13 @@ class AuthD::Request
initialize :user
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.
{% begin %}
enum Type
@ -452,10 +456,7 @@ module AuthD
end
def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception
pp! login
pp! activation_key
send Request::ValidateUser.new @key, login, activation_key
send Request::ValidateUser.new login, activation_key
response = Response.from_ipc read

View File

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

View File

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