Skip to content

Commit cbffb6e

Browse files
committed
device owner verification for profile deletion
this is mainly to avoid accidental actions
1 parent 5ffde15 commit cbffb6e

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

deltachat-ios/Controller/ProfileSwitchViewController.swift

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,31 +166,32 @@ class ProfileSwitchViewController: UITableViewController {
166166

167167
func deleteAccount(at indexPath: IndexPath) {
168168
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
169-
let accountId = accountIds[indexPath.row]
170-
let account = self.dcAccounts.get(id: accountId)
171-
let message = "⚠️ " + String.localized(stringID: "delete_account_explain_with_name", parameter: account.displayname ?? account.addr ?? "no addr")
172-
let alert = UIAlertController(title: String.localized("delete_account_ask"), message: message, preferredStyle: .alert)
173-
alert.addAction(UIAlertAction(title: String.localized("delete_account"), style: .destructive, handler: { [weak self] _ in
169+
Utils.authenticateDeviceOwner(reason: String.localized("edit_transport")) { [weak self] in
174170
guard let self else { return }
175-
176-
appDelegate.locationManager.disableLocationStreamingInAllChats()
177-
self.dcAccounts.stopIo()
178-
_ = self.dcAccounts.remove(id: accountId)
179-
self.dcAccounts.startIo()
180-
KeychainManager.deleteAccountSecret(id: accountId)
181-
INInteraction.delete(with: "\(accountId)", completion: nil)
182-
if self.dcAccounts.getAll().isEmpty {
183-
_ = self.dcAccounts.add()
184-
} else {
185-
let lastSelectedAccountId = UserDefaults.standard.integer(forKey: Constants.Keys.lastSelectedAccountKey)
186-
if lastSelectedAccountId != 0 {
187-
_ = self.dcAccounts.select(id: lastSelectedAccountId)
171+
let accountId = accountIds[indexPath.row]
172+
let account = dcAccounts.get(id: accountId)
173+
let message = "⚠️ " + String.localized(stringID: "delete_account_explain_with_name", parameter: account.displayname ?? account.addr ?? "no addr")
174+
let alert = UIAlertController(title: String.localized("delete_account_ask"), message: message, preferredStyle: .alert)
175+
alert.addAction(UIAlertAction(title: String.localized("delete_account"), style: .destructive, handler: { [weak self] _ in
176+
guard let self else { return }
177+
178+
appDelegate.locationManager.disableLocationStreamingInAllChats()
179+
_ = dcAccounts.remove(id: accountId)
180+
KeychainManager.deleteAccountSecret(id: accountId)
181+
INInteraction.delete(with: "\(accountId)", completion: nil)
182+
if dcAccounts.getAll().isEmpty {
183+
_ = dcAccounts.add()
184+
} else {
185+
let lastSelectedAccountId = UserDefaults.standard.integer(forKey: Constants.Keys.lastSelectedAccountKey)
186+
if lastSelectedAccountId != 0 {
187+
_ = dcAccounts.select(id: lastSelectedAccountId)
188+
}
188189
}
189-
}
190-
self.reloadAndExit(appDelegate: appDelegate, previousAccountId: 0)
191-
}))
192-
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
193-
self.present(alert, animated: true, completion: nil)
190+
reloadAndExit(appDelegate: appDelegate, previousAccountId: 0)
191+
}))
192+
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
193+
present(alert, animated: true, completion: nil)
194+
}
194195
}
195196

196197
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

0 commit comments

Comments
 (0)