Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function loginFacebookCanvas():Promise {
- function retryLogin():Promise {
- return FacebookManager.Instance.login()
- .except(function(reason:*):Promise{
- Log.warning("fbauth", "Unable to connect to Facebook, retrying in 3...\n\t$(reason)", {reason:reason});
- return Promise.WallClockDelay(3)
- .then(function(_:*):Promise{
- return retryLogin();
- });
- });
- }
- return FacebookManager.Instance.queryProfile()
- .then(function(profile: FacebookOwnProfile): Promise {
- if (!profile) {
- return retryLogin();
- }
- return Promise.Resolve(profile);
- }, function(reason:*):Promise{
- return retryLogin();
- })
- .then(getUserFromFBProfile)
- .except(function(reason:Object):Promise{
- Log.warning("fbauth", "Facebook authorization failed: $(reason)", {reason : reason});
- return Promise.Reject("fbauth login failed");
- });
- }
- private function getUserFromFBProfile(profile:FacebookOwnProfile):Promise{
- if ( !profile ){
- return Promise.Reject("no fb profile");
- }
- Log.trace("fbauth", "Authenticating with a Facebook signed request for uid=$(uid)...", { uid:profile.uid } );
- return Promise.Repeat(
- function():Promise{
- return Promise.WithTimeout(model.authService.loginWithFBSignedRequest(profile.signedRequest), 15);
- },
- 3
- )
- .then(function(login:LoginResult):UserState {
- Log.trace("fbauth", "Authenticated as Facebook user, with player uid=$(uid). Fetching save game...", { uid:login.uid } );
- var user:UserState = UserState.FromLoginResult(model, login);
- user.defaultProfile = UserProfile.FromFB(profile);
- return user;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement