Esempio n. 1
0
        protected override DriverResult Display(FacebookConnectWidgetPart part, string displayType, dynamic shapeHelper)
        {
            return(ContentShape("Parts_FacebookConnectWidget",
                                () =>
            {
                var settings = _siteService.GetSiteSettings().As <FacebookConnectSettingsPart>();

                var authenticatedUser = _authenticationService.GetAuthenticatedUser();
                var isConnected = _facebookConnectService.AuthenticatedFacebookUserIsSaved() ||
                                  (authenticatedUser != null && !string.IsNullOrEmpty(authenticatedUser.As <FacebookUserPart>().Name));

                IFacebookUser authenticatedFacebookUser = null;

                if (isConnected)
                {
                    authenticatedFacebookUser = authenticatedUser.As <FacebookUserPart>();
                }

                return shapeHelper.Parts_FacebookConnectWidget(
                    IsAuthenticated: authenticatedUser != null,
                    IsConnected: isConnected,
                    IsAuthenticatedWithFacebookConnect: _facebookConnectService.IsAuthenticated(),
                    AuthenticatedFacebookUser: authenticatedFacebookUser);
            }));
        }
Esempio n. 2
0
        private bool ValidateUser(IFacebookUser facebookUser)
        {
            IEnumerable <FacebookConnectValidationKey> errors;

            if (!_facebookConnectService.UserIsValid(facebookUser, GetSettings(), out errors))
            {
                foreach (var error in errors)
                {
                    switch (error)
                    {
                    case FacebookConnectValidationKey.NotAuthenticated:
                        _notifier.Error(T("You are not logged in and connected to the app."));
                        //ModelState.AddModelError("notVerified", T("You are not logged in and connected to the app."));
                        break;

                    case FacebookConnectValidationKey.NotVerified:
                        _notifier.Error(T("You're not a verified Facebook user. Only verified users are allowed to register, so please verify your account."));
                        //ModelState.AddModelError("notVerified", T("You're not a verified Facebook user. Only verified users are allowed to register, so please verify your account."));
                        break;
                    }
                }

                return(false);
            }

            return(true);
        }
        public void UserUpdated(IFacebookUser facebookUser)
        {
            var part = facebookUser.As <FacebookUserPart>();

            using (var wc = new WebClient())
            {
                try
                {
                    var stream = new MemoryStream(wc.DownloadData(part.GetPictureLink()));
                    _avatarsService.SaveAvatarFile(part.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                }
                catch (WebException ex)
                {
                    Logger.Error(ex, "Downloading of Facebok profile picture failed: " + ex.Message);
                }

                // Async versions throw exception regarding the transaction

                //wc.DownloadDataCompleted += _taskFactory.BuildAsyncEventHandler<object, DownloadDataCompletedEventArgs>(
                //    (sender, e) =>
                //    {
                //        if (e.Error == null)
                //        {
                //            var stream = new MemoryStream(e.Result);
                //            _avatarsService.SaveAvatarFile(facebookUserPart.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                //        }

                //        else
                //        {
                //            string message = "Downloading of Facebok profile picture failed: " + e.Error.Message;
                //            Logger.Error(e.Error, message);
                //        }
                //    }, false).Invoke;

                //wc.DownloadDataCompleted +=
                //    (sender, e) =>
                //    {
                //        if (e.Error == null)
                //        {
                //            var stream = new MemoryStream(e.Result);
                //            _avatarsService.SaveAvatarFile(facebookUserPart.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                //        }

                //        else
                //        {
                //            string message = "Downloading of Facebok profile picture failed: " + e.Error.Message;
                //            Logger.Error(e.Error, message);
                //        }
                //    };


                //wc.DownloadDataAsync(new Uri(part.PictureLink));
            }
        }
        public void UserUpdated(IFacebookUser facebookUser)
        {
            var part = facebookUser.As<FacebookUserPart>();

            using (var wc = new WebClient())
            {
                try
                {
                    var stream = new MemoryStream(wc.DownloadData(part.GetPictureLink()));
                    _avatarsService.SaveAvatarFile(part.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                }
                catch (WebException ex)
                {
                    Logger.Error(ex, "Downloading of Facebok profile picture failed: " + ex.Message);
                }

                // Async versions throw exception regarding the transaction

                //wc.DownloadDataCompleted += _taskFactory.BuildAsyncEventHandler<object, DownloadDataCompletedEventArgs>(
                //    (sender, e) =>
                //    {
                //        if (e.Error == null)
                //        {
                //            var stream = new MemoryStream(e.Result);
                //            _avatarsService.SaveAvatarFile(facebookUserPart.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                //        }

                //        else
                //        {
                //            string message = "Downloading of Facebok profile picture failed: " + e.Error.Message;
                //            Logger.Error(e.Error, message);
                //        }
                //    }, false).Invoke;

                //wc.DownloadDataCompleted +=
                //    (sender, e) =>
                //    {
                //        if (e.Error == null)
                //        {
                //            var stream = new MemoryStream(e.Result);
                //            _avatarsService.SaveAvatarFile(facebookUserPart.Id, stream, "jpg"); // We could look at the bytes to detect the file type, but rather not
                //        }

                //        else
                //        {
                //            string message = "Downloading of Facebok profile picture failed: " + e.Error.Message;
                //            Logger.Error(e.Error, message);
                //        }
                //    };

                //wc.DownloadDataAsync(new Uri(part.PictureLink));
            }
        }
Esempio n. 5
0
        public void UpdateFacebookUser(IUser user, IFacebookUser facebookUser)
        {
            var part = user.As <FacebookUserPart>();

            // Could this be better, e.g. with Automapper?
            part.FacebookUserId   = facebookUser.FacebookUserId;
            part.FacebookUserName = facebookUser.FacebookUserName;
            part.FirstName        = facebookUser.FirstName;
            part.Gender           = facebookUser.Gender;
            part.IsVerified       = facebookUser.IsVerified;
            part.LastName         = facebookUser.LastName;
            part.Link             = facebookUser.Link;
            part.Locale           = facebookUser.Locale;
            part.Name             = facebookUser.Name;
            part.TimeZone         = facebookUser.TimeZone;

            _eventHandler.UserUpdated(user.As <IFacebookUser>());
        }
Esempio n. 6
0
        public bool UserIsValid(IFacebookUser facebookUser, IFacebookConnectSettings settings, out IEnumerable <FacebookConnectValidationKey> errors)
        {
            var errorsList = new List <FacebookConnectValidationKey>();


            if (!this.IsAuthenticated())
            {
                errorsList.Add(FacebookConnectValidationKey.NotAuthenticated);
            }
            if (settings.OnlyAllowVerified && !facebookUser.IsVerified)
            {
                errorsList.Add(FacebookConnectValidationKey.NotVerified);
            }

            errors = errorsList;

            return(errorsList.Count == 0);
        }
        /// <summary>
        /// Updates the currently authenticated Facebook user's local profile with fresh profile data from Facebook
        /// </summary>
        /// <param name="newData">Data to update the profile with. If not set, fresh data will be fetched from Facebook.</param>
        /// <returns>The updated user</returns>
        public static IFacebookUser UpdateAuthenticatedFacebookUser(this IFacebookConnectService service, IFacebookUser newData = null)
        {
            var facebookUser = GetAuthenticatedFacebookUser(service);

            if (facebookUser == null) return null;

            if (newData == null) newData = service.FetchMe();
            service.UpdateFacebookUser(facebookUser.As<IUser>(), newData);

            return facebookUser;
        }
        /// <summary>
        /// Updates the currently authenticated Facebook user's local profile with fresh profile data from Facebook
        /// </summary>
        /// <param name="newData">Data to update the profile with. If not set, fresh data will be fetched from Facebook.</param>
        /// <returns>The updated user</returns>
        public static IFacebookUser UpdateAuthenticatedFacebookUser(this IFacebookConnectService service, IFacebookUser newData = null)
        {
            var facebookUser = GetAuthenticatedFacebookUser(service);

            if (facebookUser == null)
            {
                return(null);
            }

            if (newData == null)
            {
                newData = service.FetchMe();
            }
            service.UpdateFacebookUser(facebookUser.As <IUser>(), newData);

            return(facebookUser);
        }
 public static string GetPictureLink(this IFacebookUser user)
 {
     return("http://graph.facebook.com/" + user.FacebookUserId + "/picture");
 }
        private bool ValidateUser(IFacebookUser facebookUser)
        {
            IEnumerable<FacebookConnectValidationKey> errors;
            if (!_facebookConnectService.UserIsValid(facebookUser, GetSettings(), out errors))
            {
                foreach (var error in errors)
                {
                    switch (error)
                    {
                        case FacebookConnectValidationKey.NotAuthenticated:
                            _notifier.Error(T("You are not logged in and connected to the app."));
                            //ModelState.AddModelError("notVerified", T("You are not logged in and connected to the app."));
                            break;
                        case FacebookConnectValidationKey.NotVerified:
                            _notifier.Error(T("You're not a verified Facebook user. Only verified users are allowed to register, so please verify your account."));
                            //ModelState.AddModelError("notVerified", T("You're not a verified Facebook user. Only verified users are allowed to register, so please verify your account."));
                            break;
                    }
                }

                return false;
            }

            return true;
        }
        public bool UserIsValid(IFacebookUser facebookUser, IFacebookConnectSettings settings, out IEnumerable<FacebookConnectValidationKey> errors)
        {
            var errorsList = new List<FacebookConnectValidationKey>();

            if (!this.IsAuthenticated()) errorsList.Add(FacebookConnectValidationKey.NotAuthenticated);
            if (settings.OnlyAllowVerified && !facebookUser.IsVerified) errorsList.Add(FacebookConnectValidationKey.NotVerified);

            errors = errorsList;

            return errorsList.Count == 0;
        }
        public void UpdateFacebookUser(IUser user, IFacebookUser facebookUser)
        {
            var part = user.As<FacebookUserPart>();

            // Could this be better, e.g. with Automapper?
            part.FacebookUserId = facebookUser.FacebookUserId;
            part.FacebookUserName = facebookUser.FacebookUserName;
            part.FirstName = facebookUser.FirstName;
            part.Gender = facebookUser.Gender;
            part.IsVerified = facebookUser.IsVerified;
            part.LastName = facebookUser.LastName;
            part.Link = facebookUser.Link;
            part.Locale = facebookUser.Locale;
            part.Name = facebookUser.Name;
            part.TimeZone = facebookUser.TimeZone;

            _eventHandler.UserUpdated(user.As<IFacebookUser>());
        }