Advertisement
Guest User

Untitled

a guest
May 14th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private function loginFacebookCanvas():Promise {
  2.     function retryLogin():Promise {
  3.         return FacebookManager.Instance.login()
  4.         .except(function(reason:*):Promise{
  5.             Log.warning("fbauth", "Unable to connect to Facebook, retrying in 3...\n\t$(reason)", {reason:reason});
  6.             return Promise.WallClockDelay(3)
  7.             .then(function(_:*):Promise{
  8.                 return retryLogin();
  9.             });
  10.         });
  11.     }
  12.    
  13.     return FacebookManager.Instance.queryProfile()
  14.     .then(function(profile: FacebookOwnProfile): Promise {
  15.         if (!profile) {
  16.             return retryLogin();
  17.         }
  18.         return Promise.Resolve(profile);
  19.     }, function(reason:*):Promise{
  20.         return retryLogin();
  21.     })
  22.     .then(getUserFromFBProfile)
  23.     .except(function(reason:Object):Promise{
  24.         Log.warning("fbauth", "Facebook authorization failed: $(reason)", {reason : reason});
  25.         return Promise.Reject("fbauth login failed");
  26.     });
  27. }
  28.  
  29. private function getUserFromFBProfile(profile:FacebookOwnProfile):Promise{
  30.     if ( !profile ){
  31.         return Promise.Reject("no fb profile");                
  32.     }
  33.    
  34.     Log.trace("fbauth", "Authenticating with a Facebook signed request for uid=$(uid)...", { uid:profile.uid } );
  35.    
  36.     return Promise.Repeat(
  37.         function():Promise{
  38.             return Promise.WithTimeout(model.authService.loginWithFBSignedRequest(profile.signedRequest), 15);
  39.         },
  40.         3
  41.     )
  42.     .then(function(login:LoginResult):UserState {
  43.         Log.trace("fbauth", "Authenticated as Facebook user, with player uid=$(uid). Fetching save game...", { uid:login.uid } );
  44.        
  45.         var user:UserState = UserState.FromLoginResult(model, login);
  46.         user.defaultProfile = UserProfile.FromFB(profile);
  47.         return user;
  48.     });
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement