-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1Password Support for Database Connections #422
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ class DatabasePresenter: Presentable, Loggable { | |
} | ||
} | ||
|
||
var passwordManager: PasswordManager | ||
|
||
var authPresenter: AuthPresenter? | ||
var enterpriseInteractor: EnterpriseDomainInteractor? | ||
|
||
|
@@ -57,6 +59,7 @@ class DatabasePresenter: Presentable, Loggable { | |
self.database = connection | ||
self.navigator = navigator | ||
self.options = options | ||
self.passwordManager = options.passwordManager | ||
} | ||
|
||
var view: View { | ||
|
@@ -85,18 +88,18 @@ class DatabasePresenter: Presentable, Loggable { | |
showSignup(inView: database, username: initialUsername, email: initialEmail) | ||
} | ||
self.databaseView = database | ||
|
||
return database | ||
} | ||
|
||
private func showLogin(inView view: DatabaseView, identifier: String?) { | ||
self.messagePresenter?.hideCurrent() | ||
let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20), isLogin: true) | ||
let style = self.database.requiresUsername ? self.options.usernameStyle : [.Email] | ||
view.showLogin(withIdentifierStyle: style, identifier: identifier, authCollectionView: authCollectionView) | ||
view.showLogin(withIdentifierStyle: style, identifier: identifier, authCollectionView: authCollectionView, showPassswordManager: self.passwordManager.available) | ||
self.currentScreen = .login | ||
let form = view.form | ||
form?.onValueChange = self.handleInput | ||
|
||
let action = { [weak form] (button: PrimaryButton) in | ||
self.messagePresenter?.hideCurrent() | ||
self.logger.info("Perform login for email: \(self.authenticator.email.verbatim())") | ||
|
@@ -146,6 +149,23 @@ class DatabasePresenter: Presentable, Loggable { | |
view.secondaryButton?.onPress = { button in | ||
self.navigator.navigate(.forgotPassword) | ||
} | ||
|
||
if let identifyField = view.identityField, let passwordField = view.passwordField { | ||
passwordManager.onUpdate = { [unowned self, unowned identifyField, unowned passwordField] identifier, password in | ||
identifyField.text = identifier | ||
passwordField.text = password | ||
self.handleInput(identifyField) | ||
self.handleInput(passwordField) | ||
} | ||
} | ||
view.passwordManagerButton?.onPress = { _ in | ||
self.passwordManager.login { | ||
guard $0 == nil else { | ||
return self.logger.error("There was a problem with the password manager: \($0.verbatim())") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private func showSignup(inView view: DatabaseView, username: String?, email: String?) { | ||
|
@@ -155,7 +175,7 @@ class DatabasePresenter: Presentable, Loggable { | |
let passwordPolicyValidator = interactor?.passwordValidator as? PasswordPolicyValidator | ||
self.currentScreen = .signup | ||
|
||
view.showSignUp(withUsername: self.database.requiresUsername, username: username, email: email, authCollectionView: authCollectionView, additionalFields: self.options.customSignupFields, passwordPolicyValidator: passwordPolicyValidator) | ||
view.showSignUp(withUsername: self.database.requiresUsername, username: username, email: email, authCollectionView: authCollectionView, additionalFields: self.options.customSignupFields, passwordPolicyValidator: passwordPolicyValidator, showPassswordManager: self.passwordManager.available) | ||
let form = view.form | ||
view.form?.onValueChange = self.handleInput | ||
let action = { [weak form] (button: PrimaryButton) in | ||
|
@@ -186,7 +206,6 @@ class DatabasePresenter: Presentable, Loggable { | |
form?.needsToUpdateState() | ||
self.messagePresenter?.showError(error) | ||
self.logger.error("Failed with error \(error)") | ||
|
||
} | ||
} | ||
} | ||
|
@@ -206,6 +225,23 @@ class DatabasePresenter: Presentable, Loggable { | |
[cancel, tos, privacy].forEach { alert.addAction($0) } | ||
self.navigator.present(alert) | ||
} | ||
|
||
if let identifyField = view.identityField, let passwordField = view.passwordField { | ||
passwordManager.onUpdate = { [unowned self, unowned identifyField, unowned passwordField] identifier, password in | ||
identifyField.text = identifier | ||
passwordField.text = password | ||
self.handleInput(identifyField) | ||
self.handleInput(passwordField) | ||
} | ||
} | ||
view.passwordManagerButton?.onPress = { _ in | ||
self.passwordManager.store(withPolicy: passwordPolicyValidator?.policy.onePasswordRules(), identifier: self.creator.identifier) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are retaining the presenter here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both, there is no strong reference to the block which is why I didn't modify in the last pass. Quick checked in deinit {
print("dealloc")
} |
||
guard $0 == nil else { | ||
return self.logger.error("There was a problem with the password manager: \($0.verbatim())") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private func handleInput(_ input: InputField) { | ||
|
@@ -238,9 +274,9 @@ class DatabasePresenter: Presentable, Loggable { | |
input.showValid() | ||
|
||
guard | ||
let mode = self.databaseView?.switcher?.selected, | ||
mode == .login && updateHRD | ||
else { return } | ||
let mode = self.databaseView?.switcher?.selected, | ||
mode == .login && updateHRD | ||
else { return } | ||
try? self.enterpriseInteractor?.updateEmail(input.text) | ||
if let connection = self.enterpriseInteractor?.connection { | ||
self.logger.verbose("Enterprise connection detected: \(connection)") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// IconButton.swift.swift | ||
// | ||
// Copyright (c) 2017 Auth0 (http://auth0.com) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
|
||
class IconButton: UIView { | ||
|
||
weak var button: UIButton? | ||
|
||
var onPress: (IconButton) -> Void = {_ in } | ||
|
||
var color: UIColor = .clear { | ||
didSet { | ||
self.button?.tintColor = self.color | ||
} | ||
} | ||
|
||
var icon: UIImage? { | ||
didSet { | ||
self.button?.setImage(self.icon, for: .normal) | ||
} | ||
} | ||
|
||
// MARK: - Initialisers | ||
convenience init() { | ||
self.init(frame: CGRect.zero) | ||
} | ||
|
||
required override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
self.layoutButton() | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
self.layoutButton() | ||
} | ||
|
||
// MARK: - Layout | ||
|
||
private func layoutButton() { | ||
let button = UIButton(type: .custom) | ||
self.addSubview(button) | ||
|
||
constraintEqual(anchor: button.topAnchor, toAnchor: self.topAnchor) | ||
constraintEqual(anchor: button.leftAnchor, toAnchor: self.leftAnchor) | ||
constraintEqual(anchor: button.rightAnchor, toAnchor: self.rightAnchor) | ||
constraintEqual(anchor: button.bottomAnchor, toAnchor: self.bottomAnchor) | ||
button.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
button.addTarget(self, action: #selector(pressed), for: .touchUpInside) | ||
button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) | ||
self.button = button | ||
} | ||
|
||
func pressed(_ sender: Any) { | ||
self.onPress(self) | ||
} | ||
|
||
override var intrinsicContentSize: CGSize { | ||
return CGSize(width: 50, height: UIViewNoIntrinsicMetric) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "ic_onepassword.pdf" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are retaining the presenter here