add authentication method selection UI

This commit is contained in:
Bob Sun 2017-01-25 18:28:37 +08:00
parent fcef83277f
commit cc7a53781c
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
9 changed files with 273 additions and 7 deletions

View file

@ -94,7 +94,7 @@
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="K0b-qZ-UOk" kind="show" identifier="gitServerSetting" id="lTe-xz-AE8"/>
<segue destination="K0b-qZ-UOk" kind="show" id="Y7o-EF-Fj2"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="sshKeyTableViewCell" textLabel="39M-pD-G4c" style="IBUITableViewCellStyleDefault" id="D5Y-70-cIk">
@ -165,10 +165,10 @@
</objects>
<point key="canvasLocation" x="2425" y="2424"/>
</scene>
<!--Key Setting Form View Controller-->
<!--SSH Key Setting Form View Controller-->
<scene sceneID="o8D-OA-kri">
<objects>
<viewController id="2wS-CW-naM" customClass="SSHKeySettingFormViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController"/>
<viewController id="2wS-CW-naM" userLabel="SSH Key Setting Form View Controller" customClass="SSHKeySettingFormViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="DSc-wl-N2L" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3430" y="2473"/>
@ -273,6 +273,37 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="s6v-aZ-kaD">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="Gar-Yh-ZKL" detailTextLabel="Tjx-af-c7u" style="IBUITableViewCellStyleValue1" id="skE-NA-SBb">
<rect key="frame" x="0.0" y="227" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="skE-NA-SBb" id="xec-0B-cTD">
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Authentication" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Gar-Yh-ZKL">
<rect key="frame" x="15" y="11" width="111" height="21"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Not Set" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Tjx-af-c7u">
<rect key="frame" x="282" y="11" width="58" height="21"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="4Hl-LX-rKS" kind="show" identifier="selectAuthenticationMethod" id="7nl-GC-PCz"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="ynQ-64-MfA" id="q89-h8-Hqq"/>
@ -294,6 +325,7 @@
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="authenticationTableViewCell" destination="skE-NA-SBb" id="Tc1-FF-nhM"/>
<outlet property="gitRepositoryURLTextField" destination="EVT-VU-sCi" id="2EH-Uq-tbU"/>
<outlet property="passwordTextField" destination="hSW-BQ-SXN" id="uFS-s5-yfZ"/>
<outlet property="usernameTextField" destination="cxu-dD-J2H" id="RjU-Hf-xyw"/>
@ -302,7 +334,76 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="7c1-c7-Qyp" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="7K9-cE-9qq" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="4383" y="1752"/>
<point key="canvasLocation" x="4381.6000000000004" y="1751.8740629685158"/>
</scene>
<!--Git Repository Authentication Setting Table View Controller-->
<scene sceneID="xth-c9-Oea">
<objects>
<tableViewController id="4Hl-LX-rKS" customClass="GitRepositoryAuthenticationSettingTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="g4G-LT-2oZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection id="gnN-PG-erQ">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="pyY-6T-Ar4" style="IBUITableViewCellStyleDefault" id="GZS-hV-7Yy">
<rect key="frame" x="0.0" y="35" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="GZS-hV-7Yy" id="wRk-ML-bpj">
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Password" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pyY-6T-Ar4">
<rect key="frame" x="15" y="0.0" width="345" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="MfG-VE-Ork" kind="unwind" unwindAction="saveWithSegue:" id="QZM-o4-88Q"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="844-Ya-Uiz" style="IBUITableViewCellStyleDefault" id="ahw-Sp-Et2">
<rect key="frame" x="0.0" y="79" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ahw-Sp-Et2" id="gjE-7z-REN">
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="SSH Key" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="844-Ya-Uiz">
<rect key="frame" x="15" y="0.0" width="345" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="MfG-VE-Ork" kind="unwind" unwindAction="saveWithSegue:" id="eBA-wP-36P"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="4Hl-LX-rKS" id="eKS-rA-GFV"/>
<outlet property="delegate" destination="4Hl-LX-rKS" id="ILw-Ae-IBj"/>
</connections>
</tableView>
<connections>
<outlet property="passwordCell" destination="GZS-hV-7Yy" id="wyf-vh-roY"/>
<outlet property="sshKeyCell" destination="ahw-Sp-Et2" id="4QS-fY-Z5M"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="e1d-uR-lAI" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="MfG-VE-Ork" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="5127" y="1751"/>
</scene>
<!--PGP Key-->
<scene sceneID="8Hi-tl-elT">

View file

@ -17,6 +17,7 @@ extension DefaultsKeys {
static let pgpKeyUserID = DefaultsKey<String>("pgpKeyUserID")
static let gitRepositoryURL = DefaultsKey<URL?>("gitRepositoryURL")
static let gitRepositoryAuthenticationMethod = DefaultsKey<String>("gitRepositoryAuthenticationMethod")
static let gitRepositoryUsername = DefaultsKey<String>("gitRepositoryUsername")
static let gitRepositoryPassword = DefaultsKey<String>("gitRepositoryPassword")
static let gitRepositorySSHPublicKeyURL = DefaultsKey<URL?>("gitRepositorySSHPublicKeyURL")

View file

@ -0,0 +1,30 @@
//
// GitRepositoryAuthenticationSettingTableViewController.swift
// pass
//
// Created by Mingshen Sun on 25/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class GitRepositoryAuthenticationSettingTableViewController: UITableViewController {
var selectedMethod: String?
@IBOutlet weak var sshKeyCell: UITableViewCell!
@IBOutlet weak var passwordCell: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
switch selectedMethod! {
case "Password":
passwordCell.accessoryType = UITableViewCellAccessoryType.checkmark
case "SSH Key":
sshKeyCell.accessoryType = UITableViewCellAccessoryType.checkmark
default:
break
}
}
}

