Compare commits
2 commits
623446d934
...
79dc4c780a
| Author | SHA1 | Date | |
|---|---|---|---|
| 79dc4c780a | |||
| ac7cb0ddee |
1 changed files with 23 additions and 3 deletions
|
|
@ -48,7 +48,8 @@ impl juniper::Context for Context {}
|
|||
struct TokenInfo {
|
||||
pid: i32,
|
||||
expire_date: NaiveDateTime,
|
||||
title_id: Option<String>
|
||||
title_id: Option<String>,
|
||||
token_type: i32
|
||||
}
|
||||
|
||||
#[derive(GraphQLObject)]
|
||||
|
|
@ -60,6 +61,16 @@ struct UserInfo {
|
|||
mii_data: String,
|
||||
}
|
||||
|
||||
#[derive(GraphQLObject)]
|
||||
#[graphql(description = "User information from a token")]
|
||||
struct TokenUserInfo {
|
||||
username: String,
|
||||
account_level: i32,
|
||||
nex_password: String,
|
||||
mii_data: String,
|
||||
token_type: i32,
|
||||
}
|
||||
|
||||
#[derive(GraphQLObject)]
|
||||
#[graphql(description = "User information from a username")]
|
||||
pub struct UserInfoWithPId {
|
||||
|
|
@ -96,13 +107,14 @@ impl Query {
|
|||
pid: data.pid,
|
||||
expire_date: token_info.expires,
|
||||
title_id: token_info.title_id,
|
||||
token_type: token_info.token_type,
|
||||
})
|
||||
}
|
||||
|
||||
async fn user_from_token(
|
||||
token_data: String,
|
||||
context: &Context,
|
||||
) -> Option<UserInfo> {
|
||||
) -> Option<TokenUserInfo> {
|
||||
let data = match TokenData::decode(&token_data) {
|
||||
Some(data) => data,
|
||||
None => {
|
||||
|
|
@ -111,6 +123,13 @@ impl Query {
|
|||
}
|
||||
};
|
||||
|
||||
let token_info =
|
||||
sqlx::query!(
|
||||
"select * from tokens where pid = $1 and token_id = $2 and random = $3",
|
||||
data.pid, data.token_id, data.random
|
||||
).
|
||||
fetch_one(&context.pool).await.ok()?;
|
||||
|
||||
let user = match sqlx::query!(
|
||||
"SELECT username, account_level, nex_password, mii_data FROM users WHERE pid = $1",
|
||||
data.pid
|
||||
|
|
@ -127,11 +146,12 @@ impl Query {
|
|||
|
||||
let nex_password = user.nex_password;
|
||||
|
||||
Some(UserInfo {
|
||||
Some(TokenUserInfo {
|
||||
username: user.username,
|
||||
account_level: user.account_level,
|
||||
nex_password,
|
||||
mii_data: user.mii_data.replace('\n', "").replace('\r', ""),
|
||||
token_type: token_info.token_type
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue