Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@
[submodule "tenprintcover-ios"]
path = tenprintcover-ios
url = git@github.com:NYPL/tenprintcover-ios.git
[submodule "adept-ios"]
path = adept-ios
url = git@github.com:NYPL/DRM-iOS-Adobe.git
[submodule "adobe-content-filter"]
path = adobe-content-filter
url = git@github.com:NYPL/Adobe-Content-Filter.git
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
binary "Crashlytics.json"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json"
github "NYPL-Simplified/CardCreator-iOS" ~> 1.1.2
github "NYPL-Simplified/NYPLAEToolkit" "master"
github "NYPL-Simplified/NYPLAudiobookToolkit" "master"
github "PureLayout/PureLayout" ~> 3.1.2
github "TheLevelUp/ZXingObjC" ~> 3.3
Expand Down
2 changes: 1 addition & 1 deletion Simplified.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Simplified+RMSDK.xcconfig"
//#include "Simplified+RMSDK.xcconfig"

HEADER_SEARCH_PATHS = $(inherited) "$(SDKROOT)/usr/include/libxml2" "$(SRCROOT)/readium-sdk/Platform/Apple/RDServices" "$(SRCROOT)/readium-sdk/Platform/Apple/include" "$(SRCROOT)/tenprintcover-ios/TenPrintCover" "$(SRCROOT)/adept-ios" "$(SRCROOT)/adobe-content-filter/public"

Expand Down
58 changes: 27 additions & 31 deletions Simplified.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

114 changes: 58 additions & 56 deletions Simplified/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ private let accountSyncEnabledKey = "NYPLAccountSyncEnabledKey"
// MARK: AccountDetails
// Extra data that gets loaded from an OPDS2AuthenticationDocument,
@objcMembers final class AccountDetails: NSObject {
enum AuthType: String {
enum AuthType: String, Codable {
case basic = "http://opds-spec.org/auth/basic"
case coppa = "http://librarysimplified.org/terms/authentication/gate/coppa"
case anonymous = "http://librarysimplified.org/rel/auth/anonymous"
case oauthIntermediary = "http://librarysimplified.org/authtype/OAuth-with-intermediary"
case none
}

struct Authentication {
@objc(AccountDetailsAuthentication)
@objcMembers
class Authentication: NSObject, Codable, NSCoding {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the classname the same between Swift and Objc? Easy to rename the Swift one if needed. This way the codebase would be much easier to browse IMO.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccountDetailsAuthentication because Authentication struct is nested inside AccountDetails struct. I wasn't able to access this struct otherwise in objc, but I might take a second look into this.

struct AccountDetails {
struct Authentication {
}
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to use nested types in Objective-C. And I'm afraid of name collision in case there is another Authentication type in future. I'd leave it as it currently is.

let authType:AuthType
let authPasscodeLength:UInt
let patronIDKeyboard:LoginKeyboard
Expand All @@ -24,81 +27,80 @@ private let accountSyncEnabledKey = "NYPLAccountSyncEnabledKey"
let supportsBarcodeDisplay:Bool
let coppaUnderUrl:URL?
let coppaOverUrl:URL?

let oauthIntermediaryUrl:URL?
let methodDescription: String?

init(auth: OPDS2AuthenticationDocument.Authentication) {
authType = AuthType(rawValue: auth.type) ?? .none
authPasscodeLength = auth.inputs?.password.maximumLength ?? 99
patronIDKeyboard = LoginKeyboard.init(auth.inputs?.login.keyboard) ?? .standard
pinKeyboard = LoginKeyboard.init(auth.inputs?.password.keyboard) ?? .standard
patronIDLabel = auth.labels?.login
pinLabel = auth.labels?.password
methodDescription = auth.description
supportsBarcodeScanner = auth.inputs?.login.barcodeFormat == "Codabar"
supportsBarcodeDisplay = supportsBarcodeScanner
coppaUnderUrl = URL.init(string: auth.links?.first(where: { $0.rel == "http://librarysimplified.org/terms/rel/authentication/restriction-not-met" })?.href ?? "")
coppaOverUrl = URL.init(string: auth.links?.first(where: { $0.rel == "http://librarysimplified.org/terms/rel/authentication/restriction-met" })?.href ?? "")
coppaOverUrl = URL.init(string: auth.links?.first(where: { $0.rel == "http://librarysimplified.org/terms/rel/authentication/restriction-met" })?.href ?? "")
oauthIntermediaryUrl = URL.init(string: auth.links?.first(where: { $0.rel == "authenticate" })?.href ?? "")
}

var needsAuth:Bool {
return authType == .basic || authType == .oauthIntermediary
}

var needsAgeCheck:Bool {
return authType == .coppa
}

var isCatalogSecured: Bool {
return authType == .oauthIntermediary
}

func encode(with coder: NSCoder) {
let jsonEncoder = JSONEncoder()
guard let data = try? jsonEncoder.encode(self) else { return }
coder.encode(data as NSData)
}

required init?(coder: NSCoder) {
guard let data = coder.decodeData() else { return nil }
let jsonDecoder = JSONDecoder()
guard let authentication = try? jsonDecoder.decode(Authentication.self, from: data) else { return nil }

authType = authentication.authType
authPasscodeLength = authentication.authPasscodeLength
patronIDKeyboard = authentication.patronIDKeyboard
pinKeyboard = authentication.pinKeyboard
patronIDLabel = authentication.patronIDLabel
pinLabel = authentication.pinLabel
supportsBarcodeScanner = authentication.supportsBarcodeScanner
supportsBarcodeDisplay = authentication.supportsBarcodeDisplay
coppaUnderUrl = authentication.coppaUnderUrl
coppaOverUrl = authentication.coppaOverUrl
oauthIntermediaryUrl = authentication.oauthIntermediaryUrl
methodDescription = authentication.methodDescription
}
}

let defaults:UserDefaults
let uuid:String
let supportsSimplyESync:Bool
let supportsCardCreator:Bool
let supportsReservations:Bool
let auths: [Authentication]

let mainColor:String?
let userProfileUrl:String?
let signUpUrl:URL?
let loansUrl:URL?

var authType: AuthType {
return auths.first?.authType ?? .none
}

var authPasscodeLength: UInt {
return auths.first?.authPasscodeLength ?? 99
}

var patronIDKeyboard: LoginKeyboard {
return auths.first?.patronIDKeyboard ?? .standard
}

var pinKeyboard: LoginKeyboard {
return auths.first?.pinKeyboard ?? .standard
}

var supportsBarcodeScanner: Bool {
return auths.first?.supportsBarcodeScanner ?? false
}

var supportsBarcodeDisplay: Bool {
return auths.first?.supportsBarcodeDisplay ?? false
}

var coppaUnderUrl: URL? {
return auths.first?.coppaUnderUrl
}

var coppaOverUrl: URL? {
return auths.first?.coppaOverUrl
}

var patronIDLabel: String? {
return auths.first?.patronIDLabel
}

var pinLabel: String? {
return auths.first?.pinLabel
}

var needsAuth:Bool {
return authType == .basic
}

var needsAgeCheck:Bool {
return authType == .coppa
// FIXME: Is it needed?
var defaultAuth: Authentication? {
guard auths.count > 1 else { return auths.first }
return auths.first(where: { !$0.isCatalogSecured }) ?? auths.first
}

fileprivate var urlAnnotations:URL?
fileprivate var urlAcknowledgements:URL?
fileprivate var urlContentLicenses:URL?
Expand Down Expand Up @@ -333,7 +335,7 @@ private let accountSyncEnabledKey = "NYPLAccountSyncEnabledKey"

NYPLNetworkExecutor.shared.GET(url) { result in
switch result {
case .success(let serverData):
case .success(let serverData, _):
do {
self.authenticationDocument = try
OPDS2AuthenticationDocument.fromData(serverData)
Expand All @@ -345,7 +347,7 @@ private let accountSyncEnabledKey = "NYPLAccountSyncEnabledKey"
""")
completion(false)
}
case .failure(let error):
case .failure(let error, _):
Log.error(#file, """
Failed to load authentication document at URL \(url). Error: \(error)
""")
Expand Down Expand Up @@ -386,7 +388,7 @@ extension Account {
}

// MARK: LoginKeyboard
@objc enum LoginKeyboard: Int {
@objc enum LoginKeyboard: Int, Codable {
case standard
case email
case numeric
Expand Down
Loading