Profile edition request.

This commit is contained in:
Luka Vandervelden 2020-04-18 21:21:17 +02:00
parent e47f7e7f75
commit f6bbf77732
2 changed files with 18 additions and 1 deletions

View File

@ -319,6 +319,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

View File

@ -397,13 +397,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