Add username/password login and keychain manager

Fix #224
This commit is contained in:
Arkadiusz Fal
2022-08-26 01:36:46 +02:00
parent 08ed810b9e
commit 2f2fd67860
19 changed files with 280 additions and 107 deletions

View File

@@ -109,23 +109,33 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
}
func updateToken() {
guard !account.anonymous else {
let (username, password) = AccountsModel.getCredentials(account)
guard !account.anonymous,
let username = username,
let password = password
else {
return
}
account.token = nil
login.request(
.post,
json: ["username": account.username, "password": account.password]
json: ["username": username, "password": password]
)
.onSuccess { response in
self.account.token = response.json.dictionaryValue["token"]?.string ?? ""
let token = response.json.dictionaryValue["token"]?.string ?? ""
if let error = response.json.dictionaryValue["error"]?.string {
NavigationModel.shared.presentAlert(
title: "Could not connect with your account",
title: "Account Error",
message: error
)
} else if !token.isEmpty {
AccountsModel.setToken(self.account, token)
} else {
NavigationModel.shared.presentAlert(
title: "Account Error",
message: "Could not update your token."
)
}
self.configure()