change user payload
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
8dd218235d
commit
54cc45dd66
@ -14,31 +14,37 @@ class HttpType {
|
||||
static const kAuthResTypeEmailCheck = "email_check";
|
||||
}
|
||||
|
||||
enum UserStatus { kDisabled, kNormal, kUnverified }
|
||||
|
||||
// to-do: The UserPayload does not contain all the fields of the user.
|
||||
// Is all the fields of the user needed?
|
||||
class UserPayload {
|
||||
String id = '';
|
||||
String name = '';
|
||||
String email = '';
|
||||
String note = '';
|
||||
int? status;
|
||||
UserStatus status;
|
||||
bool isAdmin = false;
|
||||
|
||||
UserPayload.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'] ?? '',
|
||||
name = json['name'] ?? '',
|
||||
: name = json['name'] ?? '',
|
||||
email = json['email'] ?? '',
|
||||
note = json['note'] ?? '',
|
||||
status = json['status'],
|
||||
status = json['status'] == 0
|
||||
? UserStatus.kDisabled
|
||||
: json['status'] == -1
|
||||
? UserStatus.kUnverified
|
||||
: UserStatus.kNormal,
|
||||
isAdmin = json['is_admin'] == true;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> map = {
|
||||
'name': name,
|
||||
'status': status == UserStatus.kDisabled
|
||||
? 0
|
||||
: status == UserStatus.kUnverified
|
||||
? -1
|
||||
: 1,
|
||||
};
|
||||
if (status != null) {
|
||||
map['status'] = status!;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -117,6 +123,7 @@ class LoginResponse {
|
||||
LoginResponse.fromJson(Map<String, dynamic> json) {
|
||||
access_token = json['access_token'];
|
||||
type = json['type'];
|
||||
print('REMOVE ME ================== $json');
|
||||
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ pub struct UserInfo {
|
||||
#[serde(default)]
|
||||
pub settings: UserSettings,
|
||||
#[serde(default)]
|
||||
pub login_ip_whitelist: Vec<WhitelistItem>,
|
||||
#[serde(default)]
|
||||
pub login_device_whitelist: Vec<WhitelistItem>,
|
||||
#[serde(default)]
|
||||
pub other: HashMap<String, String>,
|
||||
@ -83,14 +81,6 @@ pub enum UserStatus {
|
||||
Unverified = -1,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(i64)]
|
||||
pub enum UserRole {
|
||||
Owner = 10,
|
||||
Admin = 1,
|
||||
Member = 0,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct UserPayload {
|
||||
pub name: String,
|
||||
@ -98,8 +88,8 @@ pub struct UserPayload {
|
||||
pub note: Option<String>,
|
||||
pub status: UserStatus,
|
||||
pub info: UserInfo,
|
||||
pub role: UserRole,
|
||||
pub is_admin: bool,
|
||||
pub third_auth_type: Option<String>,
|
||||
// helper field for serialize
|
||||
#[serde(default)]
|
||||
pub ser_store_local: bool,
|
||||
@ -148,8 +138,8 @@ impl serde::Serialize for UserPayload {
|
||||
state.serialize_field("note", &self.note)?;
|
||||
state.serialize_field("status", &self.status)?;
|
||||
state.serialize_field("info", &self.info)?;
|
||||
state.serialize_field("role", &self.role)?;
|
||||
state.serialize_field("is_admin", &self.is_admin)?;
|
||||
state.serialize_field("third_auth_type", &self.third_auth_type)?;
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
@ -1174,6 +1174,11 @@ function check_if_overlay() {
|
||||
|
||||
checkConnectStatus();
|
||||
|
||||
function set_local_user_info(user) {
|
||||
var user_info = {name: user.name, status: user.status};
|
||||
handler.set_local_option("user_info", JSON.stringify(user_info));
|
||||
}
|
||||
|
||||
function login() {
|
||||
var name0 = getUserName();
|
||||
var pass0 = '';
|
||||
@ -1209,7 +1214,7 @@ function login() {
|
||||
return;
|
||||
}
|
||||
handler.set_local_option("access_token", data.access_token);
|
||||
handler.set_local_option("user_info", JSON.stringify(data.user));
|
||||
set_local_user_info(data.user);
|
||||
show_progress(-1);
|
||||
myIdMenu.update();
|
||||
getAb();
|
||||
@ -1248,7 +1253,7 @@ function on_email_check(last_msg) {
|
||||
return;
|
||||
}
|
||||
handler.set_local_option("access_token", data.access_token);
|
||||
handler.set_local_option("user_info", JSON.stringify(data.user));
|
||||
set_local_user_info(data.user);
|
||||
show_progress(-1);
|
||||
myIdMenu.update();
|
||||
getAb();
|
||||
@ -1298,7 +1303,7 @@ function refreshCurrentUser() {
|
||||
handleAbError(data.error);
|
||||
return;
|
||||
}
|
||||
handler.set_local_option("user_info", JSON.stringify(data));
|
||||
set_local_user_info(data);
|
||||
myIdMenu.update();
|
||||
getAb();
|
||||
}, function(err, status) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user