logout: clear keypair on logout
Fixes: #12 Reported-by: Jeff Thibault (github:jeffthibault) Changelog-Fixed: Logging out now resets your keypair and actually logs out Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -84,15 +84,24 @@ func save_privkey(privkey: String) {
|
|||||||
UserDefaults.standard.set(privkey, forKey: "privkey")
|
UserDefaults.standard.set(privkey, forKey: "privkey")
|
||||||
}
|
}
|
||||||
|
|
||||||
func clear_privkey() {
|
func clear_saved_privkey() {
|
||||||
UserDefaults.standard.removeObject(forKey: "privkey")
|
UserDefaults.standard.removeObject(forKey: "privkey")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clear_saved_pubkey() {
|
||||||
|
UserDefaults.standard.removeObject(forKey: "pubkey")
|
||||||
|
}
|
||||||
|
|
||||||
func save_keypair(pubkey: String, privkey: String) {
|
func save_keypair(pubkey: String, privkey: String) {
|
||||||
save_pubkey(pubkey: pubkey)
|
save_pubkey(pubkey: pubkey)
|
||||||
save_privkey(privkey: privkey)
|
save_privkey(privkey: privkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clear_keypair() {
|
||||||
|
clear_saved_privkey()
|
||||||
|
clear_saved_pubkey()
|
||||||
|
}
|
||||||
|
|
||||||
func get_saved_keypair() -> Keypair? {
|
func get_saved_keypair() -> Keypair? {
|
||||||
get_saved_pubkey().flatMap { pubkey in
|
get_saved_pubkey().flatMap { pubkey in
|
||||||
let privkey = get_saved_privkey()
|
let privkey = get_saved_privkey()
|
||||||
|
|||||||
@@ -139,12 +139,12 @@ func process_login(_ key: ParsedKey, is_pubkey: Bool) -> Bool {
|
|||||||
save_pubkey(pubkey: pk)
|
save_pubkey(pubkey: pk)
|
||||||
|
|
||||||
case .pub(let pub):
|
case .pub(let pub):
|
||||||
clear_privkey()
|
clear_saved_privkey()
|
||||||
save_pubkey(pubkey: pub)
|
save_pubkey(pubkey: pub)
|
||||||
|
|
||||||
case .hex(let hexstr):
|
case .hex(let hexstr):
|
||||||
if is_pubkey {
|
if is_pubkey {
|
||||||
clear_privkey()
|
clear_saved_privkey()
|
||||||
save_pubkey(pubkey: hexstr)
|
save_pubkey(pubkey: hexstr)
|
||||||
} else {
|
} else {
|
||||||
save_privkey(privkey: hexstr)
|
save_privkey(privkey: hexstr)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct MainView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(handle_notify(.logout)) { _ in
|
.onReceive(handle_notify(.logout)) { _ in
|
||||||
|
clear_keypair()
|
||||||
keypair = nil
|
keypair = nil
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|||||||
Reference in New Issue
Block a user