Commit f689f728 authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch 'release/1.1.8' into release/2.0.0

# Conflicts:
#	PIALibrary/Sources/UI/iOS/ViewControllers/LoginViewController.swift
parents dff03424 d266916c
......@@ -62,6 +62,16 @@ public protocol AccountProvider: class {
*/
func refreshAccountInfo(force: Bool, _ callback: LibraryCallback<AccountInfo>?)
/**
Retrieves information associated with the account currently logged in.
- Precondition: `isLoggedIn` is `true`.
- Postcondition:
- Posts `Notification.Name.PIAAccountDidRefresh` on success.
- Parameter callback: Returns a refreshed `AccountInfo`.
*/
func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?)
/**
Updates the account currently logged in.
......
......@@ -215,6 +215,14 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
public func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
guard let token = self.token else {
callback?(nil, ClientError.unauthorized)
return
}
accountInfoWith(token, callback)
}
private func accountInfoWith(_ token: String, _ callback: ((AccountInfo?, Error?) -> Void)?) {
webServices.info(token: token) { (accountInfo, error) in
guard let accountInfo = accountInfo else {
......@@ -339,11 +347,34 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
self.accessedDatabase.secure.setPublicUsername(credentials.username)
self.accessedDatabase.secure.setPassword(credentials.password, for: credentials.username)
let user = UserAccount(credentials: credentials, info: nil)
Macros.postNotification(.PIAAccountDidSignup, [
.user: user
])
callback?(user, nil)
self.webServices.token(credentials: credentials) { (token, error) in
guard let token = token else {
callback?(nil, error)
return
}
self.updateDatabaseWith(token,
andUsername: credentials.username)
self.webServices.info(token: token) { (accountInfo, error) in
guard let accountInfo = accountInfo else {
callback?(nil, error)
return
}
//Save after confirm the login was successful.
self.accessedDatabase.plain.accountInfo = accountInfo
let user = UserAccount(credentials: credentials, info: nil)
Macros.postNotification(.PIAAccountDidSignup, [
.user: user
])
callback?(user, nil)
}
}
}
}
......
......@@ -164,6 +164,15 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
delegate.refreshAccountInfo(force: false, callback)
}
/// :nodoc:
public func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
guard !mockIsUnauthorized else {
callback?(nil, ClientError.unauthorized)
return
}
delegate.accountInformation(callback)
}
/// :nodoc:
public func update(with request: UpdateAccountRequest, andPassword password: String, _ callback: LibraryCallback<AccountInfo>?) {
delegate.update(with: request, andPassword: password, callback)
......
......@@ -311,6 +311,10 @@ class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
fatalError("Not implemented")
}
func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
fatalError("Not implemented")
}
func update(with request: UpdateAccountRequest, andPassword password: String, _ callback: ((AccountInfo?, Error?) -> Void)?) {
fatalError("Not implemented")
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment