fix a bug caused by keychain modifications

This commit is contained in:
Bob Sun 2017-02-20 11:48:39 +08:00
parent eb501ee65f
commit 70166c9901
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 22 additions and 25 deletions

View file

@ -84,21 +84,19 @@ class PasswordStore {
let pgp: ObjectivePGP = ObjectivePGP()
var pgpKeyPassphrase: String? {
didSet {
if pgpKeyPassphrase != nil {
Utils.addPasswrodToKeychain(name: "pgpKeyPassphrase", password: pgpKeyPassphrase!)
} else {
Utils.removeKeychain(name: "pgpKeyPassphrase")
}
set {
Utils.addPasswrodToKeychain(name: "pgpKeyPassphrase", password: newValue!)
}
get {
return Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase")
}
}
var gitRepositoryPassword: String? {
didSet {
if gitRepositoryPassword != nil {
Utils.addPasswrodToKeychain(name: "gitRepositoryPassword", password: gitRepositoryPassword!)
} else {
Utils.removeKeychain(name: "gitRepositoryPassword")
}
var gitRepositoryPassword: String? {
set {
Utils.addPasswrodToKeychain(name: "gitRepositoryPassword", password: newValue!)
}
get {
return Utils.getPasswordFromKeychain(name: "gitRepositoryPassword")
}
}
@ -119,14 +117,12 @@ class PasswordStore {
}
if Defaults[.gitRepositoryAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername]!, password: PasswordStore.shared.gitRepositoryPassword!))
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername]!, password: Utils.getPasswordFromKeychain(name: "gitRepositoryPassword") ?? ""))
} else if Defaults[.gitRepositoryAuthenticationMethod] == "SSH Key"{
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: Defaults[.gitRepositoryUsername]!, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL))
} else {
gitCredential = nil
}
pgpKeyPassphrase = Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase")
gitRepositoryPassword = Utils.getPasswordFromKeychain(name: "gitRepositoryPassword")
}
@ -465,8 +461,7 @@ class PasswordStore {
Utils.removeFileIfExists(at: Globals.sshPublicKeyURL)
Utils.removeAllKeychain()
pgpKeyPassphrase = nil
gitRepositoryPassword = nil
deleteCoreData(entityName: "PasswordEntity")
deleteCoreData(entityName: "PasswordCategoryEntity")