Add ability to update credentials
This commit is contained in:
parent
aaa4342494
commit
261e2a951a
|
@ -83,9 +83,9 @@ extension AccountsAddViewController: NSTableViewDelegate {
|
|||
accountsAddLocalWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsAddWindowController = accountsAddLocalWindowController
|
||||
case 1:
|
||||
let accountsAddLocalWindowController = AccountsAddFeedbinWindowController()
|
||||
accountsAddLocalWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsAddWindowController = accountsAddLocalWindowController
|
||||
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
|
||||
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsAddWindowController = accountsFeedbinWindowController
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<customObject id="-2" userLabel="File's Owner" customClass="AccountsDetailViewController" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="activeButton" destination="wxB-dX-nGt" id="ALS-GI-sb5"/>
|
||||
<outlet property="credentialsButton" destination="gLh-gl-ZGQ" id="ee9-t8-lUg"/>
|
||||
<outlet property="nameTextField" destination="TT0-Kf-YTC" id="oMG-jn-Qn0"/>
|
||||
<outlet property="typeLabel" destination="XYX-iz-hnq" id="SKM-et-3h3"/>
|
||||
<outlet property="view" destination="3ki-rg-6yb" id="ttM-4E-OLN"/>
|
||||
|
@ -92,10 +93,22 @@
|
|||
</gridCell>
|
||||
</gridCells>
|
||||
</gridView>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gLh-gl-ZGQ">
|
||||
<rect key="frame" x="109" y="115" width="109" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Credentials" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="vYg-ZC-o4W">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<connections>
|
||||
<action selector="credentials:" target="-2" id="KS2-fM-QKK"/>
|
||||
</connections>
|
||||
</buttonCell>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="nVy-H3-bFO" firstAttribute="leading" secondItem="ft2-Mb-5LD" secondAttribute="leading" constant="20" symbolic="YES" id="SQe-pg-1hl"/>
|
||||
<constraint firstAttribute="trailing" secondItem="nVy-H3-bFO" secondAttribute="trailing" constant="20" symbolic="YES" id="Wsq-ar-poP"/>
|
||||
<constraint firstItem="gLh-gl-ZGQ" firstAttribute="top" secondItem="nVy-H3-bFO" secondAttribute="bottom" constant="20" symbolic="YES" id="a0S-2S-3dR"/>
|
||||
<constraint firstItem="gLh-gl-ZGQ" firstAttribute="centerX" secondItem="ft2-Mb-5LD" secondAttribute="centerX" id="cW8-YT-BEn"/>
|
||||
<constraint firstItem="nVy-H3-bFO" firstAttribute="top" secondItem="ft2-Mb-5LD" secondAttribute="top" constant="20" symbolic="YES" id="sy2-s4-iEW"/>
|
||||
</constraints>
|
||||
</view>
|
||||
|
|
|
@ -14,8 +14,10 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
|||
@IBOutlet weak var typeLabel: NSTextField!
|
||||
@IBOutlet weak var nameTextField: NSTextField!
|
||||
@IBOutlet weak var activeButton: NSButtonCell!
|
||||
@IBOutlet weak var credentialsButton: NSButton!
|
||||
|
||||
private weak var account: Account?
|
||||
private var accountsWindowController: NSWindowController?
|
||||
private var account: Account?
|
||||
|
||||
init(account: Account) {
|
||||
super.init(nibName: "AccountsDetail", bundle: nil)
|
||||
|
@ -28,10 +30,12 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
nameTextField.delegate = self
|
||||
typeLabel.stringValue = account?.defaultName ?? ""
|
||||
nameTextField.stringValue = account?.name ?? ""
|
||||
activeButton.state = account?.isActive ?? false ? .on : .off
|
||||
credentialsButton.isHidden = account?.type ?? .onMyMac == .onMyMac
|
||||
}
|
||||
|
||||
func controlTextDidEndEditing(_ obj: Notification) {
|
||||
|
@ -46,4 +50,20 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
|||
account?.isActive = sender.state == .on ? true : false
|
||||
}
|
||||
|
||||
@IBAction func credentials(_ sender: Any) {
|
||||
|
||||
guard let account = account else { return }
|
||||
|
||||
switch account.type {
|
||||
case .feedbin:
|
||||
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
|
||||
accountsFeedbinWindowController.account = account
|
||||
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsWindowController = accountsFeedbinWindowController
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="AccountsAddFeedbinWindowController" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="AccountsFeedbinWindowController" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="createButton" destination="9mz-D9-krh" id="p7i-JM-G69"/>
|
||||
<outlet property="actionButton" destination="9mz-D9-krh" id="ozu-6Q-9Lb"/>
|
||||
<outlet property="errorMessageLabel" destination="byK-Sd-r7F" id="8zt-9d-dWQ"/>
|
||||
<outlet property="passwordTextField" destination="JSa-LY-zNQ" id="5cF-bM-CJE"/>
|
||||
<outlet property="progressIndicator" destination="B0W-bh-Evv" id="Tiq-gx-s3F"/>
|
||||
|
@ -24,7 +24,7 @@
|
|||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<view key="contentView" id="se5-gp-TjO">
|
||||
<rect key="frame" x="0.0" y="0.0" width="433" height="249"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="horizontal" alignment="bottom" spacing="19" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7Ht-Fn-0Ya">
|
||||
<rect key="frame" x="134" y="190" width="166" height="39"/>
|
||||
|
@ -88,9 +88,6 @@
|
|||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="7Z4-KY-ChP"/>
|
||||
</connections>
|
||||
</textField>
|
||||
</gridCell>
|
||||
<gridCell row="eW8-uH-txq" column="fCQ-jY-Mts" id="Hqa-3w-cQv">
|
||||
|
@ -117,9 +114,6 @@
|
|||
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
|
||||
</allowedInputSourceLocales>
|
||||
</secureTextFieldCell>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="jAp-eC-dOn"/>
|
||||
</connections>
|
||||
</secureTextField>
|
||||
</gridCell>
|
||||
<gridCell row="DbI-7g-Xme" column="fCQ-jY-Mts" headOfMergedCell="xX0-vn-AId" xPlacement="leading" id="xX0-vn-AId">
|
||||
|
@ -136,8 +130,8 @@
|
|||
</gridCells>
|
||||
</gridView>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9mz-D9-krh">
|
||||
<rect key="frame" x="338" y="13" width="81" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Create" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="IMO-YT-k9Z">
|
||||
<rect key="frame" x="340" y="13" width="79" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Action" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="IMO-YT-k9Z">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
|
@ -145,11 +139,11 @@ DQ
|
|||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="create:" target="-2" id="jfu-Va-dnt"/>
|
||||
<action selector="action:" target="-2" id="Kix-5a-5Og"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XAM-Hb-0Hw">
|
||||
<rect key="frame" x="256" y="13" width="82" height="32"/>
|
||||
<rect key="frame" x="258" y="13" width="82" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ufs-ar-BAY">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
|
@ -10,18 +10,30 @@ import AppKit
|
|||
import Account
|
||||
import RSWeb
|
||||
|
||||
class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegate {
|
||||
class AccountsFeedbinWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet weak var progressIndicator: NSProgressIndicator!
|
||||
@IBOutlet weak var usernameTextField: NSTextField!
|
||||
@IBOutlet weak var passwordTextField: NSSecureTextField!
|
||||
@IBOutlet weak var errorMessageLabel: NSTextField!
|
||||
@IBOutlet weak var createButton: NSButton!
|
||||
@IBOutlet weak var actionButton: NSButton!
|
||||
|
||||
var account: Account?
|
||||
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("AccountsAddFeedbin"))
|
||||
self.init(windowNibName: NSNib.Name("AccountsFeedbin"))
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
if let account = account, let credentials = try? account.retrieveCredentials() {
|
||||
usernameTextField.stringValue = credentials.username ?? ""
|
||||
passwordTextField.stringValue = credentials.password ?? ""
|
||||
actionButton.title = NSLocalizedString("Update", comment: "Update")
|
||||
} else {
|
||||
actionButton.title = NSLocalizedString("Create", comment: "Create")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
@ -30,16 +42,6 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||
self.hostWindow = hostWindow
|
||||
hostWindow.beginSheet(window!, completionHandler: handler)
|
||||
}
|
||||
|
||||
// MARK: NSTextFieldDelegate
|
||||
|
||||
func controlTextDidEndEditing(_ obj: Notification) {
|
||||
if !usernameTextField.stringValue.isEmpty {
|
||||
createButton.isEnabled = true
|
||||
} else {
|
||||
createButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
@ -47,9 +49,16 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
@IBAction func create(_ sender: Any) {
|
||||
@IBAction func action(_ sender: Any) {
|
||||
|
||||
createButton.isEnabled = false
|
||||
self.errorMessageLabel.stringValue = ""
|
||||
|
||||
guard !usernameTextField.stringValue.isEmpty && !passwordTextField.stringValue.isEmpty else {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("Username & password required.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
actionButton.isEnabled = false
|
||||
progressIndicator.isHidden = false
|
||||
progressIndicator.startAnimation(self)
|
||||
|
||||
|
@ -58,7 +67,7 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||
|
||||
guard let self = self else { return }
|
||||
|
||||
self.createButton.isEnabled = true
|
||||
self.actionButton.isEnabled = true
|
||||
self.progressIndicator.isHidden = true
|
||||
self.progressIndicator.stopAnimation(self)
|
||||
|
||||
|
@ -66,9 +75,14 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||
case .success(let authenticated):
|
||||
|
||||
if authenticated {
|
||||
let account = AccountManager.shared.createAccount(type: .feedbin)
|
||||
|
||||
if self.account == nil {
|
||||
self.account = AccountManager.shared.createAccount(type: .feedbin)
|
||||
}
|
||||
|
||||
do {
|
||||
try account.storeCredentials(credentials)
|
||||
try self.account?.removeCredentials()
|
||||
try self.account?.storeCredentials(credentials)
|
||||
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
} catch {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")
|
|
@ -26,8 +26,8 @@
|
|||
5144EA43227A380F00D19003 /* ExportOPMLWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA42227A380F00D19003 /* ExportOPMLWindowController.swift */; };
|
||||
5144EA46227A5A8700D19003 /* AccountsDeleteWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA44227A5A8700D19003 /* AccountsDeleteWindowController.swift */; };
|
||||
5144EA47227A5A8700D19003 /* AccountsDelete.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA45227A5A8700D19003 /* AccountsDelete.xib */; };
|
||||
5144EA51227B8E4500D19003 /* AccountsAddFeedbinWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA4F227B8E4500D19003 /* AccountsAddFeedbinWindowController.swift */; };
|
||||
5144EA52227B8E4500D19003 /* AccountsAddFeedbin.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA50227B8E4500D19003 /* AccountsAddFeedbin.xib */; };
|
||||
5144EA51227B8E4500D19003 /* AccountsFeedbinWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA4F227B8E4500D19003 /* AccountsFeedbinWindowController.swift */; };
|
||||
5144EA52227B8E4500D19003 /* AccountsFeedbin.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA50227B8E4500D19003 /* AccountsFeedbin.xib */; };
|
||||
5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; };
|
||||
5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; };
|
||||
5183CCDD226F1F5C0010922C /* NavigationProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */; };
|
||||
|
@ -656,8 +656,8 @@
|
|||
5144EA42227A380F00D19003 /* ExportOPMLWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportOPMLWindowController.swift; sourceTree = "<group>"; };
|
||||
5144EA44227A5A8700D19003 /* AccountsDeleteWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsDeleteWindowController.swift; sourceTree = "<group>"; };
|
||||
5144EA45227A5A8700D19003 /* AccountsDelete.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountsDelete.xib; sourceTree = "<group>"; };
|
||||
5144EA4F227B8E4500D19003 /* AccountsAddFeedbinWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsAddFeedbinWindowController.swift; sourceTree = "<group>"; };
|
||||
5144EA50227B8E4500D19003 /* AccountsAddFeedbin.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountsAddFeedbin.xib; sourceTree = "<group>"; };
|
||||
5144EA4F227B8E4500D19003 /* AccountsFeedbinWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsFeedbinWindowController.swift; sourceTree = "<group>"; };
|
||||
5144EA50227B8E4500D19003 /* AccountsFeedbin.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountsFeedbin.xib; sourceTree = "<group>"; };
|
||||
5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = "<group>"; };
|
||||
5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = "<group>"; };
|
||||
5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationProgressView.swift; sourceTree = "<group>"; };
|
||||
|
@ -1602,8 +1602,8 @@
|
|||
51EF0F912279CA620050506E /* AccountsAddTableCellView.swift */,
|
||||
84C9FC7422629E1200D921D6 /* AccountsDetail.xib */,
|
||||
5144EA2E2279FAB600D19003 /* AccountsDetailViewController.swift */,
|
||||
5144EA50227B8E4500D19003 /* AccountsAddFeedbin.xib */,
|
||||
5144EA4F227B8E4500D19003 /* AccountsAddFeedbinWindowController.swift */,
|
||||
5144EA50227B8E4500D19003 /* AccountsFeedbin.xib */,
|
||||
5144EA4F227B8E4500D19003 /* AccountsFeedbinWindowController.swift */,
|
||||
5144EA352279FC3D00D19003 /* AccountsAddLocal.xib */,
|
||||
5144EA372279FC6200D19003 /* AccountsAddLocalWindowController.swift */,
|
||||
5144EA45227A5A8700D19003 /* AccountsDelete.xib */,
|
||||
|
@ -2215,7 +2215,7 @@
|
|||
848362FD2262A30800DA1D35 /* styleSheet.css in Resources */,
|
||||
8483630B2262A3F000DA1D35 /* RenameSheet.xib in Resources */,
|
||||
848363052262A3CC00DA1D35 /* AddFolderSheet.xib in Resources */,
|
||||
5144EA52227B8E4500D19003 /* AccountsAddFeedbin.xib in Resources */,
|
||||
5144EA52227B8E4500D19003 /* AccountsFeedbin.xib in Resources */,
|
||||
8405DDA222168920008CE1BF /* TimelineTableView.xib in Resources */,
|
||||
8483630E2262A3FE00DA1D35 /* MainWindow.storyboard in Resources */,
|
||||
84BAE64921CEDAF20046DB56 /* CrashReporterWindow.xib in Resources */,
|
||||
|
@ -2439,7 +2439,7 @@
|
|||
8472058120142E8900AD578B /* FeedInspectorViewController.swift in Sources */,
|
||||
5144EA382279FC6200D19003 /* AccountsAddLocalWindowController.swift in Sources */,
|
||||
84AD1EAA2031617300BC20B7 /* FolderPasteboardWriter.swift in Sources */,
|
||||
5144EA51227B8E4500D19003 /* AccountsAddFeedbinWindowController.swift in Sources */,
|
||||
5144EA51227B8E4500D19003 /* AccountsFeedbinWindowController.swift in Sources */,
|
||||
84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */,
|
||||
845A29241FC9255E007B49E3 /* SidebarCellAppearance.swift in Sources */,
|
||||
84F3EE1620DEC97E003FADEB /* FeedFinder.swift in Sources */,
|
||||
|
|
Loading…
Reference in New Issue