Merge pull request #5456 from 21pages/ab
always sync recent/ab password
This commit is contained in:
commit
25e784fe8a
@ -752,14 +752,13 @@ abstract class BasePeerCard extends StatelessWidget {
|
|||||||
style: style,
|
style: style,
|
||||||
),
|
),
|
||||||
proc: () async {
|
proc: () async {
|
||||||
if (tab == PeerTabIndex.ab) {
|
bool result = gFFI.abModel.changePassword(id, '');
|
||||||
gFFI.abModel.unrememberPassword(id);
|
|
||||||
await bind.mainForgetPassword(id: id);
|
await bind.mainForgetPassword(id: id);
|
||||||
gFFI.abModel.pushAb();
|
if (result) {
|
||||||
} else {
|
bool toast = tab == PeerTabIndex.ab;
|
||||||
bind.mainForgetPassword(id: id);
|
gFFI.abModel.pushAb(toastIfFail: toast, toastIfSucc: toast);
|
||||||
showToast(translate('Successful'));
|
|
||||||
}
|
}
|
||||||
|
showToast(translate('Successful'));
|
||||||
},
|
},
|
||||||
padding: menuPadding,
|
padding: menuPadding,
|
||||||
dismissOnClicked: true,
|
dismissOnClicked: true,
|
||||||
|
@ -722,7 +722,6 @@ Widget _hoverAction(
|
|||||||
);
|
);
|
||||||
return Obx(
|
return Obx(
|
||||||
() => Container(
|
() => Container(
|
||||||
padding: padding,
|
|
||||||
margin: EdgeInsets.symmetric(horizontal: 1),
|
margin: EdgeInsets.symmetric(horizontal: 1),
|
||||||
decoration:
|
decoration:
|
||||||
(hover.value || hoverableWhenfalse?.value == false) ? deco : null,
|
(hover.value || hoverableWhenfalse?.value == false) ? deco : null,
|
||||||
@ -730,6 +729,6 @@ Widget _hoverAction(
|
|||||||
onHover: (value) => hover.value = value,
|
onHover: (value) => hover.value = value,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
onTapDown: onTapDown,
|
onTapDown: onTapDown,
|
||||||
child: child)),
|
child: Container(padding: padding, child: child))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -211,12 +211,15 @@ class AbModel {
|
|||||||
it.first.alias = alias;
|
it.first.alias = alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unrememberPassword(String id) {
|
bool changePassword(String id, String hash) {
|
||||||
final it = peers.where((element) => element.id == id);
|
final it = peers.where((element) => element.id == id);
|
||||||
if (it.isEmpty) {
|
if (it.isNotEmpty) {
|
||||||
return;
|
if (it.first.hash != hash) {
|
||||||
|
it.first.hash = hash;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
it.first.hash = '';
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> pushAb(
|
Future<bool> pushAb(
|
||||||
@ -225,6 +228,7 @@ class AbModel {
|
|||||||
bool isRetry = false}) async {
|
bool isRetry = false}) async {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"pushAb: toastIfFail:$toastIfFail, toastIfSucc:$toastIfSucc, isRetry:$isRetry");
|
"pushAb: toastIfFail:$toastIfFail, toastIfSucc:$toastIfSucc, isRetry:$isRetry");
|
||||||
|
if (!gFFI.userModel.isLogin) return false;
|
||||||
pushError.value = '';
|
pushError.value = '';
|
||||||
if (isRetry) retrying.value = true;
|
if (isRetry) retrying.value = true;
|
||||||
DateTime startTime = DateTime.now();
|
DateTime startTime = DateTime.now();
|
||||||
|
@ -241,6 +241,17 @@ class FfiModel with ChangeNotifier {
|
|||||||
handleReloading(evt);
|
handleReloading(evt);
|
||||||
} else if (name == 'plugin_option') {
|
} else if (name == 'plugin_option') {
|
||||||
handleOption(evt);
|
handleOption(evt);
|
||||||
|
} else if (name == "sync_peer_password_to_ab") {
|
||||||
|
if (desktopType == DesktopType.main) {
|
||||||
|
final id = evt['id'];
|
||||||
|
final password = evt['password'];
|
||||||
|
if (id != null && password != null) {
|
||||||
|
if (gFFI.abModel
|
||||||
|
.changePassword(id.toString(), password.toString())) {
|
||||||
|
gFFI.abModel.pushAb(toastIfFail: false, toastIfSucc: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
debugPrint('Unknown event name: $name');
|
debugPrint('Unknown event name: $name');
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ class UserModel {
|
|||||||
_parseAndUpdateUser(UserPayload user) {
|
_parseAndUpdateUser(UserPayload user) {
|
||||||
userName.value = user.name;
|
userName.value = user.name;
|
||||||
isAdmin.value = user.isAdmin;
|
isAdmin.value = user.isAdmin;
|
||||||
|
bind.mainSetLocalOption(key: 'user_info', value: jsonEncode(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
// update ab and group status
|
// update ab and group status
|
||||||
|
@ -1074,7 +1074,7 @@ pub struct LoginConfigHandler {
|
|||||||
pub direct: Option<bool>,
|
pub direct: Option<bool>,
|
||||||
pub received: bool,
|
pub received: bool,
|
||||||
switch_uuid: Option<String>,
|
switch_uuid: Option<String>,
|
||||||
pub save_ab_password_to_recent: bool,
|
pub save_ab_password_to_recent: bool, // true: connected with ab password
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for LoginConfigHandler {
|
impl Deref for LoginConfigHandler {
|
||||||
@ -1656,6 +1656,18 @@ impl LoginConfigHandler {
|
|||||||
log::debug!("remove password of {}", self.id);
|
log::debug!("remove password of {}", self.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "flutter")]
|
||||||
|
{
|
||||||
|
// sync ab password with PeerConfig password
|
||||||
|
let password = base64::encode(config.password.clone(), base64::Variant::Original);
|
||||||
|
let evt: HashMap<&str, String> = HashMap::from([
|
||||||
|
("name", "sync_peer_password_to_ab".to_string()),
|
||||||
|
("id", self.id.clone()),
|
||||||
|
("password", password),
|
||||||
|
]);
|
||||||
|
let evt = serde_json::ser::to_string(&evt).unwrap_or("".to_owned());
|
||||||
|
crate::flutter::push_global_event(crate::flutter::APP_TYPE_MAIN, evt);
|
||||||
|
}
|
||||||
if config.keyboard_mode.is_empty() {
|
if config.keyboard_mode.is_empty() {
|
||||||
if is_keyboard_mode_supported(&KeyboardMode::Map, get_version_number(&pi.version)) {
|
if is_keyboard_mode_supported(&KeyboardMode::Map, get_version_number(&pi.version)) {
|
||||||
config.keyboard_mode = KeyboardMode::Map.to_string();
|
config.keyboard_mode = KeyboardMode::Map.to_string();
|
||||||
@ -2260,12 +2272,12 @@ pub async fn handle_hash(
|
|||||||
if !hash.is_empty() {
|
if !hash.is_empty() {
|
||||||
password = hash;
|
password = hash;
|
||||||
lc.write().unwrap().save_ab_password_to_recent = true;
|
lc.write().unwrap().save_ab_password_to_recent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
lc.write().unwrap().password = password.clone();
|
lc.write().unwrap().password = password.clone();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let password = if password.is_empty() {
|
let password = if password.is_empty() {
|
||||||
// login without password, the remote side can click accept
|
// login without password, the remote side can click accept
|
||||||
interface.msgbox("input-password", "Password Required", "", "");
|
interface.msgbox("input-password", "Password Required", "", "");
|
||||||
@ -2337,9 +2349,9 @@ pub async fn handle_login_from_ui(
|
|||||||
hasher.update(&lc.read().unwrap().hash.salt);
|
hasher.update(&lc.read().unwrap().hash.salt);
|
||||||
let res = hasher.finalize();
|
let res = hasher.finalize();
|
||||||
lc.write().unwrap().remember = remember;
|
lc.write().unwrap().remember = remember;
|
||||||
lc.write().unwrap().password = res[..].into();
|
|
||||||
res[..].into()
|
res[..].into()
|
||||||
};
|
};
|
||||||
|
lc.write().unwrap().password = hash_password.clone();
|
||||||
let mut hasher2 = Sha256::new();
|
let mut hasher2 = Sha256::new();
|
||||||
hasher2.update(&hash_password[..]);
|
hasher2.update(&hash_password[..]);
|
||||||
hasher2.update(&lc.read().unwrap().hash.challenge);
|
hasher2.update(&lc.read().unwrap().hash.challenge);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user