diff --git a/MobileiaAuthenticationCore.podspec b/MobileiaAuthenticationCore.podspec index 671a5ba..60cc7d9 100644 --- a/MobileiaAuthenticationCore.podspec +++ b/MobileiaAuthenticationCore.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "MobileiaAuthenticationCore" - s.version = "0.0.1" + s.version = "0.0.2" s.summary = "Libreria Authentication Core para MobileIA" # This description is used to generate tags and improve search results. @@ -81,7 +81,7 @@ Esta la base para la creacion de servicios de autenticacion y librerias que son # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/MobileIA/mia-authentication-ios.git", :tag => "0.0.1" } + s.source = { :git => "https://github.com/MobileIA/mia-authentication-ios.git", :tag => "0.0.2" } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # diff --git a/MobileiaAuthenticationCore/Entity/MIAUser.swift b/MobileiaAuthenticationCore/Entity/MIAUser.swift index 85d469c..b4f38d1 100644 --- a/MobileiaAuthenticationCore/Entity/MIAUser.swift +++ b/MobileiaAuthenticationCore/Entity/MIAUser.swift @@ -41,8 +41,16 @@ open class MIAUser : Object, Decodable { open required convenience init(from decoder: Decoder) throws { self.init(); let container = try decoder.container(keyedBy: MIAUserEnum.self); - id = try container.decode(Int.self, forKey: .id) - app_id = try container.decode(Int.self, forKey: .app_id) + do{ + id = try container.decode(Int.self, forKey: .id) + }catch{ + id = Int(try container.decode(String.self, forKey: .id))!; + } + do{ + app_id = try container.decode(Int.self, forKey: .app_id) + }catch{ + app_id = Int(try container.decode(String.self, forKey: .app_id))!; + } email = try container.decode(String.self, forKey: .email) firstname = try container.decode(String.self, forKey: .firstname) lastname = try container.decode(String.self, forKey: .lastname) diff --git a/MobileiaAuthenticationCore/Realm/MIAAuthRealm.swift b/MobileiaAuthenticationCore/Realm/MIAAuthRealm.swift index 9507149..ffa438a 100644 --- a/MobileiaAuthenticationCore/Realm/MIAAuthRealm.swift +++ b/MobileiaAuthenticationCore/Realm/MIAAuthRealm.swift @@ -29,6 +29,12 @@ open class MIAAuthRealm : MIABaseRealm { return users.first; } + open func deleteAllUsers(){ + let realm = getRealm(); + let users = realm.objects(MIAUser.self); + realm.delete(users); + } + open override func getNameFile() -> String { return "mobileia_authentication_" + String(Mobileia.getInstance().appId); } diff --git a/MobileiaAuthenticationCore/Rest/MIAAuthRest.swift b/MobileiaAuthenticationCore/Rest/MIAAuthRest.swift index f4a8e49..5be3a3e 100644 --- a/MobileiaAuthenticationCore/Rest/MIAAuthRest.swift +++ b/MobileiaAuthenticationCore/Rest/MIAAuthRest.swift @@ -19,13 +19,25 @@ open class MIAAuthRest : MIABaseRest { execute("api/oauth", method: .post, parameters: parameters, callback: callback, callbackError: callbackError); } - open func register(parameters : Parameters, callback: @escaping (_ object: Int) -> Void, callbackError: @escaping (_ error: MIAErrorRest) -> Void) -> Void{ + open func register(parameters : Parameters, callback: @escaping (_ object: MIAUser) -> Void, callbackError: @escaping (_ error: MIAErrorRest) -> Void) -> Void{ // Procesamos los parametros let parameters = processParameters(parameters: parameters); // Ejecutamos llamada execute("api/register", method: .post, parameters: parameters, callback: callback, callbackError: callbackError); } + open func update(accessToken : String, user: MIAUser, callback: @escaping (_ object: MIAUser) -> Void, callbackError: @escaping (_ error: MIAErrorRest) -> Void) -> Void{ + // Procesamos los parametros + var parameters = processParameters(parameters: [:]); + parameters["access_token"] = accessToken; + parameters["firstname"] = user.firstname; + parameters["lastname"] = user.lastname; + parameters["photo"] = user.photo; + parameters["phone"] = user.phone; + // Ejecutamos llamada + execute("api/update", method: .post, parameters: parameters, callback: callback, callbackError: callbackError); + } + open func me(accessToken : String, callback: @escaping (_ object: MIAUser) -> Void, callbackError: @escaping (_ error: MIAErrorRest) -> Void) -> Void{ // Procesamos los parametros var parameters = processParameters(parameters: [:]); @@ -54,6 +66,6 @@ open class MIAAuthRest : MIABaseRest { } open override func getBaseUrl() -> String { - return "http://authentication.mobileia.com/"; + return "https://authentication.mobileia.com/"; } } diff --git a/MobileiaAuthenticationCore/Service/MIAAuthBaseService.swift b/MobileiaAuthenticationCore/Service/MIAAuthBaseService.swift index 438c5a4..befdd89 100644 --- a/MobileiaAuthenticationCore/Service/MIAAuthBaseService.swift +++ b/MobileiaAuthenticationCore/Service/MIAAuthBaseService.swift @@ -18,7 +18,7 @@ open class MIAAuthBaseService : NSObject { open var callbackAccessTokenSuccess : ((_ object: MIAAccessToken) -> Void)?; open var callbackAccessTokenError : ((_ error: MIAErrorRest) -> Void)?; - open var callbackNewAccountSuccess : ((_ object: Int) -> Void)?; + open var callbackNewAccountSuccess : ((_ object: MIAUser) -> Void)?; open required override init() { super.init();