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