소스 검색

add force login

alqindiirsyam 2 년 전
부모
커밋
d2632707d4

+ 2 - 2
appbuilder-ios/AppBuilder/AppBuilder/FourthTabViewController.swift

@@ -118,7 +118,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
     }
     
     func makeMenu(imageSignIn: String = ""){
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         Database.shared.database?.inTransaction({ fmdb, rollback in
             let idMe = UserDefaults.standard.string(forKey: "me") as String?
             if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
@@ -437,7 +437,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                             Nexilis.changeUser(f_pin: id)
                             UserDefaults.standard.setValue(id, forKey: "me")
                             UserDefaults.standard.set("", forKey: "pwd")
-                            UserDefaults.standard.set(false, forKey: "is_change_profile")
+                            Utils.setProfile(value: false)
                             UserDefaults.standard.synchronize()
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))

+ 16 - 1
appbuilder-ios/AppBuilder/AppBuilder/ViewController.swift

@@ -175,7 +175,7 @@ class ViewController: UITabBarController, UITabBarControllerDelegate {
     }
     
     public static func checkIsChangePerson() -> Bool {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized().localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .destructive, handler: {_ in
@@ -392,6 +392,21 @@ class ViewController: UITabBarController, UITabBarControllerDelegate {
         let acceptTerm = PrefsUtil.getTerms()
         if !acceptTerm {
             showWelocomeView()
+        } else {
+            if !Utils.getForceAnonymous() && !Utils.getSetProfile() {
+                let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
+                controller.forceLogin = true
+                let navigationController = UINavigationController(rootViewController: controller)
+                navigationController.navigationBar.tintColor = .white
+                navigationController.navigationBar.barTintColor = .mainColor
+                navigationController.navigationBar.isTranslucent = false
+                let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
+                navigationController.navigationBar.titleTextAttributes = textAttributes
+                navigationController.view.backgroundColor = .mainColor
+                navigationController.modalPresentationStyle = .fullScreen
+                navigationController.modalTransitionStyle = .crossDissolve
+                self.present(navigationController, animated: true)
+            }
         }
     }
     

+ 2 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/CoreMessage_TMessageKey.swift

@@ -482,4 +482,6 @@ public class CoreMessage_TMessageKey {
     public static let WORKING_AREA = "WKA";
     public static let IS_SECOND_LAYER = "ISL";
     
+    public static let IS_ENABLED_ANONYMOUS = "A999";
+    
 }

+ 8 - 8
appbuilder-ios/NexilisLite/NexilisLite/Source/FloatingButton/FloatingButton.swift

@@ -390,7 +390,7 @@ public class FloatingButton: UIView {
     
     @objc func tapMoreApp(_ sender: UIButton) {
         let id = sender.restorationIdentifier
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -427,7 +427,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func fb1Tap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -481,7 +481,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func fb2Tap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -525,7 +525,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func fb3Tap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -570,7 +570,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func fb4Tap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -614,7 +614,7 @@ public class FloatingButton: UIView {
     }
 
     @objc func bniBookingTap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -651,7 +651,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func openCustomURL(url: String) {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
@@ -689,7 +689,7 @@ public class FloatingButton: UIView {
     }
     
     @objc func historyBroadcastTap() {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in

+ 18 - 14
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -121,6 +121,8 @@ public class Nexilis: NSObject {
             if(!id.isEmpty && (UserDefaults.standard.string(forKey: "me") == nil)){
                 if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000){
                     id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
+                    let enable_signup = (response.getBody(key: CoreMessage_TMessageKey.IS_ENABLED_ANONYMOUS, default_value: "0")) == "1"
+                    Utils.setForceAnonymous(value: enable_signup)
                     if(!id.isEmpty) {
                         Nexilis.changeUser(f_pin: id)
                         UserDefaults.standard.setValue(id, forKey: "me")
@@ -133,21 +135,23 @@ public class Nexilis: NSObject {
             }
             
             if let me = UserDefaults.standard.string(forKey: "me") {
-                _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: me))
-                DispatchQueue.global().asyncAfter(deadline: .now() + 1.5, execute: {
-                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
-                        if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT image_id FROM GROUPZ where group_type = 1 AND official = 1"), cursorData.next() {
-                            do {
-                                let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
-                                let file = documentDir.appendingPathComponent(cursorData.string(forColumnIndex: 0)!)
-                                if !FileManager().fileExists(atPath: file.path) {
-                                    Download().start(forKey: cursorData.string(forColumnIndex: 0)!) { (name, progress) in}
-                                }
-                            } catch {}
-                            cursorData.close()
-                        }
+                if Utils.getForceAnonymous() {
+                    _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: me))
+                    DispatchQueue.global().asyncAfter(deadline: .now() + 1.5, execute: {
+                        Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                            if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT image_id FROM GROUPZ where group_type = 1 AND official = 1"), cursorData.next() {
+                                do {
+                                    let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
+                                    let file = documentDir.appendingPathComponent(cursorData.string(forColumnIndex: 0)!)
+                                    if !FileManager().fileExists(atPath: file.path) {
+                                        Download().start(forKey: cursorData.string(forColumnIndex: 0)!) { (name, progress) in}
+                                    }
+                                } catch {}
+                                cursorData.close()
+                            }
+                        })
                     })
-                })
+                }
                 delegate.onSuccess(userId: me)
                 if showButton {
                     DispatchQueue.main.async {

+ 16 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Utils.swift

@@ -38,6 +38,22 @@ public final class Utils {
         return Int64((ProcessInfo().systemUptime * 1000_000_000).rounded()) // SystemClock.elapsedRealtimeNano();
     }
     
+    public static func getForceAnonymous() -> Bool {
+        return UserDefaults.standard.bool(forKey: "force_anonymous")
+    }
+    
+    public static func setForceAnonymous(value: Bool){
+        UserDefaults.standard.set(value, forKey: "force_anonymous")
+    }
+    
+    public static func getSetProfile() -> Bool {
+        return UserDefaults.standard.bool(forKey: "is_change_profile")
+    }
+    
+    public static func setProfile(value: Bool){
+        UserDefaults.standard.set(value, forKey: "is_change_profile")
+    }
+    
     public static func sGetCurrentDateTime(sFormat: String!) -> String! {
         let todaysDate = NSDate()
         let dateFormatter = DateFormatter()

+ 7 - 2
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeDeviceViewController.swift

@@ -15,6 +15,7 @@ public class ChangeDeviceViewController: UIViewController {
     @IBOutlet weak var showPasswordButton: UIButton!
     
     public var isDismiss: ((String) -> ())?
+    public var forceLogin = false
     
     public override func viewDidLoad() {
         super.viewDidLoad()
@@ -116,7 +117,7 @@ public class ChangeDeviceViewController: UIViewController {
                         Nexilis.changeUser(f_pin: id)
                         UserDefaults.standard.setValue(id, forKey: "me")
                         UserDefaults.standard.set(password, forKey: "pwd")
-                        UserDefaults.standard.set(true, forKey: "is_change_profile")
+                        Utils.setProfile(value: true)
                         UserDefaults.standard.synchronize()
                         // pos registration
                         _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
@@ -126,7 +127,11 @@ public class ChangeDeviceViewController: UIViewController {
                             imageView.tintColor = .white
                             let banner = FloatingNotificationBanner(title: "Successfully changed device".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
                             banner.show()
-                            self.navigationController?.popViewController(animated: true)
+                            if !self.forceLogin {
+                                self.navigationController?.popViewController(animated: true)
+                            } else {
+                                self.navigationController?.dismiss(animated: true)
+                            }
                             self.isDismiss?(thumb)
                         })
                     }

+ 1 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeNamePassswordViewController.swift

@@ -145,7 +145,7 @@ public class ChangeNamePassswordViewController: UIViewController {
                                 _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["first_name": first , "last_name": last], _where: "f_pin = '\(idMe)'")
                             })
                             UserDefaults.standard.set(password, forKey: "pwd")
-                            UserDefaults.standard.set(true, forKey: "is_change_profile")
+                            Utils.setProfile(value: true)
                             UserDefaults.standard.synchronize()
         //                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
                             DispatchQueue.main.async {

+ 3 - 3
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/SettingTableViewController.swift

@@ -81,7 +81,7 @@ public class SettingTableViewController: UITableViewController {
     }
     
     func makeMenu(imageSignIn: String = "") {
-        let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+        let isChangeProfile = Utils.getSetProfile()
         Database.shared.database?.inTransaction({ fmdb, rollback in
             if !isChangeProfile {
                 Item.menus["Personal"] = [
@@ -266,7 +266,7 @@ public class SettingTableViewController: UITableViewController {
         tableView.deselectRow(at: indexPath, animated: false)
         let item = Item.menuFor(section: indexPath.section)[indexPath.row]
         if item.title == "User Profile Management".localized() {
-            let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
+            let isChangeProfile = Utils.getSetProfile()
             if isChangeProfile {
                 let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
                 controller.data = UserDefaults.standard.string(forKey: "me")!
@@ -349,7 +349,7 @@ public class SettingTableViewController: UITableViewController {
                             Nexilis.changeUser(f_pin: id)
                             UserDefaults.standard.setValue(id, forKey: "me")
                             UserDefaults.standard.set("", forKey: "pwd")
-                            UserDefaults.standard.set(false, forKey: "is_change_profile")
+                            Utils.setProfile(value: false)
                             UserDefaults.standard.synchronize()
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))