- ADD OAuth2 Manager

This commit is contained in:
giuseppenuc committed 2016-02-05 00:56:20 +01:00
1 parent 515d75c316
commit 31a1afdc98
65 files changed
+4110 -2732

No files matched your search

-60
View File
@@ -1,60 +0,0 @@
//
// PNAccessToken.h
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import "PNObject.h"
@interface PNAccessToken : PNObject
typedef NS_ENUM(NSInteger, TokenType) {
TokenTypeBasic = 1,
TokenTypeBearer = 2
};
/**
* gets singleton object of current user session.
*
* @return singleton
*/
+ (instancetype _Nonnull) currentAccessToken;
/**
* gets singleton object of current user session.
*
* @return singleton
*/
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON;
///--------------------------------------
#pragma mark - PNAccessToken Properties
///--------------------------------------
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString *accessToken;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSDate *expirationDate;
@property (nonatomic, strong, nullable) NSNumber *expiresIn;
/**
* <#Description#>
*/
@property (nonatomic) TokenType tokenType;
@property (nonatomic, strong, nullable) NSString *tokenTypeString;
@property (nonatomic, strong, nullable) NSString *scope;
@property (nonatomic, strong, nullable) NSString *refreshToken;
@end
-127
View File
@@ -1,127 +0,0 @@
//
// PNAccessToken.m
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import "PNAccessToken.h"
#import <NSDate_Utils/NSDate+NSDate_Util.h>
@interface PNAccessToken() <PNObjectSubclassing>
@end
@implementation PNAccessToken
static PNAccessToken *SINGLETON = nil;
static bool isFirstAccess = YES;
#pragma mark - Public Method
+ (instancetype) currentAccessToken {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:nil];
});
return SINGLETON;
}
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:JSON];
});
return SINGLETON;
}
- (instancetype) initForCurrentAccessTokenWithJSON:(NSDictionary *)JSON {
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedAccessToken;
if (JSON) {
savedAccessToken = JSON;
}
else {
savedAccessToken = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
}
if (savedAccessToken) {
self = [super initWithJSON:savedAccessToken];
}
else {
self = [super init];
}
if (self) {
if (_tokenTypeString) {
((void (^)())@{
@"beaer" : ^{
_tokenType = TokenTypeBearer;
},
@"basic" : ^{
_tokenType = TokenTypeBasic;
}
}[_tokenTypeString] ?: ^{
})();
}
if (_expiresIn) {
NSLog(@"%ld",[_expiresIn integerValue]);
NSLog(@"%@",[NSDate date]);
NSLog(@"%@",[[NSDate date] dateByAddingMinutes:[_expiresIn integerValue]]);
NSLog(@"%@",[[NSDate date] dateByAddingMinutes:10000]);
_expirationDate = [[NSDate date] dateByAddingMinutes:[_expiresIn integerValue]];
}
}
return self;
}
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"accessToken":@"access_token",
@"expiresIn":@"expires_in",
@"tokenTypeString":@"token_type",
@"tokenType":@"scope",
@"refreshToken":@"refresh_token",
};
return mapping;
}
- (instancetype) initWithJSON:(NSDictionary *)JSON {
return [[self class] currentAccessTokenWithJSON:JSON];
}
+ (NSString *)objectClassName {
return @"AccessToken";
}
+ (BOOL) singleInstance {
return YES;
}
#pragma mark -
@end
+4
View File
@@ -14,6 +14,10 @@
return @"Address";
}
+ (NSString *)objectEndPoint {
return @"Address";
}
+ (NSDictionary *) objcetMapping {
NSDictionary *mapping = @{@"country":@"country",
@"province":@"province",
+59 -55
View File
@@ -26,25 +26,29 @@ static bool isFirstAccess = YES;
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"deviceType":@"deviceType",
@"deviceModel":@"deviceModel",
@"deviceName":@"deviceName",
@"osVersion":@"osVersion",
@"deviceToken":@"deviceToken",
@"badge":@"badge",
@"localeIdentifier":@"localeIdentifier",
};
return mapping;
NSDictionary *mapping = @{
@"deviceType":@"deviceType",
@"deviceModel":@"deviceModel",
@"deviceName":@"deviceName",
@"osVersion":@"osVersion",
@"deviceToken":@"deviceToken",
@"badge":@"badge",
@"localeIdentifier":@"localeIdentifier",
};
return mapping;
}
+ (NSString *)objectClassName {
return @"AccessToken";
return @"Installation";
}
+ (NSString *)objectEndPoint {
return @"Installation";
}
+ (BOOL) singleInstance {
return YES;
return YES;
}
#pragma mark -
@@ -53,26 +57,26 @@ static bool isFirstAccess = YES;
+ (instancetype) currentInstallation {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
}
- (void)setDeviceTokenFromData:(NSData *)deviceTokenData {
_deviceTokenData = deviceTokenData;
NSString *ptoken = [[[[deviceTokenData description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
_deviceToken = ptoken;
_deviceTokenData = deviceTokenData;
NSString *ptoken = [[[[deviceTokenData description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
_deviceToken = ptoken;
}
#pragma mark -
@@ -81,31 +85,31 @@ static bool isFirstAccess = YES;
- (id) init
{
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedInstallation = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedInstallation) {
self = [super initWithJSON:savedInstallation];
}
else {
self = [super init];
}
if (self) {
_deviceType = @"iOS";
_deviceModel = [[UIDevice currentDevice] model];
_osVersion = [[UIDevice currentDevice] systemVersion];
_deviceName = [[UIDevice currentDevice] name];
}
return self;
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedInstallation = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedInstallation) {
self = [super initWithJSON:savedInstallation];
}
else {
self = [super init];
}
if (self) {
_deviceType = @"iOS";
_deviceModel = [[UIDevice currentDevice] model];
_osVersion = [[UIDevice currentDevice] systemVersion];
_deviceName = [[UIDevice currentDevice] name];
}
return self;
}
#pragma mark -
+3
View File
@@ -14,6 +14,9 @@
return @"Location";
}
+(NSString *)objectEndPoint {
return @"Location";
}
+ (NSDictionary *) objcetMapping {
NSDictionary *mapping = @{@"lat":@"lat",
-1
View File
@@ -7,7 +7,6 @@
//
#import "PNObject.h"
#import "PNAccessToken.h"
@interface PNUser : PNObject
+75 -76
View File
@@ -27,119 +27,118 @@ static bool isFirstAccess = YES;
#pragma mark - Public Method
+ (instancetype) currentUser {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentUser];
});
return SINGLETON;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentUser];
});
return SINGLETON;
}
#pragma mark - Life Cycle
- (instancetype)copy
{
return [[PNUser alloc] init];
return [[PNUser alloc] init];
}
- (instancetype)mutableCopy
{
return [[PNUser alloc] init];
return [[PNUser alloc] init];
}
- (instancetype) initForCurrentUser
{
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedUser) {
self = [super initWithJSON:savedUser];
}
else {
self = [super init];
}
if (self) {
}
return self;
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedUser) {
self = [super initWithJSON:savedUser];
}
else {
self = [super init];
}
if (self) {
}
return self;
}
- (void) setEmail:(NSString *)email {
if ([email isValidEmail]) {
_email = email;
}
else {
NSLogDebug(@"insertedEmail is not valid.");
}
if ([email isValidEmail]) {
_email = email;
}
else {
NSLogDebug(@"insertedEmail is not valid.");
}
}
- (void) setPassword:(NSString *)password {
if ([self isValidPassword:password]) {
_password = password;
}
else {
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
}
if ([self isValidPassword:password]) {
_password = password;
}
else {
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
}
}
- (BOOL) isValidPassword:(NSString* _Nonnull) password {
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
return YES;
}
return NO;
}
- (NSString *) password {
return @"password is not readble";
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
return YES;
}
return NO;
}
- (void)logout {
[self autoRemoveLocally];
[self resetObject];
[self autoRemoveLocally];
[self resetObject];
}
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"userId":@"id",
@"firstName":@"firstName",
@"lastName":@"lastName",
@"profileImage":@"profileImage",
@"sex":@"sex",
@"birthDate":@"birthDate",
@"phone":@"phone",
@"password":@"password",
@"hasAcceptedPrivacy":@"hasAcceptedPrivacy",
@"hasAcceptedNewsletter":@"hasAcceptedNewsletter",
@"hasVerifiedEmail":@"hasVerifiedEmail",
@"emailVerifiedDate":@"emailVerifiedDate",
@"email":@"email",
@"username":@"username",
@"publicProfile":@"public_profile",
@"loginCount":@"login_count",
@"facebookId":@"facebookId",
@"facebookAccessToken":@"facebookAccessToken",
};
return mapping;
NSDictionary *mapping = @{
@"userId":@"id",
@"firstName":@"firstName",
@"lastName":@"lastName",
@"profileImage":@"profileImage",
@"sex":@"sex",
@"birthDate":@"birthDate",
@"phone":@"phone",
@"password":@"password",
@"hasAcceptedPrivacy":@"hasAcceptedPrivacy",
@"hasAcceptedNewsletter":@"hasAcceptedNewsletter",
@"hasVerifiedEmail":@"hasVerifiedEmail",
@"emailVerifiedDate":@"emailVerifiedDate",
@"email":@"email",
@"username":@"username",
@"publicProfile":@"public_profile",
@"loginCount":@"login_count",
@"facebookId":@"facebookId",
@"facebookAccessToken":@"facebookAccessToken",
};
return mapping;
}
+ (NSString *)objectClassName {
return @"User";
return @"User";
}
+ (NSString *) objectEndPoint {
return @"User";
}
+ (BOOL) singleInstance {
return YES;
return YES;
}
#pragma mark -