Skip to content

Commit

Permalink
Merge pull request #49 from NatLibFi/EKIR-241-Invite-dependents
Browse files Browse the repository at this point in the history
Ekir 241 invite dependents
  • Loading branch information
natlibfi-kaisa authored Sep 3, 2024
2 parents 7ffe89e + 0437cd7 commit f815552
Show file tree
Hide file tree
Showing 6 changed files with 633 additions and 23 deletions.
6 changes: 6 additions & 0 deletions Palace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@
E6207B652118973800864143 /* TPPAppTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6207B642118973800864143 /* TPPAppTheme.swift */; };
E63F2C6C1EAA81B3002B6373 /* ExtendedNavBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63F2C6B1EAA81B3002B6373 /* ExtendedNavBarView.swift */; };
E65977C51F82AC91003CD6BC /* TPP_Launch_Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E65977C41F82AC91003CD6BC /* TPP_Launch_Screen.storyboard */; };
E6602BC52C64DCB200B1212D /* DependentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6602BC42C64DCB200B1212D /* DependentsView.swift */; };
E6602BC62C64DCB200B1212D /* DependentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6602BC42C64DCB200B1212D /* DependentsView.swift */; };
E66A6C441EAFB63300AA282D /* TPPBookButtonsView.m in Sources */ = {isa = PBXBuildFile; fileRef = E66A6C431EAFB63300AA282D /* TPPBookButtonsView.m */; };
E671FF7D1E3A7068002AB13F /* TPPNetworkQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = E671FF7C1E3A7068002AB13F /* TPPNetworkQueue.swift */; };
E683953B217663B100371072 /* TPPFacetViewDefaultDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = E683953A217663B100371072 /* TPPFacetViewDefaultDataSource.swift */; };
Expand Down Expand Up @@ -2101,6 +2103,7 @@
E6207B642118973800864143 /* TPPAppTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TPPAppTheme.swift; sourceTree = "<group>"; };
E63F2C6B1EAA81B3002B6373 /* ExtendedNavBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExtendedNavBarView.swift; sourceTree = "<group>"; };
E65977C41F82AC91003CD6BC /* TPP_Launch_Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = TPP_Launch_Screen.storyboard; sourceTree = "<group>"; };
E6602BC42C64DCB200B1212D /* DependentsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependentsView.swift; sourceTree = "<group>"; };
E66A6C421EAFB63300AA282D /* TPPBookButtonsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPPBookButtonsView.h; sourceTree = "<group>"; };
E66A6C431EAFB63300AA282D /* TPPBookButtonsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPPBookButtonsView.m; sourceTree = "<group>"; };
E66AE32F1DC0FCFC00124AE2 /* TPPCirculationAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TPPCirculationAnalytics.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3645,6 +3648,7 @@
E5B2B8D9275952EC00150ED4 /* TPPSettingsView.swift */,
E5B2B8DC2759552F00150ED4 /* TPPSettingsViewController.swift */,
E69E21B62C638C0D007B26EC /* PreferencesView.swift */,
E6602BC42C64DCB200B1212D /* DependentsView.swift */,
);
path = NewSettings;
sourceTree = "<group>";
Expand Down Expand Up @@ -4837,6 +4841,7 @@
331264152A287F53006BA87D /* TPPSettingsView.swift in Sources */,
3375701E2A2F685500547CE1 /* TPPSecrets.swift in Sources */,
331264162A287F53006BA87D /* TPPOPDSFeed.m in Sources */,
E6602BC52C64DCB200B1212D /* DependentsView.swift in Sources */,
331264172A287F53006BA87D /* TPPOPDSLink.m in Sources */,
33FCF7F92AC4595E008E3B72 /* URL+Extensions.swift in Sources */,
331264182A287F53006BA87D /* TPPSettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -5395,6 +5400,7 @@
5DD5674522B303DF001F0C83 /* TPPDeveloperSettingsTableViewController.swift in Sources */,
E5AD65E12684FDA300C62951 /* TPPAccountListDataSource.swift in Sources */,
E5EFDE7C298C4F8000258CA3 /* BookCellModel.swift in Sources */,
E6602BC62C64DCB200B1212D /* DependentsView.swift in Sources */,
2D754BC22002F1B10061D34F /* TPPOPDSIndirectAcquisition.m in Sources */,
21E35FC3268CC8AC00066F9D /* AdobeContentProtectionService.swift in Sources */,
21C7B87E25AE1DBA000E8BF3 /* LibraryServiceError.swift in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions Palace/Accounts/User/TPPUserAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private enum StorageKey: String {
case credentials = "TPPAccountCredentialsKey"
case authDefinition = "TPPAccountAuthDefinitionKey"
case cookies = "TPPAccountAuthCookiesKey"
case patronPermanentId = "TPPPatronPermanentId"

func keyForLibrary(uuid libraryUUID: String?) -> String {
guard
Expand Down Expand Up @@ -65,6 +66,7 @@ class TPPUserAccountAuthentication: ObservableObject {
StorageKey.credentials: _credentials,
StorageKey.authDefinition: _authDefinition,
StorageKey.cookies: _cookies,
StorageKey.patronPermanentId: _patronPermanentId,

// legacy
StorageKey.barcode: _barcode,
Expand Down Expand Up @@ -149,6 +151,7 @@ class TPPUserAccountAuthentication: ObservableObject {
_credentials.write(credentials)
_authToken.write(nil)
}

}
}

Expand Down Expand Up @@ -255,6 +258,9 @@ class TPPUserAccountAuthentication: ObservableObject {
private lazy var _cookies: TPPKeychainVariable<[HTTPCookie]> = StorageKey.cookies
.keyForLibrary(uuid: libraryUUID)
.asKeychainVariable(with: accountInfoLock)
private lazy var _patronPermanentId: TPPKeychainVariable<String> = StorageKey.patronPermanentId
.keyForLibrary(uuid: libraryUUID)
.asKeychainVariable(with: accountInfoLock)

// Legacy
private lazy var _barcode: TPPKeychainVariable<String> = StorageKey.barcode
Expand Down Expand Up @@ -408,6 +414,9 @@ class TPPUserAccountAuthentication: ObservableObject {
return nil
}

var patronPermantId: String? { _patronPermanentId.read() }


var patronFullName: String? {
if let patron = patron,
let name = patron["name"] as? [String:String]
Expand Down Expand Up @@ -520,6 +529,12 @@ class TPPUserAccountAuthentication: ObservableObject {
_deviceID.write(id)
notifyAccountDidChange()
}

@objc(setPatronPermanentId:)
func setPatronPermanentId(_ identifier: String) {
_patronPermanentId.write(identifier)
print("TPPUserAccount patronPermanentId has been set")
}

// MARK: - Remove

Expand All @@ -542,6 +557,7 @@ class TPPUserAccountAuthentication: ObservableObject {
_barcode.write(nil)
_pin.write(nil)
_authToken.write(nil)
_patronPermanentId.write(nil)

notifyAccountDidChange()

Expand Down
54 changes: 32 additions & 22 deletions Palace/Network/TPPNetworkExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,33 +471,43 @@ extension TPPNetworkExecutor {
URLSession.shared.dataTask(with: request){ data, response, error in

if(data != nil){
let json = try? JSONSerialization.jsonObject(with: data!)
let jsonRoot = json as? [String: Any]
let accessToken = jsonRoot?["access_token"] as? String

if let accessToken = accessToken {
let sharedAccount = TPPUserAccount.sharedAccount()

sharedAccount.setAuthToken(accessToken,barcode: nil, pin: nil, expirationDate: nil)

//is it ok to have a direct reference to TPPSignInBusinessLogic here?
TPPSignInBusinessLogic.getShared { logic in
logic?.notifySignIn()
}

}else{
TPPSignInBusinessLogic.getShared { logic in
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any] {
let sharedAccount = TPPUserAccount.sharedAccount()

if let accessToken = json["access_token"] as? String {
print("ACCESS TOKEN \(accessToken)")
sharedAccount.setAuthToken(accessToken,barcode: nil, pin: nil, expirationDate: nil)

DispatchQueue.main.async {
logic?.performLogOut()
}
if let patronInfo = json["patron_info"] as? String {
if let patronData = patronInfo.data(using: .utf8) {
if let patronObject = try JSONSerialization.jsonObject(with: patronData, options: []) as? [String: Any] {
if let patronPermanentId = patronObject["permanent_id"] as? String {
sharedAccount.setPatronPermanentId(patronPermanentId)
print("PERMANENT ID \(patronPermanentId)")
}
}
}
}
TPPSignInBusinessLogic.getShared { logic in
logic?.notifySignIn()
}
}
}
print("authenticateWithToken error: \(String(describing: error?.localizedDescription)) data: \(String(describing: String(data:data!,encoding: .utf8)))")

} catch {
print("Virhe JSONin käsittelyssä: \(error.localizedDescription)")
}


} else {
TPPSignInBusinessLogic.getShared { logic in
DispatchQueue.main.async {
logic?.performLogOut()
}
}
print("authenticateWithToken error: \(String(describing: error?.localizedDescription)) data: \(String(describing: String(data:data!,encoding: .utf8)))")
}

if let httpResponse = response as? HTTPURLResponse {
completion?(httpResponse.statusCode)
}else{
Expand Down
Loading

0 comments on commit f815552

Please sign in to comment.