From f6bbf77732698571c925ec5afe4fc7aba799f5f3 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Sat, 18 Apr 2020 21:21:17 +0200 Subject: [PATCH] Profile edition request. --- src/authd.cr | 7 +++++++ src/main.cr | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/authd.cr b/src/authd.cr index d90a596..a6540d4 100644 --- a/src/authd.cr +++ b/src/authd.cr @@ -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 diff --git a/src/main.cr b/src/main.cr index 7617713..8c513b6 100644 --- a/src/main.cr +++ b/src/main.cr @@ -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