Merge pull request #4738 from dignow/refact/store_user_info
Refact/store user info
This commit is contained in:
commit
cf856af933
@ -101,13 +101,15 @@ class LoginRequest {
|
|||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
data['username'] = username ?? '';
|
if (username != null) data['username'] = username;
|
||||||
data['password'] = password ?? '';
|
if (password != null) data['password'] = password;
|
||||||
data['id'] = id ?? '';
|
if (id != null) data['id'] = id;
|
||||||
data['uuid'] = uuid ?? '';
|
if (uuid != null) data['uuid'] = uuid;
|
||||||
data['trustThisDevice'] = trustThisDevice ?? '';
|
if (trustThisDevice != null) data['trustThisDevice'] = trustThisDevice;
|
||||||
data['type'] = type ?? '';
|
if (type != null) data['type'] = type;
|
||||||
data['verificationCode'] = verificationCode ?? '';
|
if (verificationCode != null) {
|
||||||
|
data['verificationCode'] = verificationCode;
|
||||||
|
}
|
||||||
data['deviceInfo'] = deviceInfo;
|
data['deviceInfo'] = deviceInfo;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class UserModel {
|
|||||||
try {
|
try {
|
||||||
return json.decode(userInfo);
|
return json.decode(userInfo);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Failed to get local user info "$userInfo": $e');
|
debugPrint('Failed to get local user info, json decode "$userInfo": $e');
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use hbb_common::{
|
|||||||
log, ResultType,
|
log, ResultType,
|
||||||
};
|
};
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde::ser::SerializeStruct;
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use std::{
|
use std::{
|
||||||
@ -81,7 +80,7 @@ pub enum UserStatus {
|
|||||||
Unverified = -1,
|
Unverified = -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct UserPayload {
|
pub struct UserPayload {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
@ -90,9 +89,6 @@ pub struct UserPayload {
|
|||||||
pub info: UserInfo,
|
pub info: UserInfo,
|
||||||
pub is_admin: bool,
|
pub is_admin: bool,
|
||||||
pub third_auth_type: Option<String>,
|
pub third_auth_type: Option<String>,
|
||||||
// helper field for serialize
|
|
||||||
#[serde(default)]
|
|
||||||
pub ser_store_local: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -121,30 +117,6 @@ pub struct AuthResult {
|
|||||||
pub auth_body: Option<AuthBody>,
|
pub auth_body: Option<AuthBody>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serde::Serialize for UserPayload {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: serde::Serializer,
|
|
||||||
{
|
|
||||||
if self.ser_store_local {
|
|
||||||
let mut state = serializer.serialize_struct("UserPayload", 1)?;
|
|
||||||
state.serialize_field("name", &self.name)?;
|
|
||||||
state.serialize_field("status", &self.status)?;
|
|
||||||
state.end()
|
|
||||||
} else {
|
|
||||||
let mut state = serializer.serialize_struct("UserPayload", 7)?;
|
|
||||||
state.serialize_field("name", &self.name)?;
|
|
||||||
state.serialize_field("email", &self.email)?;
|
|
||||||
state.serialize_field("note", &self.note)?;
|
|
||||||
state.serialize_field("status", &self.status)?;
|
|
||||||
state.serialize_field("info", &self.info)?;
|
|
||||||
state.serialize_field("is_admin", &self.is_admin)?;
|
|
||||||
state.serialize_field("third_auth_type", &self.third_auth_type)?;
|
|
||||||
state.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OidcSession {
|
impl OidcSession {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -250,12 +222,10 @@ impl OidcSession {
|
|||||||
"access_token".to_owned(),
|
"access_token".to_owned(),
|
||||||
auth_body.access_token.clone(),
|
auth_body.access_token.clone(),
|
||||||
);
|
);
|
||||||
auth_body.user.ser_store_local = true;
|
|
||||||
LocalConfig::set_option(
|
LocalConfig::set_option(
|
||||||
"user_info".to_owned(),
|
"user_info".to_owned(),
|
||||||
serde_json::to_string(&auth_body.user).unwrap_or_default(),
|
serde_json::json!({ "name": auth_body.user.name, "status": auth_body.user.status }).to_string(),
|
||||||
);
|
);
|
||||||
auth_body.user.ser_store_local = false;
|
|
||||||
}
|
}
|
||||||
OIDC_SESSION
|
OIDC_SESSION
|
||||||
.write()
|
.write()
|
||||||
|
@ -822,11 +822,7 @@ pub fn account_auth_cancel() {
|
|||||||
|
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
pub fn account_auth_result() -> String {
|
pub fn account_auth_result() -> String {
|
||||||
let mut auth_result = account::OidcSession::get_result();
|
serde_json::to_string(&account::OidcSession::get_result()).unwrap_or_default()
|
||||||
if let Some(auth) = auth_result.auth_body.as_mut() {
|
|
||||||
auth.user.ser_store_local = false;
|
|
||||||
}
|
|
||||||
serde_json::to_string(&auth_result).unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user