Profile edition request.
This commit is contained in:
parent
e47f7e7f75
commit
f6bbf77732
@ -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
|
||||
|
12
src/main.cr
12
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
|
||||
|
Loading…
Reference in New Issue
Block a user