SignUpSignIn.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. //
  2. // SignUpSignIn.swift
  3. // NexilisLite
  4. //
  5. // Created by Akhmad Al Qindi Irsyam on 17/01/23.
  6. //
  7. import UIKit
  8. import NotificationBannerSwift
  9. import nuSDKService
  10. public class SignUpSignIn: UIViewController {
  11. @IBOutlet weak var descSignUpSignIn: UILabel!
  12. @IBOutlet weak var usernameField: UITextField!
  13. @IBOutlet weak var passwordField: PasswordTextField!
  14. @IBOutlet weak var showPasswordButton: UIButton!
  15. @IBOutlet weak var descDisclaimer: UILabel!
  16. public var isDismiss: ((String) -> ())?
  17. public var forceLogin = false
  18. public var fromChangeNamePass = false
  19. public override func viewDidLoad() {
  20. super.viewDidLoad()
  21. // self.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
  22. let attributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
  23. let navBarAppearance = UINavigationBarAppearance()
  24. navBarAppearance.configureWithOpaqueBackground()
  25. navBarAppearance.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : UIColor.mainColor
  26. navBarAppearance.titleTextAttributes = attributes
  27. navigationController?.navigationBar.standardAppearance = navBarAppearance
  28. navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
  29. navigationController?.navigationBar.tintColor = .white
  30. self.title = "Sign-Up/Sign-In".localized()
  31. descSignUpSignIn.text = "Please enter your nickname and your password".localized()
  32. descDisclaimer.text = "Disclaimer : Signing up with a nickname provides full privacy since".localized() + " \(Bundle.main.infoDictionary?["CFBundleName"] as! String) " + "does not know your identity, which is usually linked to your email account or mobile number. However, if you use a nickname, we will not be able to reset your password if you lose or forget it, so please keep your password secure.".localized()
  33. descDisclaimer.font = UIFont.italicSystemFont(ofSize: 14)
  34. navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Submit".localized(), style: .plain, target: self, action: #selector(didTapSubmit(sender:)))
  35. if forceLogin {
  36. navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(didTapCancel(sender:)))
  37. }
  38. passwordField.addPadding(.right(40))
  39. passwordField.isSecureTextEntry = true
  40. showPasswordButton.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  41. usernameField.placeholder = "Your Nickname".localized()
  42. passwordField.placeholder = "Password".localized()
  43. usernameField.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .mainColor
  44. passwordField.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .mainColor
  45. usernameField.addTarget(self, action: #selector(checkUsername(_:)), for: .editingChanged)
  46. showPasswordButton.addTarget(self, action: #selector(showPassword), for: .touchUpInside)
  47. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
  48. tapGesture.cancelsTouchesInView = false
  49. view.addGestureRecognizer(tapGesture)
  50. }
  51. @objc func didTapCancel(sender: Any) {
  52. self.navigationController?.dismiss(animated: true)
  53. }
  54. @objc func checkUsername(_ textField: UITextField) {
  55. let text : String! = usernameField.text
  56. if isValidEmail(text) {
  57. passwordField.isHidden = true
  58. showPasswordButton.isHidden = true
  59. } else if passwordField.isHidden {
  60. passwordField.isHidden = false
  61. showPasswordButton.isHidden = false
  62. }
  63. }
  64. func isValidEmail(_ email: String) -> Bool {
  65. let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
  66. let emailPred = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
  67. return emailPred.evaluate(with: email)
  68. }
  69. @objc func dismissKeyboard() {
  70. //Causes the view (or one of its embedded text fields) to resign the first responder status.
  71. view.endEditing(true)
  72. }
  73. @objc func showPassword() {
  74. if passwordField.isSecureTextEntry {
  75. passwordField.isSecureTextEntry = false
  76. showPasswordButton.setImage(UIImage(systemName: "eye.fill"), for: .normal)
  77. } else {
  78. passwordField.isSecureTextEntry = true
  79. showPasswordButton.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  80. }
  81. }
  82. func checkEmail(email: String) {
  83. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  84. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  85. imageView.tintColor = .white
  86. 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: .center)
  87. banner.show()
  88. return
  89. }
  90. Nexilis.showLoader()
  91. DispatchQueue.global().async {
  92. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSendOTPLogin(p_email: email), timeout: 30 * 1000) {
  93. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") != "00" {
  94. DispatchQueue.main.async {
  95. Nexilis.hideLoader(completion: {
  96. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  97. imageView.tintColor = .white
  98. let banner = FloatingNotificationBanner(title: "Unregistered email account".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: .center)
  99. banner.show()
  100. })
  101. }
  102. } else {
  103. DispatchQueue.main.async {
  104. Nexilis.hideLoader(completion: {
  105. self.showPageOTP(email: email)
  106. })
  107. }
  108. }
  109. } else {
  110. DispatchQueue.main.async {
  111. Nexilis.hideLoader(completion: {
  112. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  113. imageView.tintColor = .white
  114. 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: .center)
  115. banner.show()
  116. })
  117. }
  118. }
  119. }
  120. }
  121. func showPageOTP(email: String, errCode:String = "") {
  122. let showOTPVC = VerifyEmail()
  123. showOTPVC.email = email
  124. showOTPVC.showWrongOTP = errCode
  125. showOTPVC.isDismiss = { code in
  126. Nexilis.showLoader()
  127. DispatchQueue.global().async {
  128. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSendVerifyChangeDevice(p_email: email, p_vercode: code), timeout: 30 * 1000) {
  129. if !response.isOk() {
  130. DispatchQueue.main.async {
  131. Nexilis.hideLoader(completion: {
  132. self.showPageOTP(email: email, errCode: response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99"))
  133. })
  134. }
  135. } else {
  136. self.deleteAllRecordDatabase()
  137. let id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
  138. let thumb = response.getBody(key: CoreMessage_TMessageKey.THUMB_ID, default_value: "")
  139. if(!id.isEmpty) {
  140. // Nexilis.changeUser(f_pin: id)
  141. Utils.setProfile(value: true)
  142. // pos registration
  143. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
  144. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  145. Nexilis.hideLoader(completion: {
  146. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  147. imageView.tintColor = .white
  148. let banner = FloatingNotificationBanner(title: "Successfully Sign-In".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)
  149. banner.show()
  150. if Nexilis.showFB {
  151. Nexilis.floatingButton.removeFromSuperview()
  152. Nexilis.floatingButton = FloatingButton()
  153. Nexilis.addFB()
  154. }
  155. if self.fromChangeNamePass{
  156. var vc = self.navigationController?.presentingViewController
  157. while vc?.presentingViewController != nil {
  158. vc = vc?.presentingViewController
  159. }
  160. vc?.dismiss(animated: true, completion: nil)
  161. }
  162. else if !self.forceLogin {
  163. self.navigationController?.popViewController(animated: true)
  164. } else {
  165. self.navigationController?.dismiss(animated: true)
  166. }
  167. self.isDismiss?(thumb)
  168. })
  169. })
  170. }
  171. }
  172. } else {
  173. DispatchQueue.main.async {
  174. Nexilis.hideLoader(completion: {
  175. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  176. imageView.tintColor = .white
  177. 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: .center)
  178. banner.show()
  179. })
  180. }
  181. }
  182. }
  183. }
  184. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
  185. self.navigationController?.present(showOTPVC, animated: true, completion: nil)
  186. })
  187. }
  188. @objc func didTapSubmit(sender: Any) {
  189. guard let name = usernameField.text, !name.isEmpty else {
  190. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  191. imageView.tintColor = .white
  192. let banner = FloatingNotificationBanner(title: "Username can't be empty".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: .center)
  193. banner.show()
  194. return
  195. }
  196. let a = name.split(separator: " ", maxSplits: 1)
  197. let first = String(a[0])
  198. let last = a.count == 2 ? String(a[1]) : ""
  199. if first.count > 24 {
  200. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  201. imageView.tintColor = .white
  202. let banner = FloatingNotificationBanner(title: "First name is too long".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: .center)
  203. banner.show()
  204. return
  205. }
  206. if last.count > 24 {
  207. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  208. imageView.tintColor = .white
  209. let banner = FloatingNotificationBanner(title: "Last name is too long".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: .center)
  210. banner.show()
  211. return
  212. }
  213. let idMe = User.getMyPin()!
  214. if isValidEmail(name) {
  215. checkEmail(email: name)
  216. return
  217. }
  218. if !name.matches("^[a-zA-Z0-9 ]*$") {
  219. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  220. imageView.tintColor = .white
  221. let banner = FloatingNotificationBanner(title: "Contains prohibited characters. Only alphabetic characters are allowed.".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: .center)
  222. banner.show()
  223. return
  224. }
  225. guard let password = passwordField.text, !password.isEmpty else {
  226. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  227. imageView.tintColor = .white
  228. let banner = FloatingNotificationBanner(title: "Password can't be empty".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: .center)
  229. banner.show()
  230. return
  231. }
  232. if password.count < 6 {
  233. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  234. imageView.tintColor = .white
  235. let banner = FloatingNotificationBanner(title: "Password min 6 character".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: .center)
  236. banner.show()
  237. return
  238. }
  239. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  240. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  241. imageView.tintColor = .white
  242. 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: .center)
  243. banner.show()
  244. return
  245. }
  246. if Database.shared.openDatabase() == 0 {
  247. APIS.showRestartApp()
  248. return
  249. }
  250. Nexilis.showLoader()
  251. DispatchQueue.global().async {
  252. let md5Hex = password
  253. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpSignInAPI(p_name: name, p_password: md5Hex), timeout: 30 * 1000) {
  254. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  255. DispatchQueue.main.async {
  256. Nexilis.hideLoader(completion: {
  257. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  258. imageView.tintColor = .white
  259. let banner = FloatingNotificationBanner(title: "Invalid user / Username and 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: .center)
  260. banner.show()
  261. })
  262. }
  263. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  264. DispatchQueue.main.async {
  265. Nexilis.hideLoader(completion: {
  266. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  267. imageView.tintColor = .white
  268. let banner = FloatingNotificationBanner(title: "Failed, unknown user".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: .center)
  269. banner.show()
  270. })
  271. }
  272. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "4u" {
  273. DispatchQueue.main.async {
  274. Nexilis.hideLoader(completion: {
  275. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  276. imageView.tintColor = .white
  277. let banner = FloatingNotificationBanner(title: "Failed, blocked user".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: .center)
  278. banner.show()
  279. })
  280. }
  281. } else if !response.isOk() {
  282. DispatchQueue.main.async {
  283. Nexilis.hideLoader(completion: {
  284. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  285. imageView.tintColor = .white
  286. let banner = FloatingNotificationBanner(title: "Failed".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: .center)
  287. banner.show()
  288. })
  289. }
  290. } else {
  291. let sign = response.getBody(key: CoreMessage_TMessageKey.SIGN, default_value: "")
  292. if sign == "1" {
  293. let id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
  294. let f_pin = response.getBody(key: CoreMessage_TMessageKey.F_PIN_REAL, default_value: "")
  295. let thumb = response.getBody(key: CoreMessage_TMessageKey.THUMB_ID, default_value: "")
  296. let device_id = response.getBody(key: CoreMessage_TMessageKey.IMEI, default_value: id)
  297. let last_sign = response.getBody(key: CoreMessage_TMessageKey.LAST_SIGN, default_value: "0")
  298. //print("last sign: \(last_sign)")
  299. if last_sign != "0" {
  300. Utils.setLoginMultipleFPin(value: f_pin)
  301. DispatchQueue.main.async {
  302. let imageView = UIImageView(image: UIImage(systemName: "info.circle"))
  303. imageView.tintColor = .white
  304. let banner = FloatingNotificationBanner(title: "Multiple Login Detected...".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .info, colors: nil, iconPosition: .center)
  305. banner.show()
  306. }
  307. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  308. Nexilis.hideLoader(completion: {
  309. if Nexilis.showFB {
  310. Nexilis.floatingButton.removeFromSuperview()
  311. Nexilis.floatingButton = FloatingButton()
  312. Nexilis.addFB()
  313. }
  314. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "onRefreshWebView"), object: nil, userInfo: nil)
  315. if self.fromChangeNamePass{
  316. var vc = self.navigationController?.presentingViewController
  317. while vc?.presentingViewController != nil {
  318. vc = vc?.presentingViewController
  319. }
  320. vc?.dismiss(animated: true, completion: nil)
  321. }
  322. else if !self.forceLogin {
  323. self.navigationController?.popViewController(animated: true)
  324. } else {
  325. self.navigationController?.dismiss(animated: true)
  326. }
  327. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
  328. let dialog = DialogUnableAccess()
  329. dialog.modalTransitionStyle = .crossDissolve
  330. dialog.modalPresentationStyle = .overCurrentContext
  331. UIApplication.shared.visibleViewController?.present(dialog, animated: true)
  332. })
  333. })
  334. })
  335. return
  336. }
  337. self.deleteAllRecordDatabase()
  338. if(!id.isEmpty) {
  339. // Nexilis.changeUser(f_pin: device_id)
  340. SecureUserDefaults.shared.set(device_id, forKey: "device_id")
  341. Utils.setProfile(value: true)
  342. // pos registration
  343. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
  344. DispatchQueue.global().asyncAfter(deadline: .now() + 2, execute: {
  345. Nexilis.getWhitelistFileExt()
  346. })
  347. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  348. Nexilis.hideLoader(completion: {
  349. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  350. imageView.tintColor = .white
  351. let banner = FloatingNotificationBanner(title: "Successfully Sign-In".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)
  352. banner.show()
  353. if Nexilis.showFB {
  354. Nexilis.floatingButton.removeFromSuperview()
  355. Nexilis.floatingButton = FloatingButton()
  356. Nexilis.addFB()
  357. }
  358. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "onRefreshWebView"), object: nil, userInfo: nil)
  359. if self.fromChangeNamePass{
  360. var vc = self.navigationController?.presentingViewController
  361. while vc?.presentingViewController != nil {
  362. vc = vc?.presentingViewController
  363. }
  364. vc?.dismiss(animated: true, completion: nil)
  365. }
  366. else if !self.forceLogin {
  367. self.navigationController?.popViewController(animated: true)
  368. } else {
  369. self.navigationController?.dismiss(animated: true)
  370. }
  371. self.isDismiss?(thumb)
  372. })
  373. })
  374. }
  375. } else {
  376. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  377. do {
  378. if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT * FROM BUDDY where f_pin = '\(idMe)' ") {
  379. if !cursorData.next() {
  380. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: idMe))
  381. } else {
  382. _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["first_name": first , "last_name": last], _where: "f_pin = '\(idMe)'")
  383. }
  384. cursorData.close()
  385. }
  386. } catch {
  387. rollback.pointee = true
  388. print("Access database error: \(error.localizedDescription)")
  389. }
  390. })
  391. Utils.setProfile(value: true)
  392. Nexilis.getWhitelistFileExt()
  393. // NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
  394. DispatchQueue.main.async {
  395. Nexilis.hideLoader(completion: {
  396. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  397. imageView.tintColor = .white
  398. let banner = FloatingNotificationBanner(title: "Successfully Sign-Up".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)
  399. banner.show()
  400. if self.fromChangeNamePass{
  401. var vc = self.navigationController?.presentingViewController
  402. while vc?.presentingViewController != nil {
  403. vc = vc?.presentingViewController
  404. }
  405. vc?.dismiss(animated: true, completion: nil)
  406. }
  407. else if !self.forceLogin {
  408. self.navigationController?.popViewController(animated: true)
  409. } else {
  410. self.navigationController?.dismiss(animated: true)
  411. }
  412. })
  413. }
  414. }
  415. }
  416. } else {
  417. DispatchQueue.main.async {
  418. Nexilis.hideLoader(completion: {
  419. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  420. imageView.tintColor = .white
  421. 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: .center)
  422. banner.show()
  423. })
  424. }
  425. }
  426. }
  427. }
  428. }