protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (SPContext.Current != null && SPContext.Current.Web != null && SPContext.Current.Web.CurrentUser != null)
            {
                if (Settings != null)
                {
                    byte[] BinaryId   = SPContext.Current.Web.CurrentUser.GetBinaryId();
                    string BinaryJoin = string.Join("|", BinaryId);

                    FacebookOAuthClient client = new FacebookOAuthClient
                    {
                        AppId     = AppId,
                        AppSecret = AppSecret,
                        ReturnUri = this.Page.Request.Url.AbsoluteUri
                    };

                    if ((AuthCode == null) && (!Settings.facebook_allow && string.IsNullOrWhiteSpace(Settings.facebook_access_token)))
                    {
                        FacebookScopeCollection scope = new FacebookScopeCollection();
                        scope.Add(FacebookScope.PublishStream);
                        scope.Add(FacebookScope.PublishActions);
                        scope.Add(FacebookScope.Email);
                        scope.Add(FacebookScope.Birthday);


                        Response.Redirect(client.GetAuthorizationUrl(BinaryJoin, scope));
                    }
                    else
                    {
                        if (AuthCode != null)
                        {
                            try
                            {
                                string userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
                                Settings.facebook_access_token = userAccessToken;
                                Settings.facebook_allow        = true;
                                Client.SetClubCloudSettings(Settings);
                            }
                            catch (Exception ex)
                            {
                                string emssage = ex.Message;
                            }
                        }
                    }
                }
            }
            else
            {
                this.pnl_facebook.Visible = false;
                this.pnl_secure.Visible   = true;
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Callback         = Request.QueryString["callback"];
            ContentTypeAlias = Request.QueryString["contentTypeAlias"];
            PropertyAlias    = Request.QueryString["propertyAlias"];

            if (AuthState != null)
            {
                string[] stateValue = Session["Skybrud.Social_" + AuthState] as string[];
                if (stateValue != null && stateValue.Length == 3)
                {
                    Callback         = stateValue[0];
                    ContentTypeAlias = stateValue[1];
                    PropertyAlias    = stateValue[2];
                }
            }

            // Get the prevalue options
            FacebookOAuthPreValueOptions options = FacebookOAuthPreValueOptions.Get(ContentTypeAlias, PropertyAlias);

            if (!options.IsValid)
            {
                Content.Text = "Hold on now! The options of the underlying prevalue editor isn't valid.";
                return;
            }

            // Configure the OAuth client based on the options of the prevalue options
            FacebookOAuthClient client = new FacebookOAuthClient {
                AppId       = options.AppId,
                AppSecret   = options.AppSecret,
                RedirectUri = options.RedirectUri
            };

            // Session expired?
            if (AuthState != null && Session["Skybrud.Social_" + AuthState] == null)
            {
                Content.Text = "<div class=\"error\">Session expired?</div>";
                return;
            }

            // Check whether an error response was received from Facebook
            if (AuthError != null)
            {
                Content.Text = "<div class=\"error\">Error: " + AuthErrorDescription + "</div>";
                return;
            }

            // Redirect the user to the Facebook login dialog
            if (AuthCode == null)
            {
                // Generate a new unique/random state
                string state = Guid.NewGuid().ToString();

                // Save the state in the current user session
                Session["Skybrud.Social_" + state] = new[] { Callback, ContentTypeAlias, PropertyAlias };

                // Construct the authorization URL
                string url = client.GetAuthorizationUrl(state, options.Scope);

                // Redirect the user
                Response.Redirect(url);
                return;
            }

            // Exchange the authorization code for a user access token
            string userAccessToken;

            try {
                userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
            } catch (Exception ex) {
                Content.Text = "<div class=\"error\"><b>Unable to acquire access token</b><br />" + ex.Message + "</div>";
                return;
            }

            try {
                // Initialize the Facebook service (no calls are made here)
                FacebookService service = FacebookService.CreateFromAccessToken(userAccessToken);

                // Make a call to the Facebook API to get information about the user
                FacebookUser me = service.Users.GetUser("me").Body;

                //Get accounts information. Only works with "manage_pages" permission
                FacebookAccountsResponse response = null;
                if (options.Scope.Contains("manage_pages"))
                {
                    response = service.Accounts.GetAccounts();
                }


                // Get debug information about the access token
                FacebookDebugToken debugToken = null;

                try {
                    debugToken = service.Debug.DebugToken(userAccessToken).Body;
                } catch (Exception ex) {
                    Content.Text = "<div class=\"error\"><b>Unable to acquire debug token. Are you a developer?</b><br />" + ex.Message + "</div>";
                }

                Content.Text += "<p>Hi <strong>" + me.Name + "</strong></p>";
                Content.Text += "<p>Please wait while you're being redirected...</p>";

                // Set the callback data
                FacebookOAuthData data = new FacebookOAuthData {
                    Id                   = me.Id,
                    Name                 = me.Name,
                    AccessToken          = userAccessToken,
                    ExpiresAt            = DateTime.Now.AddDays(60),
                    BusinessPages        = new FacebookBusinessPageData[0],
                    SelectedBusinessPage = null
                };

                // Set the the business pages (if available)
                if (response != null)
                {
                    data.BusinessPages = response.Body.Data.Select(ac => new FacebookBusinessPageData {
                        Id          = ac.Id,
                        Name        = ac.Name,
                        AccessToken = ac.AccessToken
                    }).ToArray();
                }

                // Update the OAuth data with information from the debug token
                if (debugToken != null)
                {
                    data.ExpiresAt = (debugToken.Data.ExpiresAt ?? DateTime.Now.AddDays(60));//NULL when manage_pages permission is granted
                    data.Scope     = (
                        from scope in debugToken.Data.Scopes select scope.Name
                        ).ToArray();
                }

                // Update the UI and close the popup window
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "callback", String.Format(
                                                                "self.opener." + Callback + "({0}); window.close();",
                                                                data.Serialize()//Save JSON data through callback parameter
                                                                ), true);
            } catch (Exception ex) {
                Content.Text = "<div class=\"error\"><b>Unable to get user information</b><br />" + ex.Message + "</div>";
            }
        }
