OnboardingNavigator.swift 1.81 KB
Newer Older
domenicw's avatar
domenicw committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
//  OnboardingNavigator.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 18.09.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation
import UIKit

public class OnboardingNavigator: Navigator {
    
    // MARK: - Variables
    
domenicw's avatar
domenicw committed
16
17
    public var delegate: OnboardingNavigatorDelegate?
    
domenicw's avatar
domenicw committed
18
19
20
21
22
23
24
25
26
    public var rootViewController: UIViewController {
        return self.navigationController
    }
    
    private var navigationController: UINavigationController
    
    // MARK: - Initializers
    
    public init() {
domenicw's avatar
domenicw committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        let info = InfoViewController(model: .create())
        self.navigationController = UINavigationController(rootViewController: info)
        info.delegate = self
    }
    
    // MARK: - Navigation
    
    private func presentLogin() {
        let login = LoginViewController(model: .createOnboarding())
        login.delegate = self
        self.navigationController.present(login, animated: true, completion: nil)
    }
    
}

extension OnboardingNavigator: InfoViewControllerDelegate {
    
    public func buttonPressed() {
        self.presentLogin()
    }
    
    public func smallButtonPressed() {
        self.delegate?.onboardingFinished()
    }
    
}

extension OnboardingNavigator: LoginViewControllerDelegate {
    
    public func login(username: String, password: String) {
domenicw's avatar
domenicw committed
57
        // TODO: - Check for valid credentials
domenicw's avatar
domenicw committed
58
        debugPrint("Logging in with username: \(username) and password: \(password)")
domenicw's avatar
domenicw committed
59
60
61
62
        let keychain = KeychainSwift()
        keychain.set(password, forKey: KeychainKey.password.rawValue)
        keychain.set(username, forKey: KeychainKey.username.rawValue)
        keychain.synchronizable = true
domenicw's avatar
domenicw committed
63
64
65
66
67
        self.delegate?.onboardingFinished()
    }
    
    public func smallButtonTapped() {
        self.delegate?.onboardingFinished()
domenicw's avatar
domenicw committed
68
69
70
    }
    
}