Implement creating password

This commit is contained in:
Ivan Grachyov 2021-06-19 00:38:05 +03:00
parent d9309ffee7
commit 67074f2211
6 changed files with 119 additions and 37 deletions

View File

@ -38,7 +38,7 @@
2C8A09EB2675964700993638 /* ApproveViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8A09EA2675964700993638 /* ApproveViewController.swift */; };
2C8A09EE2675965F00993638 /* WaitingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8A09ED2675965F00993638 /* WaitingViewController.swift */; };
2C917429267D2A6E00049075 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C917428267D2A6E00049075 /* Keychain.swift */; };
2CDAB3722675B3F0009F8B97 /* PinViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CDAB3712675B3F0009F8B97 /* PinViewController.swift */; };
2CDAB3722675B3F0009F8B97 /* PasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */; };
88745B0F4DEE1F60AD0F02C3 /* Pods_Encrypted_Ink.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3704D7F64179CCDCE2E8C783 /* Pods_Encrypted_Ink.framework */; };
/* End PBXBuildFile section */
@ -79,7 +79,7 @@
2C8A09EA2675964700993638 /* ApproveViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApproveViewController.swift; sourceTree = "<group>"; };
2C8A09ED2675965F00993638 /* WaitingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitingViewController.swift; sourceTree = "<group>"; };
2C917428267D2A6E00049075 /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
2CDAB3712675B3F0009F8B97 /* PinViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinViewController.swift; sourceTree = "<group>"; };
2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordViewController.swift; sourceTree = "<group>"; };
3704D7F64179CCDCE2E8C783 /* Pods_Encrypted_Ink.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Encrypted_Ink.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -191,7 +191,7 @@
children = (
2C1995412674C4B900A8E370 /* ImportViewController.swift */,
2C797E7D267BB88800F2CE2D /* WelcomeViewController.swift */,
2CDAB3712675B3F0009F8B97 /* PinViewController.swift */,
2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */,
2C8A09E72675960D00993638 /* ErrorViewController.swift */,
2C8A09EA2675964700993638 /* ApproveViewController.swift */,
2C8A09ED2675965F00993638 /* WaitingViewController.swift */,
@ -380,7 +380,7 @@
2C8A09E82675960D00993638 /* ErrorViewController.swift in Sources */,
2C1995422674C4B900A8E370 /* ImportViewController.swift in Sources */,
2C8A09B52675101300993638 /* AccountsService.swift in Sources */,
2CDAB3722675B3F0009F8B97 /* PinViewController.swift in Sources */,
2CDAB3722675B3F0009F8B97 /* PasswordViewController.swift in Sources */,
2C1995402674C4B900A8E370 /* AppDelegate.swift in Sources */,
0DB729142674E2DB0011F7A1 /* EIP712Parameter.swift in Sources */,
0DB7291B2674E2DB0011F7A1 /* EIP712Hash.swift in Sources */,

View File

