git.iko.soy/dashared/GDproject
on master help sign in
started developing log in - log out
commit665bd8e0ffbc1f49d53e60b6579d61193840fc53 authorDarya Rednikina <rednikina.com@yandex.ru> dateSat 23 Feb 2019, 18:59 (8 years ago) parent13f2878
7 files changed+83−14
GDproject.xcodeproj/project.pbxproj+13−1 GDproject/Base.lproj/Main.storyboard+1−1 GDproject/Controller/Log In/LogInCoordinator.swift+42 GDproject/Controller/LogInViewController.swift → GDproject/Controller/Log In/LogInViewController.swift+3−5 GDproject/Controller/Profile/ProfileViewController.swift+10−2 GDproject/Extentions.swift+6−2 GDproject/Supporting files/AppDelegate.swift+8−3
GDproject.xcodeproj/project.pbxproj+13−1
@@ -15,6 +15,7 @@
1515 1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1288B5CD221F1158002BE6B1 /* DataStorage.swift */; };
1616 1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
1717 1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */; };
18+ 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE3522218DBF009D3F23 /* LogInCoordinator.swift */; };
1819 12D7D133221C321600B35452 /* ChannelListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D132221C321600B35452 /* ChannelListController.swift */; };
1920 12D7D135221C42B700B35452 /* ChannelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D134221C42B700B35452 /* ChannelController.swift */; };
2021 12D7D137221D78E800B35452 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D136221D78E800B35452 /* Channel.swift */; };
@@ -74,6 +75,7 @@
7475 1288B5CD221F1158002BE6B1 /* DataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStorage.swift; sourceTree = "<group>"; };
7576 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsCoordinator.swift; sourceTree = "<group>"; };
7677 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbarCoordinator.swift; sourceTree = "<group>"; };
78+ 1291BE3522218DBF009D3F23 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
7779 12D7D132221C321600B35452 /* ChannelListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelListController.swift; sourceTree = "<group>"; };
7880 12D7D134221C42B700B35452 /* ChannelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelController.swift; sourceTree = "<group>"; };
7981 12D7D136221D78E800B35452 /* Channel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = "<group>"; };
@@ -140,6 +142,15 @@
140142 path = "Coordinator tab bar?";
141143 sourceTree = "<group>";
142144 };
145+ 1291BE3722218DC4009D3F23 /* Log In */ = {
146+ isa = PBXGroup;
147+ children = (
148+ 123E37A4221F1B3200F6E42A /* LogInViewController.swift */,
149+ 1291BE3522218DBF009D3F23 /* LogInCoordinator.swift */,
150+ );
151+ path = "Log In";
152+ sourceTree = "<group>";
153+ };
143154 12E36D8F221424EA006FCDD7 = {
144155 isa = PBXGroup;
145156 children = (
@@ -203,7 +214,7 @@
203214 isa = PBXGroup;
204215 children = (
205216 1291BE32222154C3009D3F23 /* Coordinator tab bar? */,
206− 123E37A4221F1B3200F6E42A /* LogInViewController.swift */,
217+ 1291BE3722218DC4009D3F23 /* Log In */,
207218 1288B5CC221F0EFE002BE6B1 /* Profile */,
208219 12E36DD322156519006FCDD7 /* News and channels */,
209220 );
@@ -306,6 +317,7 @@
306317 files = (
307318 12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */,
308319 12D7D137221D78E800B35452 /* Channel.swift in Sources */,
320+ 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */,
309321 12E36DB922144016006FCDD7 /* User.swift in Sources */,
310322 125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
311323 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+1−1
@@ -465,7 +465,7 @@
465465 <!--Navigation Controller-->
466466 <scene sceneID="r0M-xH-UwU">
467467 <objects>
468− <navigationController id="609-2j-gc9" sceneMemberID="viewController">
468+ <navigationController storyboardIdentifier="root" id="609-2j-gc9" sceneMemberID="viewController">
469469 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Ah8-NU-AsD">
470470 <rect key="frame" x="0.0" y="20" width="375" height="44"/>
471471 <autoresizingMask key="autoresizingMask"/>
GDproject/Controller/Log In/LogInCoordinator.swiftnew file+42
@@ -0,0 +1,42 @@
1+//
2+// LogInCoordinator.swift
3+// GDproject
4+//
5+// Created by cstore on 23/02/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class LogInCoordinator{
12+
13+ private weak var navigationController: UINavigationController?
14+ private var window: UIWindow!
15+ // MARK:- Init
16+ init(navigationController: UINavigationController, window: UIWindow) {
17+ self.navigationController = navigationController
18+ self.window = window
19+ }
20+
21+ func start(){
22+ showLogInPage()
23+ }
24+
25+ // MARK: - Private implementation
26+ private func showStatusPage(){
27+ let controller = TabbarCoordinator(window: window)
28+ controller.start()
29+ }
30+
31+ private func showLogInPage(){
32+ let controller = UIStoryboard.makeLogIn()
33+ //controller.channel = channel
34+ controller.onLogIn = { [weak self] in
35+ self?.showStatusPage()
36+ DataStorage.standard.setIsLoggedIn(value: true)
37+ }
38+ //navigationController?.setViewControllers([controller], animated: false)
39+ navigationController?.pushViewController(controller, animated: false)
40+ }
41+
42+}
GDproject/Controller/LogInViewController.swift → GDproject/Controller/Log In/LogInViewController.swiftrenamed+3−5
@@ -12,6 +12,8 @@ class LogInViewController: UIViewController {
1212
1313 @IBOutlet weak var mailTextField: UITextField!
1414
15+ var onLogIn: (()->())?
16+
1517 static let titleColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 0.5)
1618
1719 var bottomConstraint: NSLayoutConstraint?
@@ -62,11 +64,7 @@ class LogInViewController: UIViewController {
6264 @objc func activateLogInProcess(){
6365 if logInButton.isEnabled {
6466 // MARK:- when log in is succeeded do I need to go there?
65− let vc = storyboard!.instantiateViewController(withIdentifier: newsController) as! NewsController
66− present(vc, animated: true) {
67− print("logged in")
68− }
69− DataStorage.standard.setIsLoggedIn(value: true)
67+ onLogIn?()
7068 view.endEditing(true)
7169 }
7270 }
GDproject/Controller/Profile/ProfileViewController.swift+10−2
@@ -104,12 +104,20 @@ class ProfileViewController: UIViewController
104104 }
105105
106106 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
107− let shareAction = UIAlertAction(title: "Share", style: .default)
107+ let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
108+ {
109+ [weak self] (_) in
110+
111+ let root = UIStoryboard.navRoot()
112+ UIApplication.shared.keyWindow?.rootViewController = root
113+ let coordinator = LogInCoordinator(navigationController: root, window: UIApplication.shared.keyWindow!)
114+ coordinator.start()
115+ }
108116
109117 optionMenu.addAction(editAction)
110118 optionMenu.addAction(settingsAction)
111119 optionMenu.addAction(copyLink)
112− optionMenu.addAction(shareAction)
120+ optionMenu.addAction(logoutAction)
113121 optionMenu.addAction(cancelAction)
114122
115123 self.present(optionMenu, animated: true, completion: nil)
GDproject/Extentions.swift+6−2
@@ -52,7 +52,11 @@ extension UIStoryboard {
5252 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController
5353 }
5454
55− class func navChannels() ->UINavigationController{
56− return UIStoryboard.userEdit.instantiateViewController(withIdentifier: "navChannels") as! UINavigationController
55+ class func navRoot() -> UINavigationController{
56+ return UIStoryboard.userEdit.instantiateViewController(withIdentifier: "root") as! UINavigationController
57+ }
58+
59+ class func makeLogIn() -> LogInViewController {
60+ return UIStoryboard.userEdit.instantiateViewController(withIdentifier: logInController) as! LogInViewController
5761 }
5862}
GDproject/Supporting files/AppDelegate.swift+8−3
@@ -11,7 +11,7 @@ import UIKit
1111@UIApplicationMain
1212class AppDelegate: UIResponder, UIApplicationDelegate {
1313
14− var coordinator: ChannelsCoordinator!
14+ var coordinator: LogInCoordinator!
1515 var tabCoordinator: TabbarCoordinator!
1616
1717 var window: UIWindow?
@@ -27,8 +27,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727 {
2828
2929 // TODO:- determine what to do here: log in or tabbar
30− tabCoordinator = TabbarCoordinator(window: window!)
31− tabCoordinator.start()
30+ if DataStorage.standard.isLoggedIn() {
31+ tabCoordinator = TabbarCoordinator(window: window!)
32+ tabCoordinator.start()
33+ } else {
34+ coordinator = LogInCoordinator(navigationController: rootController!, window: window!)
35+ coordinator.start()
36+ }
3237
3338 return true
3439 }