From 4ff9007ab81b227c3dbb092e7964ba6bec6e6c71 Mon Sep 17 00:00:00 2001 From: Saeed Bashir Date: Mon, 25 Jun 2018 16:21:43 +0500 Subject: [PATCH] Social Flow fixes --- Source/OEXFBSocial.m | 2 +- Source/OEXLoginViewController.m | 11 +++++------ Source/OEXRegistrationViewController.m | 18 +++++++++++++----- Source/OEXUserDetails.m | 4 ---- Source/en.lproj/Localizable.strings | 2 ++ Source/es-419.lproj/Localizable.strings | 2 ++ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Source/OEXFBSocial.m b/Source/OEXFBSocial.m index a326ec3750..62c93e4d78 100644 --- a/Source/OEXFBSocial.m +++ b/Source/OEXFBSocial.m @@ -75,7 +75,7 @@ - (void)logout { - (void)requestUserProfileInfoWithCompletion:(void (^)(NSDictionary*, NSError *))completion { if([FBSDKAccessToken currentAccessToken]) { - [[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { + [[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:@{@"fields": @"name,email"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { completion(result, error); }]; } diff --git a/Source/OEXLoginViewController.m b/Source/OEXLoginViewController.m index 89d84ea643..2653b5504d 100644 --- a/Source/OEXLoginViewController.m +++ b/Source/OEXLoginViewController.m @@ -259,8 +259,6 @@ - (void)handleActivationDuringLogin { [self.btn_Login applyButtonStyleWithStyle:[self.environment.styles filledPrimaryButtonStyle] withTitle:[self signInButtonText]]; [self.activityIndicator stopAnimating]; [self.view setUserInteractionEnabled:YES]; - - self.authProvider = nil; } } @@ -274,8 +272,6 @@ - (void)setSignInToDefaultState:(NSNotification*)notification { else if(![facebookManager isLogin] && [self.authProvider isKindOfClass:[OEXFacebookAuthProvider class]]) { [self handleActivationDuringLogin]; } - - self.authProvider = nil; [[OEXGoogleSocial sharedInstance] setHandledOpenUrl:NO]; } @@ -418,9 +414,12 @@ - (void)handleLoginResponseWith:(NSData*)data response:(NSURLResponse*)response else if(httpResp.statusCode == OEXHTTPStatusCode426UpgradeRequired) { [self showUpdateRequiredMessage]; } + else if (httpResp.statusCode == OEXHTTPStatusCode400BadRequest) { + NSString *errorMessage = [Strings authProviderErrorWithAuthProvider:self.authProvider.displayName platformName:self.environment.config.platformName]; + [self loginFailedWithErrorMessage:errorMessage title:nil]; + } else if(httpResp.statusCode >= 400 && httpResp.statusCode <= 500) { - NSString* errorStr = [Strings invalidUsernamePassword]; - [self loginFailedWithErrorMessage:errorStr title:nil]; + [self loginFailedWithErrorMessage:[Strings invalidUsernamePassword] title:nil]; } else { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Source/OEXRegistrationViewController.m b/Source/OEXRegistrationViewController.m index d2af77031b..ab80757bd1 100644 --- a/Source/OEXRegistrationViewController.m +++ b/Source/OEXRegistrationViewController.m @@ -347,7 +347,7 @@ - (void)toggleOptionalFields:(id)sender { #pragma mark ExternalRegistrationOptionsDelegate - (void)optionsView:(OEXExternalRegistrationOptionsView *)view choseProvider:(id)provider { - [provider authorizeServiceFromController:self requestingUserDetails:YES withCompletion:^(NSString *accessToken, OEXRegisteringUserDetails *userProfile, NSError *error) { + [provider authorizeServiceFromController:self requestingUserDetails:YES withCompletion:^(NSString *accessToken, OEXRegisteringUserDetails *userDetails, NSError *error) { if(error == nil) { [view beginIndicatingActivity]; self.view.userInteractionEnabled = NO; @@ -361,10 +361,7 @@ - (void)optionsView:(OEXExternalRegistrationOptionsView *)view choseProvider:(id }]; } else { - // No account already, so continue registration process - UIView* headingView = [[OEXUsingExternalAuthHeadingView alloc] initWithFrame:CGRectZero serviceName:provider.displayName]; - [self useHeadingView:headingView]; - [self receivedFields:userProfile fromProvider:provider withAccessToken:accessToken]; + [self configureViewForSocial:provider accessToken:accessToken userDetails:userDetails]; } }]; } @@ -379,6 +376,17 @@ - (void)optionsView:(OEXExternalRegistrationOptionsView *)view choseProvider:(id }]; } +- (void) configureViewForSocial:(id)provider accessToken:(NSString *) accessToken userDetails:(OEXRegisteringUserDetails *) userDetails { + // No account already, so continue registration process + __block OEXRegistrationViewController *blockSelf = self; + + dispatch_async(dispatch_get_main_queue(), ^{ + UIView* headingView = [[OEXUsingExternalAuthHeadingView alloc] initWithFrame:CGRectZero serviceName:provider.displayName]; + [blockSelf useHeadingView:headingView]; + [blockSelf receivedFields:userDetails fromProvider:provider withAccessToken:accessToken]; + }); +} + - (void)receivedFields:(OEXRegisteringUserDetails*)profile fromProvider:(id )provider withAccessToken:(NSString*)accessToken { self.externalAccessToken = accessToken; self.externalProvider = provider; diff --git a/Source/OEXUserDetails.m b/Source/OEXUserDetails.m index 1770af760c..9869a8ebd3 100644 --- a/Source/OEXUserDetails.m +++ b/Source/OEXUserDetails.m @@ -60,10 +60,6 @@ - (id)initWithUserDictionary:(NSDictionary*)userDetailsDictionary { _userId = [userDetailsDictionary objectForKey:OEXUserDetailsUserIdKey]; _name = [userDetailsDictionary objectForKey:OEXUserDetailsNameKey]; _url = [userDetailsDictionary objectForKey:OEXUserDetailsUrlKey]; - - if ([_name isKindOfClass:[NSNull class]]) { - _name = @""; - } } return self; diff --git a/Source/en.lproj/Localizable.strings b/Source/en.lproj/Localizable.strings index 2f8671c4a1..f30cf699a6 100644 --- a/Source/en.lproj/Localizable.strings +++ b/Source/en.lproj/Localizable.strings @@ -208,6 +208,8 @@ "APP_REVIEW.MESSAGE_SUBJECT" = "Customer Review"; /*Asteric for marking fields required*/ "ASTERIC" = "*"; +/* This error message will be shown if user tried to login with third party (facebook/google) and server returns 400 status code*/ +"AUTH_PROVIDER_ERROR" = "This {auth_provider} account is not linked with any {platform_name} account. Please register."; /*Subtitle for bulk download view when in new, partial or downloaded state - {count} is single video*/ "BULK_DOWNLOAD_VIDEOS_SUB_TITLE##{one}" = "{count} Video, {videos_size}MB total"; /*Subtitle for bulk download view when in new, partial or downloaded state - {count} is number of videos*/ diff --git a/Source/es-419.lproj/Localizable.strings b/Source/es-419.lproj/Localizable.strings index be43f84bf3..588bbc405b 100644 --- a/Source/es-419.lproj/Localizable.strings +++ b/Source/es-419.lproj/Localizable.strings @@ -208,6 +208,8 @@ "APP_REVIEW.MESSAGE_SUBJECT" = "Crítica del cliente"; /*Asteric for marking fields required*/ "ASTERIC" = "*"; +/* This error message will be shown if user tried to login with third party (facebook/google) and server returns 400 status code*/ +"AUTH_PROVIDER_ERROR" = "This {auth_provider} account is not linked with any {platform_name} account. Please register."; /*Subtitle for bulk download view when in new, partial or downloaded state - {count} is single video*/ "BULK_DOWNLOAD_VIDEOS_SUB_TITLE##{one}" = "{count} Video, {videos_size}MB total"; /*Subtitle for bulk download view when in new, partial or downloaded state - {count} is number of videos*/