diff options
Diffstat (limited to 'server/src/api/user.rs')
-rw-r--r-- | server/src/api/user.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/server/src/api/user.rs b/server/src/api/user.rs index 8d2db104..0b1abb68 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -162,7 +162,7 @@ pub struct PasswordChange { #[derive(Serialize, Deserialize)] pub struct CreatePrivateMessage { content: String, - recipient_id: i32, + pub recipient_id: i32, auth: String, } @@ -193,6 +193,16 @@ pub struct PrivateMessageResponse { message: PrivateMessageView, } +#[derive(Serialize, Deserialize, Debug)] +pub struct UserJoin { + auth: String, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct UserJoinResponse { + pub user_id: i32, +} + impl Perform<LoginResponse> for Oper<Login> { fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> { let data: &Login = &self.data; @@ -1071,3 +1081,17 @@ impl Perform<PrivateMessagesResponse> for Oper<GetPrivateMessages> { Ok(PrivateMessagesResponse { messages }) } } + +impl Perform<UserJoinResponse> for Oper<UserJoin> { + fn perform(&self, _conn: &PgConnection) -> Result<UserJoinResponse, Error> { + let data: &UserJoin = &self.data; + + let claims = match Claims::decode(&data.auth) { + Ok(claims) => claims.claims, + Err(_e) => return Err(APIError::err("not_logged_in").into()), + }; + + let user_id = claims.id; + Ok(UserJoinResponse { user_id }) + } +} |