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