@ -11,6 +11,7 @@ class Agent {
private init() {}
private var statusBarItem: NSStatusItem!
private var hasPassword = Keychain.password != nil
func start() {
checkPasteboardAndOpen(onAppStart: true)
@ -29,6 +30,16 @@ class Agent {
windowController = Window.showNew()
}
guard hasPassword else {
let welcomeViewController = WelcomeViewController.new { [weak self] createdPassword in
guard createdPassword else { return }
self?.hasPassword = true
self?.showInitialScreen(onAppStart: onAppStart, wcSession: wcSession)
}
windowController.contentViewController = welcomeViewController
return
}
let completion = onSelectedAccount(session: wcSession)
let accounts = AccountsService.getAccounts()
if !accounts.isEmpty {

View File

@ -1185,17 +1185,17 @@ DQ
</objects>
<point key="canvasLocation" x="380" y="1177"/>
</scene>
<!--Pin View Controller-->
<!--Password View Controller-->
<scene sceneID="Riu-mP-tQs">
<objects>
<viewController storyboardIdentifier="PinViewController" id="KMi-XY-mOg" customClass="PinViewController" customModule="Encrypted_Ink" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="PasswordViewController" id="KMi-XY-mOg" customClass="PasswordViewController" customModule="Encrypted_Ink" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="Efz-OH-wm2">
<rect key="frame" x="0.0" y="0.0" width="250" height="350"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Gdw-Q4-bo0">
<rect key="frame" x="14" y="292" width="222" height="34"/>
<textFieldCell key="cell" controlSize="large" selectable="YES" alignment="center" title="Pin" id="8sq-L4-gvS">
<rect key="frame" x="14" y="258" width="222" height="68"/>
<textFieldCell key="cell" controlSize="large" selectable="YES" alignment="center" title="Create Password" id="8sq-L4-gvS">
<font key="font" metaFont="systemHeavy" size="29"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -1245,7 +1245,7 @@ DQ
<constraints>
<constraint firstAttribute="width" constant="160" id="PLH-bk-GPE"/>
</constraints>
<secureTextFieldCell key="cell" controlSize="large" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="border" alignment="center" placeholderString="Code" drawsBackground="YES" usesSingleLineMode="YES" id="Szl-cI-dPv">
<secureTextFieldCell key="cell" controlSize="large" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="border" alignment="center" placeholderString="Password" drawsBackground="YES" usesSingleLineMode="YES" id="Szl-cI-dPv">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -1266,7 +1266,9 @@ DQ
</constraints>
</view>
<connections>
<outlet property="codeTextField" destination="bsj-p7-maG" id="BA8-jH-AlN"/>
<outlet property="cancelButton" destination="cWf-at-SKV" id="bwN-MG-z5Z"/>
<outlet property="okButton" destination="N8k-Bq-UNz" id="TCK-eo-6gc"/>
<outlet property="passwordTextField" destination="bsj-p7-maG" id="pgZ-fr-vJO"/>
<outlet property="titleLabel" destination="Gdw-Q4-bo0" id="DEt-cI-9Qc"/>
</connections>
</viewController>

View File

@ -0,0 +1,86 @@
// Copyright © 2021 Encrypted Ink. All rights reserved.
import Cocoa
class PasswordViewController: NSViewController {
static func with(mode: Mode, completion: ((Bool) -> Void)?) -> PasswordViewController {
let new = instantiate(PasswordViewController.self)
new.mode = mode
new.completion = completion
return new
}
enum Mode {
case create, repeatAfterCreate, enter
}
private var mode = Mode.create
private var passwordToRepeat: String?
private var completion: ((Bool) -> Void)?
@IBOutlet weak var cancelButton: NSButton!
@IBOutlet weak var okButton: NSButton!
@IBOutlet weak var titleLabel: NSTextField!
@IBOutlet weak var passwordTextField: NSSecureTextField! {
didSet {
passwordTextField.delegate = self
}
}
override func viewDidLoad() {
super.viewDidLoad()
switchToMode(mode)
}
func switchToMode(_ mode: Mode) {
self.mode = mode
switch mode {
case .create:
titleLabel.stringValue = "Create Password"
passwordToRepeat = nil
case .repeatAfterCreate:
titleLabel.stringValue = "Repeat Password"
passwordToRepeat = passwordTextField.stringValue
case .enter:
titleLabel.stringValue = "Enter Password"
}
passwordTextField.stringValue = ""
okButton.isEnabled = false
}
@IBAction func actionButtonTapped(_ sender: Any) {
switch mode {
case .create:
switchToMode(.repeatAfterCreate)
case .repeatAfterCreate:
let repeated = passwordTextField.stringValue
if repeated == passwordToRepeat {
Keychain.save(password: repeated)
completion?(true)
}
case .enter:
print("yo") // TODO: implement
}
}
@IBAction func cancelButtonTapped(_ sender: NSButton) {
switch mode {
case .create:
view.window?.contentViewController = WelcomeViewController.new(completion: completion)
case .repeatAfterCreate:
switchToMode(.create)
case .enter:
Window.closeAll() // TODO: implement
}
}
}
extension PasswordViewController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
okButton.isEnabled = passwordTextField.stringValue.count >= 4
}
}

View File

@ -1,26 +0,0 @@
// Copyright © 2021 Encrypted Ink. All rights reserved.
import Cocoa
class PinViewController: NSViewController {
enum Mode {
case create, enter
}
@IBOutlet weak var titleLabel: NSTextField!
@IBOutlet weak var codeTextField: NSSecureTextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func actionButtonTapped(_ sender: Any) {
}
@IBAction func cancelButtonTapped(_ sender: NSButton) {
}
}

View File

@ -4,16 +4,25 @@ import Cocoa
class WelcomeViewController: NSViewController {
static func new(completion: ((Bool) -> Void)?) -> WelcomeViewController {
let new = instantiate(WelcomeViewController.self)
new.completion = completion
return new
}
@IBOutlet weak var titleLabel: NSTextField!
@IBOutlet weak var messageLabel: NSTextField!
private var completion: ((Bool) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
messageLabel.stringValue = "Sign crypto transactions.\n\nIn any browser.\n\nOn any website."
}
@IBAction func actionButtonTapped(_ sender: Any) {
// TODO: go to password creation
let passwordViewController = PasswordViewController.with(mode: .create, completion: completion)
view.window?.contentViewController = passwordViewController
}
}