Beispiel #3
0
        public virtual ActionResult FacebookLogin()
        {
            var resultMessage = new GenericMessageViewModel();

            Callback         = Request.QueryString["callback"];
            ContentTypeAlias = Request.QueryString["contentTypeAlias"];
            PropertyAlias    = Request.QueryString["propertyAlias"];

            if (AuthState != null)
            {
                var stateValue = Session[$"MvcForum_{AuthState}"] as string[];
                if (stateValue != null && stateValue.Length == 3)
                {
                    Callback         = stateValue[0];
                    ContentTypeAlias = stateValue[1];
                    PropertyAlias    = stateValue[2];
                }
            }

            // Get the prevalue options
            if (string.IsNullOrWhiteSpace(ForumConfiguration.Instance.FacebookAppId) ||
                string.IsNullOrWhiteSpace(ForumConfiguration.Instance.FacebookAppSecret))
            {
                resultMessage.Message     = "You need to add the Facebook app credentials";
                resultMessage.MessageType = GenericMessages.danger;
            }
            else
            {
                // Settings valid move on
                // Configure the OAuth client based on the options of the prevalue options
                var client = new FacebookOAuthClient
                {
                    AppId       = ForumConfiguration.Instance.FacebookAppId,
                    AppSecret   = ForumConfiguration.Instance.FacebookAppSecret,
                    RedirectUri = ReturnUrl
                };

                // Session expired?
                if (AuthState != null && Session[$"MvcForum_{AuthState}"] == null)
                {
                    resultMessage.Message     = "Session Expired";
                    resultMessage.MessageType = GenericMessages.danger;
                }

                // Check whether an error response was received from Facebook
                if (AuthError != null)
                {
                    Session.Remove($"MvcForum_{AuthState}");
                    resultMessage.Message     = AuthErrorDescription;
                    resultMessage.MessageType = GenericMessages.danger;
                }

                // Redirect the user to the Facebook login dialog
                if (AuthCode == null)
                {
                    // Generate a new unique/random state
                    var state = Guid.NewGuid().ToString();

                    // Save the state in the current user session
                    Session[$"MvcForum_{state}"] = new[] { Callback, ContentTypeAlias, PropertyAlias };

                    // Construct the authorization URL
                    var url = client.GetAuthorizationUrl(state, "public_profile", "email"); //"user_friends"

                    // Redirect the user
                    return(Redirect(url));
                }

                // Exchange the authorization code for a user access token
                var userAccessToken = string.Empty;
                try
                {
                    userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = $"Unable to acquire access token<br/>{ex.Message}";
                    resultMessage.MessageType = GenericMessages.danger;
                }

                try
                {
                    if (string.IsNullOrWhiteSpace(resultMessage.Message))
                    {
                        // Initialize the Facebook service (no calls are made here)
                        var service = FacebookService.CreateFromAccessToken(userAccessToken);

                        // Declare the options for the call to the API
                        var options = new FacebookGetUserOptions
                        {
                            Identifier = "me",
                            Fields     = new[] { "id", "name", "email", "first_name", "last_name", "gender" }
                        };

                        var user = service.Users.GetUser(options);

                        // Try to get the email - Some FB accounts have protected passwords
                        var email = user.Body.Email;
                        if (string.IsNullOrWhiteSpace(email))
                        {
                            resultMessage.Message =
                                LocalizationService.GetResourceString("Members.UnableToGetEmailAddress");
                            resultMessage.MessageType = GenericMessages.danger;
                            ShowMessage(resultMessage);
                            return(RedirectToAction("LogOn", "Members"));
                        }

                        // First see if this user has registered already - Use email address
                        var userExists = MembershipService.GetUserByEmail(email);

                        if (userExists != null)
                        {
                            try
                            {
                                // Users already exists, so log them in
                                FormsAuthentication.SetAuthCookie(userExists.UserName, true);
                                resultMessage.Message =
                                    LocalizationService.GetResourceString("Members.NowLoggedIn");
                                resultMessage.MessageType = GenericMessages.success;
                                ShowMessage(resultMessage);
                                return(RedirectToAction("Index", "Home"));
                            }
                            catch (Exception ex)
                            {
                                LoggingService.Error(ex);
                            }
                        }
                        else
                        {
                            // Not registered already so register them
                            var viewModel = new MemberAddViewModel
                            {
                                Email           = email,
                                LoginType       = LoginType.Facebook,
                                Password        = StringUtils.RandomString(8),
                                UserAccessToken = userAccessToken
                            };

                            // Get the image and save it
                            var getImageUrl = $"http://graph.facebook.com/{user.Body.Id}/picture?type=square";
                            viewModel.SocialProfileImageUrl = getImageUrl;

                            // Large size photo https://graph.facebook.com/{facebookId}/picture?type=large
                            // Medium size photo https://graph.facebook.com/{facebookId}/picture?type=normal
                            // Small size photo https://graph.facebook.com/{facebookId}/picture?type=small
                            // Square photo https://graph.facebook.com/{facebookId}/picture?type=square

                            // Store the viewModel in TempData - Which we'll use in the register logic
                            TempData[Constants.MemberRegisterViewModel] = viewModel;

                            return(RedirectToAction("SocialLoginValidator", "Members"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = $"Unable to get user information<br/>{ex.Message}";
                    resultMessage.MessageType = GenericMessages.danger;
                    LoggingService.Error(ex);
                }
            }

            ShowMessage(resultMessage);
            return(RedirectToAction("LogOn", "Members"));
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Callback         = Request.QueryString["callback"];
            ContentTypeAlias = Request.QueryString["contentTypeAlias"];
            PropertyAlias    = Request.QueryString["propertyAlias"];

            if (AuthState != null)
            {
                string[] stateValue = Session["Skybrud.Social_" + AuthState] as string[];
                if (stateValue != null && stateValue.Length == 3)
                {
                    Callback         = stateValue[0];
                    ContentTypeAlias = stateValue[1];
                    PropertyAlias    = stateValue[2];
                }
            }

            // Get the prevalue options
            FacebookOAuthPreValueOptions options = FacebookOAuthPreValueOptions.Get(ContentTypeAlias, PropertyAlias);

            if (!options.IsValid)
            {
                Content.Text = "Hold on now! The options of the underlying prevalue editor isn't valid.";
                return;
            }

            // Configure the OAuth client based on the options of the prevalue options
            FacebookOAuthClient client = new FacebookOAuthClient {
                AppId       = options.AppId,
                AppSecret   = options.AppSecret,
                RedirectUri = options.RedirectUri
            };

            // Session expired?
            if (AuthState != null && Session["Skybrud.Social_" + AuthState] == null)
            {
                Content.Text = "<div class=\"error\">Session expired?</div>";
                return;
            }

            // Check whether an error response was received from Facebook
            if (AuthError != null)
            {
                Content.Text = "<div class=\"error\">Error: " + AuthErrorDescription + "</div>";
                return;
            }

            // Redirect the user to the Facebook login dialog
            if (AuthCode == null)
            {
                // Generate a new unique/random state
                string state = Guid.NewGuid().ToString();

                // Save the state in the current user session
                Session["Skybrud.Social_" + state] = new[] { Callback, ContentTypeAlias, PropertyAlias };

                // Construct the authorization URL
                string url = client.GetAuthorizationUrl(state, "read_stream", "user_status", "user_about_me", "user_photos");

                // Redirect the user
                Response.Redirect(url);
                return;
            }

            // Exchange the authorization code for a user access token
            string userAccessToken;

            try {
                userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
            } catch (Exception ex) {
                Content.Text = "<div class=\"error\"><b>Unable to acquire access token</b><br />" + ex.Message + "</div>";
                return;
            }

            try {
                // Initialize the Facebook service (no calls are made here)
                FacebookService service = FacebookService.CreateFromAccessToken(userAccessToken);

                // Make a call to the Facebook API to get information about the user
                FacebookUser me = service.Users.GetUser("me").Body;

                // Get debug information about the access token
                FacebookDebugToken debug = service.Debug.DebugToken(userAccessToken).Body;

                Content.Text += "<p>Hi <strong>" + me.Name + "</strong></p>";
                Content.Text += "<p>Please wait while you're being redirected...</p>";

                // Set the callback data
                FacebookOAuthData data = new FacebookOAuthData {
                    Id          = me.Id,
                    Name        = me.Name,
                    AccessToken = userAccessToken,
                    ExpiresAt   = debug.Data.ExpiresAt == null ? default(DateTime) : debug.Data.ExpiresAt.Value,
                    Scope       = (
                        from scope in debug.Data.Scopes select scope.Name
                        ).ToArray()
                };

                // Update the UI and close the popup window
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "callback", String.Format(
                                                                "self.opener." + Callback + "({0}); window.close();",
                                                                data.Serialize()
                                                                ), true);
            } catch (Exception ex) {
                Content.Text = "<div class=\"error\"><b>Unable to get user information</b><br />" + ex.Message + "</div>";
                return;
            }
        }
Beispiel #5
0
        public ActionResult FacebookLogin()
        {
            var resultMessage = new GenericMessageViewModel();

            Callback         = Request.QueryString["callback"];
            ContentTypeAlias = Request.QueryString["contentTypeAlias"];
            PropertyAlias    = Request.QueryString["propertyAlias"];

            if (AuthState != null)
            {
                var stateValue = Session["Dialogue_" + AuthState] as string[];
                if (stateValue != null && stateValue.Length == 3)
                {
                    Callback         = stateValue[0];
                    ContentTypeAlias = stateValue[1];
                    PropertyAlias    = stateValue[2];
                }
            }

            // Get the prevalue options
            if (string.IsNullOrEmpty(Dialogue.Settings().FacebookAppId) || string.IsNullOrEmpty(Dialogue.Settings().FacebookAppSecret))
            {
                resultMessage.Message     = "You need to add the Facebook app credentials";
                resultMessage.MessageType = GenericMessages.Danger;
            }
            else
            {
                // Settings valid move on
                // Configure the OAuth client based on the options of the prevalue options
                var client = new FacebookOAuthClient
                {
                    AppId       = Dialogue.Settings().FacebookAppId,
                    AppSecret   = Dialogue.Settings().FacebookAppSecret,
                    RedirectUri = ReturnUrl
                };

                // Session expired?
                if (AuthState != null && Session["Dialogue_" + AuthState] == null)
                {
                    resultMessage.Message     = "Session Expired";
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                // Check whether an error response was received from Facebook
                if (AuthError != null)
                {
                    resultMessage.Message     = AuthErrorDescription;
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                // Redirect the user to the Facebook login dialog
                if (AuthCode == null)
                {
                    // Generate a new unique/random state
                    var state = Guid.NewGuid().ToString();

                    // Save the state in the current user session
                    Session["Dialogue_" + state] = new[] { Callback, ContentTypeAlias, PropertyAlias };

                    // Construct the authorization URL
                    var url = client.GetAuthorizationUrl(state, "public_profile", "email"); //"user_friends"

                    // Redirect the user
                    return(Redirect(url));
                }

                // Exchange the authorization code for a user access token
                var userAccessToken = string.Empty;
                try
                {
                    userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = $"Unable to acquire access token<br/>{ex.Message}";
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                try
                {
                    if (string.IsNullOrEmpty(resultMessage.Message))
                    {
                        // Initialize the Facebook service (no calls are made here)
                        var service = FacebookService.CreateFromAccessToken(userAccessToken);

                        // Declare the options for the call to the API
                        var options = new FacebookGetUserOptions
                        {
                            Identifier = "me",
                            Fields     = new[] { "id", "name", "email", "first_name", "last_name", "gender" }
                        };

                        var user = service.Users.GetUser(options);

                        // Try to get the email - Some FB accounts have protected passwords
                        var email = user.Body.Email;
                        if (string.IsNullOrEmpty(email))
                        {
                            //maybe use 'user.Body.Id @ facebook.com'

                            resultMessage.Message     = "Unable to get email address from Facebook";
                            resultMessage.MessageType = GenericMessages.Danger;
                            ShowMessage(resultMessage);
                            return(RedirectToUmbracoPage(Dialogue.Settings().ForumId));
                        }

                        // First see if this user has registered already - Use email address
                        using (UnitOfWorkManager.NewUnitOfWork())
                        {
                            var userExists = AppHelpers.UmbServices().MemberService.GetByEmail(email);

                            if (userExists != null)
                            {
                                // Update access token
                                userExists.Properties[AppConstants.PropMemberFacebookAccessToken].Value = userAccessToken;
                                AppHelpers.UmbServices().MemberService.Save(userExists);

                                // Users already exists, so log them in
                                FormsAuthentication.SetAuthCookie(userExists.Username, true);
                                resultMessage.Message     = Lang("Members.NowLoggedIn");
                                resultMessage.MessageType = GenericMessages.Success;
                            }
                            else
                            {
                                // Not registered already so register them
                                var viewModel = new RegisterViewModel
                                {
                                    Email           = email,
                                    LoginType       = LoginType.Facebook,
                                    Password        = AppHelpers.RandomString(8),
                                    UserName        = user.Body.Name,
                                    UserAccessToken = userAccessToken
                                };

                                // Get the image and save it
                                var getImageUrl = $"http://graph.facebook.com/{user.Body.Id}/picture?type=square";
                                viewModel.SocialProfileImageUrl = getImageUrl;

                                //Large size photo https://graph.facebook.com/{facebookId}/picture?type=large
                                //Medium size photo https://graph.facebook.com/{facebookId}/picture?type=normal
                                //Small size photo https://graph.facebook.com/{facebookId}/picture?type=small
                                //Square photo https://graph.facebook.com/{facebookId}/picture?type=square

                                return(RedirectToAction("MemberRegisterLogic", "DialogueRegister", viewModel));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = $"Unable to get user information<br/>{ex.Message}";
                    resultMessage.MessageType = GenericMessages.Danger;
                }
            }

            ShowMessage(resultMessage);
            return(RedirectToUmbracoPage(Dialogue.Settings().ForumId));
        }
        public ActionResult FacebookLogin()
        {
            var resultMessage = new GenericMessageViewModel();

            Callback         = Request.QueryString["callback"];
            ContentTypeAlias = Request.QueryString["contentTypeAlias"];
            PropertyAlias    = Request.QueryString["propertyAlias"];

            if (AuthState != null)
            {
                var stateValue = Session["Dialogue_" + AuthState] as string[];
                if (stateValue != null && stateValue.Length == 3)
                {
                    Callback         = stateValue[0];
                    ContentTypeAlias = stateValue[1];
                    PropertyAlias    = stateValue[2];
                }
            }

            // Get the prevalue options
            if (string.IsNullOrEmpty(Dialogue.Settings().FacebookAppId) || string.IsNullOrEmpty(Dialogue.Settings().FacebookAppSecret))
            {
                resultMessage.Message     = "You need to add the Facebook app credentials";
                resultMessage.MessageType = GenericMessages.Danger;
            }
            else
            {
                // Settings valid move on
                // Configure the OAuth client based on the options of the prevalue options
                var client = new FacebookOAuthClient
                {
                    AppId       = Dialogue.Settings().FacebookAppId,
                    AppSecret   = Dialogue.Settings().FacebookAppSecret,
                    RedirectUri = ReturnUrl
                };

                // Session expired?
                if (AuthState != null && Session["Dialogue_" + AuthState] == null)
                {
                    resultMessage.Message     = "Session Expired";
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                // Check whether an error response was received from Facebook
                if (AuthError != null)
                {
                    resultMessage.Message     = AuthErrorDescription;
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                // Redirect the user to the Facebook login dialog
                if (AuthCode == null)
                {
                    // Generate a new unique/random state
                    var state = Guid.NewGuid().ToString();

                    // Save the state in the current user session
                    Session["Dialogue_" + state] = new[] { Callback, ContentTypeAlias, PropertyAlias };

                    // Construct the authorization URL
                    var url = client.GetAuthorizationUrl(state, "public_profile", "email"); //"user_friends"

                    // Redirect the user
                    return(Redirect(url));
                }

                // Exchange the authorization code for a user access token
                var userAccessToken = string.Empty;
                try
                {
                    userAccessToken = client.GetAccessTokenFromAuthCode(AuthCode);
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = string.Format("Unable to acquire access token<br/>{0}", ex.Message);
                    resultMessage.MessageType = GenericMessages.Danger;
                }

                try
                {
                    if (string.IsNullOrEmpty(resultMessage.Message))
                    {
                        // Initialize the Facebook service (no calls are made here)
                        var service = FacebookService.CreateFromAccessToken(userAccessToken);

                        // Hack to get email
                        // Get the raw string and parse it
                        // we use this to get items manually including the email
                        var response = service.Methods.Raw.Me();
                        var obj      = JsonObject.ParseJson(response);

                        // Make a call to the Facebook API to get information about the user
                        var me = service.Methods.Me();

                        // Get debug information about the access token
                        //var debug = service.Methods.DebugToken(userAccessToken);

                        // Set the callback data
                        var data = new FacebookOAuthData
                        {
                            Id          = me.Id,
                            Name        = me.Name ?? me.UserName,
                            AccessToken = userAccessToken,
                            //ExpiresAt = debug.ExpiresAt == null ? default(DateTime) : debug.ExpiresAt.Value,
                            //Scope = debug.Scopes
                        };

                        // Try to get the email - Some FB accounts have protected passwords
                        var email = obj.GetString("email");
                        if (!string.IsNullOrEmpty(email))
                        {
                            data.Email = email;
                        }

                        // First see if this user has registered already - Use email address
                        using (UnitOfWorkManager.NewUnitOfWork())
                        {
                            // TODO - Ignore if no email - Have to check PropMemberFacebookAccessToken has a value
                            // TODO - and the me.UserName is there to match existing logged in accounts
                            var userExists = AppHelpers.UmbServices().MemberService.GetByEmail(data.Email);

                            if (userExists != null)
                            {
                                // Update access token
                                userExists.Properties[AppConstants.PropMemberFacebookAccessToken].Value = userAccessToken;
                                AppHelpers.UmbServices().MemberService.Save(userExists);

                                // Users already exists, so log them in
                                FormsAuthentication.SetAuthCookie(userExists.Username, true);
                                resultMessage.Message     = Lang("Members.NowLoggedIn");
                                resultMessage.MessageType = GenericMessages.Success;
                            }
                            else
                            {
                                // Not registered already so register them
                                var viewModel = new RegisterViewModel
                                {
                                    Email           = data.Email,
                                    LoginType       = LoginType.Facebook,
                                    Password        = AppHelpers.RandomString(8),
                                    UserName        = data.Name,
                                    UserAccessToken = userAccessToken
                                };

                                // Get the image and save it
                                var getImageUrl = string.Format("http://graph.facebook.com/{0}/picture?type=square", me.Id);
                                viewModel.SocialProfileImageUrl = getImageUrl;

                                //Large size photo https://graph.facebook.com/{facebookId}/picture?type=large
                                //Medium size photo https://graph.facebook.com/{facebookId}/picture?type=normal
                                //Small size photo https://graph.facebook.com/{facebookId}/picture?type=small
                                //Square photo https://graph.facebook.com/{facebookId}/picture?type=square

                                return(RedirectToAction("MemberRegisterLogic", "DialogueLoginRegisterSurface", viewModel));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    resultMessage.Message     = string.Format("Unable to get user information<br/>{0}", ex.Message);
                    resultMessage.MessageType = GenericMessages.Danger;
                }
            }

            ShowMessage(resultMessage);
            return(RedirectToUmbracoPage(Dialogue.Settings().ForumId));
        }