Esempio n. 1
0
        private void _OnLoaded()
        {
            FacebookLoginService service = null;

            try
            {
                service = new FacebookLoginService(_appKey, _appId);
                if (!FacebookClientApplication.Current2.KeepMeLoggedIn)
                {
                    service.ClearCachedCredentials();
                }

                _service = service;
                service  = null;

                if (_service.HasCachedSessionInfo)
                {
                    try
                    {
                        _OnUserLoggedIn();
                        return;
                    }
                    catch (Exception)
                    {
                        _service.ClearCachedCredentials();
                    }
                }

                LoginBrowser.Navigate(_service.GetLoginUri(_GrantedPermissionUri, _DeniedPermissionUri, _RequiredPermissions));
            }
            catch (Exception ex)
            {
                _SwitchToErrorPage(ex, _service != null);
            }
        }
Esempio n. 2
0
        public async Task SetFacebookUserProfileAsync(string accessToken)
        {
            var webserve         = new WebServices();
            var facebookServices = new FacebookLoginService();
            var Fbprofile        = await facebookServices.GetFacebookProfileAsync(accessToken);

            var alreadyRegistered = false;

            var users = JsonConvert.DeserializeObject <UserModel[]>(await webserve.GetUsers());

            foreach (var item in users)
            {
                if (item.Fullname.Equals(Fbprofile.Name))
                {
                    Settings.Token   = item.UserId;
                    Settings.Profile = JsonConvert.SerializeObject(item);
                    CloseLoginPage();
                    await _navigationService.NavigateAsync(new Uri("http://myapp.com/RootPage/SubscriberLanding/Discover", UriKind.Absolute), null, true, true);

                    alreadyRegistered = true;
                    return;
                }
            }

            if (alreadyRegistered == false)
            {
                bool register = await webserve.RegisterUser(Fbprofile.Id,
                                                            Fbprofile.FirstName,
                                                            Fbprofile.LastName,
                                                            Fbprofile.Name,
                                                            Fbprofile.Gender,
                                                            Fbprofile.Picture.Data.Url);

                if (register)
                {
                    var user = JsonConvert.DeserializeObject <UserModel[]>(await webserve.GetUsers());
                    foreach (var item in user)
                    {
                        if (item.Fullname.Equals(Fbprofile.Name))
                        {
                            Settings.Token   = item.UserId;
                            Settings.Profile = JsonConvert.SerializeObject(item);
                            CloseLoginPage();
                            await _navigationService.NavigateAsync(new Uri("http://myapp.com/RootPage/SubscriberLanding/Discover", UriKind.Absolute), null, true, true);

                            return;
                        }
                    }
                }
                else
                {
                    await PopupNavigation.Instance.PopAllAsync();

                    await pageDialogService.DisplayAlertAsync("Ooops!", "It seems like there is a problem. Please login again.", "OK");
                }
            }
        }
        public async Task <ContentResult> Facebook(string access_token, string user_id, AppName app_name)
        {
            var loginResult = await FacebookLoginService.Login(access_token, GetRequestIpAddress(), new LoginContext()
            {
                AppName   = app_name,
                LoginType = LoginType.fb,
                UserId    = user_id,
            });

            return(Content(loginResult.ToJson(), "application/json"));
        }