|
@@ -0,0 +1,724 @@
|
|
|
|
+//
|
|
|
|
+// SettingTableViewController.swift
|
|
|
|
+// Qmera
|
|
|
|
+//
|
|
|
|
+// Created by Yayan Dwi on 16/09/21.
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+import UIKit
|
|
|
|
+import NotificationBannerSwift
|
|
|
|
+import nuSDKService
|
|
|
|
+import NexilisLite
|
|
|
|
+
|
|
|
|
+public class FourthTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
|
|
|
|
+
|
|
|
|
+ var language: [[String: String]] = [["English": "en"],["Indonesia": "id"]]
|
|
|
|
+ var alert: UIAlertController?
|
|
|
|
+ var textFields = [UITextField]()
|
|
|
|
+
|
|
|
|
+ @IBOutlet weak var tableView: UITableView!
|
|
|
|
+ @IBOutlet weak var backgroundImage: UIImageView!
|
|
|
|
+
|
|
|
|
+ public override func viewDidLoad() {
|
|
|
|
+ super.viewDidLoad()
|
|
|
|
+
|
|
|
|
+ var isNCNil = navigationController == nil
|
|
|
|
+ print("isNCNil: \(isNCNil)")
|
|
|
|
+
|
|
|
|
+ tableView.delegate = self
|
|
|
|
+ tableView.dataSource = self
|
|
|
|
+
|
|
|
|
+ self.navigationController?.navigationBar.topItem?.title = "Settings".localized();
|
|
|
|
+ view.backgroundColor = .white
|
|
|
|
+
|
|
|
|
+ makeMenu()
|
|
|
|
+
|
|
|
|
+// navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapCancel))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func makeMenu(){
|
|
|
|
+ let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
|
|
|
|
+ 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() {
|
|
|
|
+ var groupId = ""
|
|
|
|
+ if let cursorGroup = Database.shared.getRecords(fmdb: fmdb, query: "SELECT group_id FROM GROUPZ where group_type = 1 AND official = 1"), cursorGroup.next() {
|
|
|
|
+ groupId = cursorGroup.string(forColumnIndex: 0) ?? ""
|
|
|
|
+ cursorGroup.close()
|
|
|
|
+ }
|
|
|
|
+ var position = ""
|
|
|
|
+ if let cursorIsAdmin = Database.shared.getRecords(fmdb: fmdb, query: "SELECT position FROM GROUPZ_MEMBER where group_id = '\(groupId)' AND f_pin = '\(idMe!)'"), cursorIsAdmin.next() {
|
|
|
|
+ position = cursorIsAdmin.string(forColumnIndex: 0) ?? ""
|
|
|
|
+ cursorIsAdmin.close()
|
|
|
|
+ }
|
|
|
|
+ if cursorUser.string(forColumnIndex: 0) == "23" && position == "1" {
|
|
|
|
+ Item.menus["Personal"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "person.fill"), title: "Personal Information".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Login to Nexilis Web".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
|
|
|
|
+ ]
|
|
|
|
+ } else if cursorUser.string(forColumnIndex: 0) == "23" || cursorUser.string(forColumnIndex: 0) == "24" {
|
|
|
|
+ Item.menus["Personal"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "person.fill"), title: "Personal Information".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Login to Nexilis Web".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
|
|
|
|
+ ]
|
|
|
|
+ } else {
|
|
|
|
+ Item.menus["Personal"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "person.fill"), title: "Personal Information".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Sign In Admin / Internal".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Login to Nexilis Web".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ let image = cursorUser.string(forColumnIndex: 1) ?? ""
|
|
|
|
+ if !image.isEmpty {
|
|
|
|
+ do {
|
|
|
|
+ let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
|
|
|
+ let file = documentDir.appendingPathComponent(image)
|
|
|
|
+ if FileManager().fileExists(atPath: file.path) {
|
|
|
|
+ let image = UIImage(contentsOfFile: file.path)
|
|
|
|
+ Item.menus["Personal"]?[0].icon = image?.circleMasked
|
|
|
|
+ } else {
|
|
|
|
+ Download().start(forKey: image) { (name, progress) in
|
|
|
|
+ guard progress == 100 else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let image = UIImage(contentsOfFile: file.path)
|
|
|
|
+ Item.menus["Personal"]?[0].icon = image?.circleMasked
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch {}
|
|
|
|
+ }
|
|
|
|
+ cursorUser.close()
|
|
|
|
+ }
|
|
|
|
+ if !isChangeProfile {
|
|
|
|
+ Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Change Device".localized()))
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ Item.menus["Call"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "message"), title: "Incoming Message(s)".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "phone"), title: "Incoming Call(s)".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "iphone.homebutton.radiowaves.left.and.right"), title: "Vibrate Mode".localized()),
|
|
|
|
+ ]
|
|
|
|
+ Item.menus["Etc"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "photo.on.rectangle.angled"), title: "Save to Gallery".localized()),
|
|
|
|
+ Item(icon: UIImage(systemName: "arrow.down.square"), title: "Auto Download".localized()),
|
|
|
|
+// Item(icon: UIImage(systemName: "mail"), title: "Email".localized()),
|
|
|
|
+ ]
|
|
|
|
+ Item.menus["Version"] = [
|
|
|
|
+ Item(icon: UIImage(systemName: "gear"), title: "Version".localized()),
|
|
|
|
+ ]
|
|
|
|
+ if isChangeProfile {
|
|
|
|
+ Item.menus["Version"]?.append(Item(icon: UIImage(systemName: "rectangle.portrait.and.arrow.right"), title: "Logout".localized()))
|
|
|
|
+ }
|
|
|
|
+ Item.menus["Powered"] = [
|
|
|
|
+ Item(icon: UIImage(named: "pb_powered_button"), title: "Powered by Nexilis".localized()),
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override public func viewWillAppear(_ animated: Bool) {
|
|
|
|
+ let randomInt = Int.random(in: 1..<2)
|
|
|
|
+ backgroundImage.image = UIImage(named: "pb_lbackground_\(randomInt)")
|
|
|
|
+ self.navigationController?.navigationBar.topItem?.title = "Settings".localized();
|
|
|
|
+ let cpaasMode = PrefsUtil.getCpaasMode()
|
|
|
|
+ let isBurger = cpaasMode == PrefsUtil.CPAAS_MODE_BURGER
|
|
|
|
+ navigationController?.setNavigationBarHidden(false, animated: false)
|
|
|
|
+ navigationController?.navigationBar.backgroundColor = .clear
|
|
|
|
+ navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
|
|
|
+ navigationController?.navigationBar.shadowImage = UIImage()
|
|
|
|
+ navigationController?.navigationBar.isTranslucent = true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// @objc func didTapCancel(sender: AnyObject) {
|
|
|
|
+// navigationController?.dismiss(animated: true, completion: nil)
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ // MARK: - Table view data source
|
|
|
|
+
|
|
|
|
+ public func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
+ return Item.sections.count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
+ return 1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
+ return Item.menuFor(section: section).count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
+ let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
|
|
|
|
+ cell.accessoryType = .none
|
|
|
|
+ cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude)
|
|
|
|
+ cell.indentationLevel = 0
|
|
|
|
+ var content = cell.defaultContentConfiguration()
|
|
|
|
+ content.textProperties.font = UIFont.systemFont(ofSize: 14)
|
|
|
|
+ content.secondaryTextProperties.font = UIFont.systemFont(ofSize: 14)
|
|
|
|
+ content.secondaryTextProperties.color = .gray
|
|
|
|
+ content.prefersSideBySideTextAndSecondaryText = true
|
|
|
|
+ let section = Item.sections[indexPath.section]
|
|
|
|
+ if let arr = Item.menus[section] {
|
|
|
|
+ let menu = arr[indexPath.row]
|
|
|
|
+ content.image = menu.icon
|
|
|
|
+ content.imageProperties.tintColor = .mainColor
|
|
|
|
+ content.imageProperties.maximumSize = CGSize(width: 24, height: 24)
|
|
|
|
+ content.text = menu.title
|
|
|
|
+ switch menu.title {
|
|
|
|
+ case "Personal Information".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Sign In Admin / Internal".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Login to Nexilis Web".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Change Device".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Change Admin / Internal Password".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Change Language".localized():
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ case "Version".localized():
|
|
|
|
+ content.secondaryText = UIApplication.appVersion
|
|
|
|
+ default:
|
|
|
|
+ content.secondaryText = nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cell.contentConfiguration = content
|
|
|
|
+ return cell
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
+ let item = Item.menuFor(section: indexPath.section)[indexPath.row]
|
|
|
|
+ if item.title == "Personal Information".localized() {
|
|
|
|
+ if(ViewController.checkIsChangePerson()){
|
|
|
|
+ let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
|
|
|
|
+ controller.data = UserDefaults.standard.string(forKey: "me")!
|
|
|
|
+ controller.flag = .me
|
|
|
|
+ controller.dismissImage = { image, imageName in
|
|
|
|
+ if !imageName.isEmpty {
|
|
|
|
+ Item.menus["Personal"]?[0].icon = image.circleMasked
|
|
|
|
+ } else {
|
|
|
|
+ Item.menus["Personal"]?[0].icon = UIImage(systemName: "person.fill")
|
|
|
|
+ }
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ navigationController?.show(controller, sender: nil)
|
|
|
|
+ }
|
|
|
|
+ } else if item.title == "Sign In Admin / Internal".localized() || item.title == "Change Admin / Internal Password".localized() {
|
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
|
+ if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT first_name, last_name FROM BUDDY where f_pin = '\(UserDefaults.standard.string(forKey: "me")!)'"), cursorData.next() {
|
|
|
|
+ if (cursorData.string(forColumnIndex: 0)! + " " + cursorData.string(forColumnIndex: 1)!).trimmingCharacters(in: .whitespaces) == "USR\(UserDefaults.standard.string(forKey: "me")!)" {
|
|
|
|
+ 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
|
|
|
|
+ let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
|
|
|
|
+ controller.data = UserDefaults.standard.string(forKey: "me")!
|
|
|
|
+ controller.flag = .me
|
|
|
|
+ self.navigationController?.show(controller, sender: nil)
|
|
|
|
+ }))
|
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+ cursorData.close()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
|
|
|
+ if(item.title.contains("Change")){
|
|
|
|
+ if let action = self.actionChangePassword(for: "admin", title: "Change Admin Password".localized()) {
|
|
|
|
+ alertController.addAction(action)
|
|
|
|
+ }
|
|
|
|
+ if let action = self.actionChangePassword(for: "internal", title: "Change Internal Password".localized()) {
|
|
|
|
+ alertController.addAction(action)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ if let action = self.actionLogin(for: "admin", title: "Login as Admin".localized()) {
|
|
|
|
+ alertController.addAction(action)
|
|
|
|
+ }
|
|
|
|
+ if let action = self.actionLogin(for: "internal", title: "Login as Internal Team".localized()) {
|
|
|
|
+ alertController.addAction(action)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ alertController.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
|
|
+ self.present(alertController, animated: true)
|
|
|
|
+ } else if item.title == "Change Language".localized() {
|
|
|
|
+ let vc = UIViewController()
|
|
|
|
+ vc.preferredContentSize = CGSize(width: UIScreen.main.bounds.width - 10, height: 150)
|
|
|
|
+ let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 150))
|
|
|
|
+ pickerView.dataSource = self
|
|
|
|
+ pickerView.delegate = self
|
|
|
|
+
|
|
|
|
+ let lang = UserDefaults.standard.string(forKey: "i18n_language")
|
|
|
|
+ var index = 0
|
|
|
|
+ if lang == "id" {
|
|
|
|
+ index = 1
|
|
|
|
+ }
|
|
|
|
+ pickerView.selectRow(index, inComponent: 0, animated: false)
|
|
|
|
+
|
|
|
|
+ vc.view.addSubview(pickerView)
|
|
|
|
+ pickerView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ pickerView.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true
|
|
|
|
+ pickerView.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true
|
|
|
|
+
|
|
|
|
+ let alert = UIAlertController(title: "Select Language".localized(), message: "", preferredStyle: .actionSheet)
|
|
|
|
+
|
|
|
|
+ alert.setValue(vc, forKey: "contentViewController")
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (UIAlertAction) in
|
|
|
|
+ }))
|
|
|
|
+
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Select", style: .default, handler: { (UIAlertAction) in
|
|
|
|
+ let selectedIndex = pickerView.selectedRow(inComponent: 0)
|
|
|
|
+ let lang = self.language[selectedIndex].values.first
|
|
|
|
+ UserDefaults.standard.set(lang, forKey: "i18n_language")
|
|
|
|
+ self.viewDidLoad()
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }))
|
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
|
+ } else if item.title == "Change Device".localized() {
|
|
|
|
+ let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
|
|
|
|
+ controller.isDismiss = { newThumb in
|
|
|
|
+ if Item.menus["Personal"]?[2].title == "Login to Nexilis Web".localized() {
|
|
|
|
+ Item.menus["Personal"]?.remove(at: 3)
|
|
|
|
+ } else {
|
|
|
|
+ Item.menus["Personal"]?.remove(at: 2)
|
|
|
|
+ }
|
|
|
|
+ if !newThumb.isEmpty {
|
|
|
|
+ do {
|
|
|
|
+ let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
|
|
|
+ let file = documentDir.appendingPathComponent(newThumb)
|
|
|
|
+ if FileManager().fileExists(atPath: file.path) {
|
|
|
|
+ let image = UIImage(contentsOfFile: file.path)
|
|
|
|
+ Item.menus["Personal"]?[0].icon = image?.circleMasked
|
|
|
|
+ } else {
|
|
|
|
+ Download().start(forKey: newThumb) { (name, progress) in
|
|
|
|
+ guard progress == 100 else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let image = UIImage(contentsOfFile: file.path)
|
|
|
|
+ Item.menus["Personal"]?[0].icon = image?.circleMasked
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch {}
|
|
|
|
+ }
|
|
|
|
+ Item.menus["Version"]?.append(Item(icon: UIImage(systemName: "rectangle.portrait.and.arrow.right"), title: "Logout".localized()))
|
|
|
|
+ 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 FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
|
|
|
|
+ var groupId = ""
|
|
|
|
+ if let cursorGroup = Database.shared.getRecords(fmdb: fmdb, query: "SELECT group_id FROM GROUPZ where group_type = 1 AND official = 1"), cursorGroup.next() {
|
|
|
|
+ groupId = cursorGroup.string(forColumnIndex: 0) ?? ""
|
|
|
|
+ cursorGroup.close()
|
|
|
|
+ }
|
|
|
|
+ var position = ""
|
|
|
|
+ if let cursorIsAdmin = Database.shared.getRecords(fmdb: fmdb, query: "SELECT position FROM GROUPZ_MEMBER where group_id = '\(groupId)' AND f_pin = '\(idMe!)'"), cursorIsAdmin.next() {
|
|
|
|
+ position = cursorIsAdmin.string(forColumnIndex: 0) ?? ""
|
|
|
|
+ cursorIsAdmin.close()
|
|
|
|
+ }
|
|
|
|
+ if cursorUser.string(forColumnIndex: 0) == "23" && position == "1" {
|
|
|
|
+ let itemCP = Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized())
|
|
|
|
+ Item.menus["Personal"]?[1] = itemCP
|
|
|
|
+ } else if cursorUser.string(forColumnIndex: 0) == "23" || cursorUser.string(forColumnIndex: 0) == "24" {
|
|
|
|
+ Item.menus["Personal"]?.remove(at: 1)
|
|
|
|
+ }
|
|
|
|
+ cursorUser.close()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ navigationController?.show(controller, sender: nil)
|
|
|
|
+ } else if item.title == "Logout".localized() {
|
|
|
|
+ let alert = UIAlertController(title: "Logout", message: "Are you sure want to logout?".localized(), preferredStyle: .alert)
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Yes".localized(), style: .destructive, handler: {(_) in
|
|
|
|
+ if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ self.deleteAllRecordDatabase()
|
|
|
|
+ let apiKey = UserDefaults.standard.string(forKey: "apiKey")!
|
|
|
|
+ var id = UIDevice.current.identifierForVendor?.uuidString ?? "UNK-DEVICE"
|
|
|
|
+ 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: "")
|
|
|
|
+ if(!id.isEmpty){
|
|
|
|
+ Nexilis.changeUser(f_pin: id)
|
|
|
|
+ UserDefaults.standard.setValue(id, forKey: "me")
|
|
|
|
+ UserDefaults.standard.set("", forKey: "pwd")
|
|
|
|
+ UserDefaults.standard.set(false, forKey: "is_change_profile")
|
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
|
+ // pos registration
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Successfully Logout".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: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ Item.menus["Personal"]?[0].icon = UIImage(systemName: "person.fill")
|
|
|
|
+ Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Change Device".localized()))
|
|
|
|
+ Item.menus["Version"]?.remove(at: 1)
|
|
|
|
+ if Item.menus["Personal"]?[1].title != "Sign In Admin / Internal".localized() {
|
|
|
|
+ if Item.menus["Personal"]?[1].title == "Change Admin / Internal Password".localized() {
|
|
|
|
+ Item.menus["Personal"]?[1] = Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Sign In Admin / Internal".localized())
|
|
|
|
+ } else {
|
|
|
|
+ Item.menus["Personal"]?.insert(Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Sign In Admin / Internal".localized()), at: 1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }))
|
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func actionLogin(for type: String, title: String) -> UIAlertAction? {
|
|
|
|
+ return UIAlertAction(title: title, style: .default) { _ in
|
|
|
|
+ self.alert = UIAlertController(title: "Login as Admin".localized(), message: nil, preferredStyle: .alert)
|
|
|
|
+ if type == "internal" {
|
|
|
|
+ self.alert = UIAlertController(title: "Login as Internal Team".localized(), message: nil, preferredStyle: .alert)
|
|
|
|
+ }
|
|
|
|
+ self.textFields.removeAll()
|
|
|
|
+ self.alert?.addTextField{ (texfield) in
|
|
|
|
+ texfield.placeholder = "Password"
|
|
|
|
+ texfield.isSecureTextEntry = true
|
|
|
|
+ texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
|
|
|
|
+ }
|
|
|
|
+ let submitAction = UIAlertAction(title: "Sign In".localized(), style: .default, handler: { (action) -> Void in
|
|
|
|
+ let textField = self.alert?.textFields![0]
|
|
|
|
+ if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if type == "admin" {
|
|
|
|
+ self.signInAdmin(password: textField!.text!, completion: { result in
|
|
|
|
+ if result {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Successfully login Admin".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: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ let itemCP = Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized())
|
|
|
|
+ Item.menus["Personal"]?[1] = itemCP
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ self.signInInternal(password: textField!.text!, completion: { result in
|
|
|
|
+ if result {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Successfully login Internal Team".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: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ Item.menus["Personal"]?.remove(at: 1)
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ submitAction.isEnabled = false
|
|
|
|
+ self.alert?.addAction(submitAction)
|
|
|
|
+ self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
|
|
+
|
|
|
|
+ self.present(self.alert!, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func actionChangePassword(for type: String, title: String) -> UIAlertAction? {
|
|
|
|
+ return UIAlertAction(title: title, style: .default) { _ in
|
|
|
|
+ self.alert = UIAlertController(title: "Change Admin Password".localized(), message: nil, preferredStyle: .alert)
|
|
|
|
+ if type == "internal" {
|
|
|
|
+ self.alert = UIAlertController(title: "Change Internal Password".localized(), message: nil, preferredStyle: .alert)
|
|
|
|
+ }
|
|
|
|
+ self.textFields.removeAll()
|
|
|
|
+ self.alert?.addTextField{ (texfield) in
|
|
|
|
+ texfield.placeholder = "Old Password"
|
|
|
|
+ texfield.isSecureTextEntry = true
|
|
|
|
+ texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
|
|
|
|
+ self.textFields.append(texfield)
|
|
|
|
+ }
|
|
|
|
+ self.alert?.addTextField{ (texfield) in
|
|
|
|
+ texfield.placeholder = "New Password"
|
|
|
|
+ texfield.isSecureTextEntry = true
|
|
|
|
+ texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
|
|
|
|
+ self.textFields.append(texfield)
|
|
|
|
+ }
|
|
|
|
+ let submitAction = UIAlertAction(title: "Change Password".localized(), style: .default, handler: { (action) -> Void in
|
|
|
|
+ let textFieldOld = self.alert?.textFields![0]
|
|
|
|
+ let textFieldNew = self.alert?.textFields![1]
|
|
|
|
+ if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if type == "admin" {
|
|
|
|
+ self.changePasswordAdmin(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
|
|
|
|
+ if result {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Admin password changed successfully".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: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ self.changePasswordInternal(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
|
|
|
|
+ if result {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Internal password changed successfully".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: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ submitAction.isEnabled = false
|
|
|
|
+ self.alert?.addAction(submitAction)
|
|
|
|
+ self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
|
|
+
|
|
|
|
+ self.present(self.alert!, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func alertTextFieldDidChange(_ sender: UITextField) {
|
|
|
|
+ if(!textFields.isEmpty){
|
|
|
|
+ print("text count 0: \(textFields[0].text!.count)")
|
|
|
|
+ print("text count 1: \(textFields[1].text!.count)")
|
|
|
|
+ alert?.actions[0].isEnabled = textFields[0].text!.count > 0 && textFields[1].text!.count > 0
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ alert?.actions[0].isEnabled = sender.text!.count > 0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+ let p_password = password
|
|
|
|
+ let md5Hex = Utils.getMD5(string: p_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ var result: Bool = false
|
|
|
|
+ if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
|
|
|
|
+ if response.isOk() {
|
|
|
|
+ result = true
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Username or password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Invalid password".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ completion(result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func signInInternal(password: String, completion: @escaping (Bool) -> ()) {
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+ let p_password = password
|
|
|
|
+ let md5Hex = Utils.getMD5(string: p_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ var result: Bool = false
|
|
|
|
+ if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiInternal(p_name: idMe!, p_password: md5Hex)) {
|
|
|
|
+ if response.isOk() {
|
|
|
|
+ result = true
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Username or password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Invalid password".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ completion(result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func changePasswordAdmin(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+ let p_password = oldPassword
|
|
|
|
+ let n_password = newPassword
|
|
|
|
+ let md5Hex = Utils.getMD5(string: p_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ let md5HexNew = Utils.getMD5(string: n_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ var result: Bool = false
|
|
|
|
+ if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordAdmin(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
|
|
|
|
+ if response.isOk() {
|
|
|
|
+ result = true
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Username or password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Invalid password".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ completion(result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func changePasswordInternal(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+ let p_password = oldPassword
|
|
|
|
+ let n_password = newPassword
|
|
|
|
+ let md5Hex = Utils.getMD5(string: p_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ let md5HexNew = Utils.getMD5(string: n_password).map { String(format: "%02hhx", $0) }.joined()
|
|
|
|
+ var result: Bool = false
|
|
|
|
+ if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordInternal(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
|
|
|
|
+ if response.isOk() {
|
|
|
|
+ result = true
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Username or password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Invalid password".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
|
|
|
|
+ imageView.tintColor = .white
|
|
|
|
+ let banner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
|
|
|
|
+ banner.show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ completion(result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - Item
|
|
|
|
+
|
|
|
|
+struct Item: Hashable {
|
|
|
|
+
|
|
|
|
+ static func == (lhs: Item, rhs: Item) -> Bool {
|
|
|
|
+ return lhs.title == rhs.title
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var icon: UIImage?
|
|
|
|
+ var title = ""
|
|
|
|
+
|
|
|
|
+ static var sections: [String] {
|
|
|
|
+ return ["Personal", "Call", "Etc", "Version", "Powered"]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static var menus: [String: [Item]] = [:]
|
|
|
|
+
|
|
|
|
+ static func menuFor(section: Int) -> [Item] {
|
|
|
|
+ let sec = sections[section]
|
|
|
|
+ if let arr = menus[sec] {
|
|
|
|
+ return arr
|
|
|
|
+ }
|
|
|
|
+ return []
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+extension FourthTabViewController: UIPickerViewDelegate, UIPickerViewDataSource {
|
|
|
|
+ public func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
|
|
|
+ return 1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
|
|
|
+ return language.count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
|
|
|
|
+ return 60
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
|
|
|
|
+ let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 30))
|
|
|
|
+ label.text = (language[row]).keys.first
|
|
|
|
+ label.sizeToFit()
|
|
|
|
+ return label
|
|
|
|
+ }
|
|
|
|
+}
|