View file

@ -26,6 +26,7 @@ class GitServerSettingTableViewController: UITableViewController {
}
usernameTextField.text = Defaults[.gitRepositoryUsername]
passwordTextField.text = Defaults[.gitRepositoryPassword]
authenticationTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryAuthenticationMethod]
}
override func viewDidAppear(_ animated: Bool) {
@ -37,4 +38,21 @@ class GitServerSettingTableViewController: UITableViewController {
super.viewWillDisappear(animated)
view.endEditing(true)
}
@IBAction func save(segue: UIStoryboardSegue) {
if let controller = segue.source as? UITableViewController {
if controller.tableView.indexPathForSelectedRow == IndexPath(row: 0, section:0) {
authenticationTableViewCell.detailTextLabel?.text = "Password"
} else {
authenticationTableViewCell.detailTextLabel?.text = "SSH Key"
}
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "selectAuthenticationMethod" {
if let controller = segue.destination as? GitRepositoryAuthenticationSettingTableViewController {
controller.selectedMethod = authenticationTableViewCell.detailTextLabel!.text
}
}
}
}

View file

@ -12,5 +12,24 @@ class SSHKeySettingFormViewController: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
let publicKeyURLTextFieldRow = TextFieldRowFormer<TextFieldTableViewCell>(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in
row.titleLabel.text = "SSH Public Key URL"
}.configure { (row) in
row.rowHeight = 52
}
let privateKeyURLTextFieldRow = TextFieldRowFormer<TextFieldTableViewCell>(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in
row.titleLabel.text = "SSH Private Key URL"
}.configure { (row) in
row.rowHeight = 52
}
let privateKeyPhassphraseTextFieldRow = TextFieldRowFormer<TextFieldTableViewCell>(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in
row.titleLabel.text = "Phassphrase"
row.textField.isSecureTextEntry = true
}.configure { (row) in
row.rowHeight = 52
}
former.append(sectionFormer: SectionFormer(rowFormer: publicKeyURLTextFieldRow, privateKeyURLTextFieldRow, privateKeyPhassphraseTextFieldRow))
}
}

View file

@ -23,6 +23,13 @@ class SettingsTableViewController: UITableViewController {
let gitRepostiroyURL = controller.gitRepositoryURLTextField.text!
let username = controller.usernameTextField.text!
let password = controller.passwordTextField.text!
let auth = controller.authenticationTableViewCell.detailTextLabel!.text!
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
Defaults[.gitRepositoryUsername] = username
Defaults[.gitRepositoryPassword] = password
Defaults[.gitRepositoryAuthenticationMethod] = auth
if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString {
SVProgressHUD.setDefaultMaskType(.black)
@ -47,9 +54,6 @@ class SettingsTableViewController: UITableViewController {
if ret {
SVProgressHUD.showSuccess(withStatus: "Done")
SVProgressHUD.dismiss(withDelay: 1)
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
Defaults[.gitRepositoryUsername] = username
Defaults[.gitRepositoryPassword] = password
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
} else {

View file

@ -0,0 +1,30 @@
//
// TextFieldTableViewCell.swift
// pass
//
// Created by Mingshen Sun on 25/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import Former
class TextFieldTableViewCell: UITableViewCell, TextFieldFormableRow {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var textField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
}
func formTextField() -> UITextField {
return textField
}
func formTitleLabel() -> UILabel? {
return titleLabel
}
func updateWithRowFormer(_ rowFormer: RowFormer) {}
}

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="TextFieldTableViewCell" customModule="pass" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="51.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SSH" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TXd-7c-hmg">
<rect key="frame" x="15" y="8" width="297" height="15"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="DT2-vj-95g">
<rect key="frame" x="15" y="24.5" width="297" height="19"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="alphabet"/>
</textField>
</subviews>
<constraints>
<constraint firstItem="DT2-vj-95g" firstAttribute="leading" secondItem="TXd-7c-hmg" secondAttribute="leading" id="DOC-hb-j7C"/>
<constraint firstItem="DT2-vj-95g" firstAttribute="trailing" secondItem="TXd-7c-hmg" secondAttribute="trailing" id="EHV-Co-Y1Q"/>
<constraint firstAttribute="bottomMargin" secondItem="DT2-vj-95g" secondAttribute="bottom" id="dlf-Ny-wun"/>
<constraint firstItem="TXd-7c-hmg" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="7" id="j7z-8j-948"/>
<constraint firstAttribute="trailingMargin" secondItem="TXd-7c-hmg" secondAttribute="trailing" id="kR8-St-nI0"/>
<constraint firstAttribute="topMargin" secondItem="TXd-7c-hmg" secondAttribute="top" id="uQl-UG-MDc"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="textField" destination="DT2-vj-95g" id="zJm-Nj-9fR"/>
<outlet property="titleLabel" destination="TXd-7c-hmg" id="oCI-QR-aFa"/>
</connections>
<point key="canvasLocation" x="42" y="126.5"/>
</tableViewCell>
</objects>
</document>