- Added localisation to theme 1, also updated the English localisation for reversing the language - Added localisation to the sidebar. Also handled the live language change with the help of observers - Integrated GetUserData API at splash. - Added the login NAv. Now if user will logout he will be redirected to the login Screen. - Added Activity Indicator on the splash to handle the getuserdata. - Added Guest Login To home.
104 lines
2.8 KiB
Swift
104 lines
2.8 KiB
Swift
//
|
|
// AuthFunc.swift
|
|
// WOKA
|
|
//
|
|
// Created by Bilal on 26/04/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import AVFoundation
|
|
import UIKit
|
|
|
|
class AuthFunc{
|
|
|
|
/**
|
|
This is not for external use!
|
|
This should only be used for login, registration, Auth Process process & userData Extraction.
|
|
*/
|
|
|
|
var player: AVQueuePlayer?
|
|
var playerLooper: AVPlayerLooper?
|
|
var userType = UserType.adult
|
|
var userData : UserDataDM.ResultData?
|
|
|
|
var languageSelected = LocalizedEnum.english {
|
|
didSet {
|
|
NotificationCenter.default.post(name: .languageDidChange, object: nil)
|
|
}
|
|
}
|
|
|
|
var authID = String()
|
|
var authPass = String()
|
|
|
|
var selectedTheme = ThemeSelect.theme1
|
|
|
|
//This is temporary variable. Make it emtpy when the registration is finished.
|
|
var regData = UserRegPostModel()
|
|
|
|
// Singleton instance of AuthFunc
|
|
static let shareInstance = AuthFunc()
|
|
|
|
//Handling Time Changes on Home
|
|
var timePeriods = [TimePeriod]()
|
|
|
|
// Returns the device's UUID
|
|
func getDeviceUUID() -> String{
|
|
/*
|
|
UIDevice.current.name // e.g. "My iPhone"
|
|
UIDevice.current.model // e.g. @"iPhone", @"iPod touch"
|
|
UIDevice.current.localizedModel // localized version of model
|
|
UIDevice.current.systemName // e.g. @"iOS"
|
|
UIDevice.current.systemVersion // e.g. @"15.5"
|
|
*/
|
|
return UIDevice.current.identifierForVendor!.uuidString
|
|
}
|
|
|
|
// Sets authentication ID and password from the app's info dictionary
|
|
func setAuthIDPass(){
|
|
if let id = Bundle.main.infoDictionary?["API_KEY_ID"] as? String{
|
|
authID = id
|
|
}
|
|
|
|
if let pass = Bundle.main.infoDictionary?["API_KEY_PASS"] as? String{
|
|
authPass = pass
|
|
}
|
|
}
|
|
|
|
func checkLogin() -> Bool{
|
|
let isLoginned = UserDefaults.standard.bool(forKey: K.UserDefaultsStruct.isUserLogined)
|
|
return isLoginned
|
|
}
|
|
|
|
/*
|
|
This func will return the access token saved at the time of login
|
|
*/
|
|
func getAccessToken() -> String{
|
|
let accessToken = UserDefaults.standard.string(forKey: K.UserDefaultsStruct.userAccessToken)
|
|
return accessToken ?? ""
|
|
}
|
|
|
|
/*
|
|
This func will remove the selected userdefaults while logout
|
|
*/
|
|
func logout(){
|
|
//Reset Theme to defaults
|
|
UserDefaults.standard.setValue(nil, forKey: K.UserDefaultsStruct.themeDefault)
|
|
UserDefaults.standard.setValue(nil, forKey: K.UserDefaultsStruct.isUserLogined)
|
|
userData = nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Language Enum
|
|
|
|
enum LocalizedEnum : String , CaseIterable{
|
|
case hindi = "hi"
|
|
case english = "en"
|
|
}
|
|
|
|
// MARK: - Enum representing different user types
|
|
|
|
enum UserType {
|
|
case adult
|
|
case kid
|
|
}
|