diff --git a/flutter/lib/common/hbbs/hbbs.dart b/flutter/lib/common/hbbs/hbbs.dart index 2d559ec74..50960e59c 100644 --- a/flutter/lib/common/hbbs/hbbs.dart +++ b/flutter/lib/common/hbbs/hbbs.dart @@ -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 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 toJson() { final Map 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 json) { access_token = json['access_token']; type = json['type']; + print('REMOVE ME ================== $json'); user = json['user'] != null ? UserPayload.fromJson(json['user']) : null; } } diff --git a/src/hbbs_http/account.rs b/src/hbbs_http/account.rs index 08b15ba90..116c0ad02 100644 --- a/src/hbbs_http/account.rs +++ b/src/hbbs_http/account.rs @@ -60,8 +60,6 @@ pub struct UserInfo { #[serde(default)] pub settings: UserSettings, #[serde(default)] - pub login_ip_whitelist: Vec, - #[serde(default)] pub login_device_whitelist: Vec, #[serde(default)] pub other: HashMap, @@ -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, pub status: UserStatus, pub info: UserInfo, - pub role: UserRole, pub is_admin: bool, + pub third_auth_type: Option, // 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() } } diff --git a/src/ui/index.tis b/src/ui/index.tis index adfa5a035..2085f998d 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -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) {