Esempio n. 1
0
        /// <summary>
        /// Check if we need to display the Login form
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void SingleSignOnOptionsChanged(object sender, EventArgs e)
        {
            var singleSignOnOptions = this.Login1.FindControlAs <RadioButtonList>("SingleSignOnOptions");

            var userNameRow = this.Login1.FindControlAs <HtmlTableRow>("UserNameRow");
            var passwordRow = this.Login1.FindControlAs <HtmlTableRow>("PasswordRow");
            var forumLogin  = this.Login1.FindControlAs <Button>("LoginButton");

            var facebookHolder = this.Login1.FindControlAs <PlaceHolder>("FacebookHolder");
            var twitterHolder  = this.Login1.FindControlAs <PlaceHolder>("TwitterHolder");
            var googleHolder   = this.Login1.FindControlAs <PlaceHolder>("GoogleHolder");

            var loginAuth =
                (AuthService)
                Enum.Parse(typeof(AuthService), this.Get <HttpRequestBase>().QueryString.GetFirstOrDefaultAs <string>("auth"), true);

            switch (singleSignOnOptions.SelectedValue)
            {
            case "connect":
            {
                userNameRow.Visible = true;
                passwordRow.Visible = true;
                forumLogin.Visible  = true;

                facebookHolder.Visible = false;
                twitterHolder.Visible  = false;
                googleHolder.Visible   = false;

                switch (loginAuth)
                {
                case AuthService.twitter:
                {
                    this.Login1.DestinationPageUrl = SingleSignOnUser.GenerateLoginUrl(
                        AuthService.twitter,
                        false,
                        true);
                }

                break;

                case AuthService.facebook:
                {
                    this.Login1.DestinationPageUrl = SingleSignOnUser.GenerateLoginUrl(
                        AuthService.facebook,
                        false,
                        true);
                }

                break;

                case AuthService.google:
                {
                    this.Login1.DestinationPageUrl = SingleSignOnUser.GenerateLoginUrl(
                        AuthService.google,
                        false,
                        true);
                }

                break;
                }
            }

            break;

            default:
            {
                userNameRow.Visible = false;
                passwordRow.Visible = false;
                forumLogin.Visible  = false;

                switch (loginAuth)
                {
                case AuthService.twitter:
                {
                    twitterHolder.Visible = true;
                }

                break;

                case AuthService.facebook:
                {
                    facebookHolder.Visible = true;
                }

                break;

                case AuthService.google:
                {
                    googleHolder.Visible = true;
                }

                break;
                }
            }

            break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.IsPostBack)
            {
                return;
            }

            this.Login1.MembershipProvider = Config.MembershipProvider;

            // Login1.CreateUserText = "Sign up for a new account.";
            // Login1.CreateUserUrl = BuildLink.GetLink( ForumPages.register );
            this.Login1.PasswordRecoveryText = this.GetText("lostpassword");
            this.Login1.PasswordRecoveryUrl  = BuildLink.GetLink(ForumPages.RecoverPassword);
            this.Login1.FailureText          = this.GetText("password_error");

            this.Login1.DestinationPageUrl =
                this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl").IsSet()
                    ? this.HtmlEncode(this.Server.UrlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl")))
                    : BuildLink.GetLink(ForumPages.forum);

            // localize controls
            var rememberMe       = this.Login1.FindControlAs <CheckBox>("RememberMe");
            var userName         = this.Login1.FindControlAs <TextBox>("UserName");
            var password         = this.Login1.FindControlAs <TextBox>("Password");
            var forumLogin       = this.Login1.FindControlAs <Button>("LoginButton");
            var passwordRecovery = this.Login1.FindControlAs <Button>("PasswordRecovery");
            var cancelAuthLogin  = this.Login1.FindControlAs <ThemeButton>("Cancel");

            var userNameRow = this.Login1.FindControlAs <PlaceHolder>("UserNameRow");
            var passwordRow = this.Login1.FindControlAs <PlaceHolder>("PasswordRow");

            var singleSignOnOptionsRow = this.Login1.FindControlAs <PlaceHolder>("SingleSignOnOptionsRow");
            var singleSignOnOptions    = this.Login1.FindControlAs <RadioButtonList>("SingleSignOnOptions");

            var registerLink            = this.Login1.FindControlAs <ThemeButton>("RegisterLink");
            var registerLinkPlaceHolder = this.Login1.FindControlAs <PlaceHolder>("RegisterLinkPlaceHolder");

            var singleSignOnRow = this.Login1.FindControlAs <PlaceHolder>("SingleSignOnRow");

            var facebookHolder = this.Login1.FindControlAs <PlaceHolder>("FacebookHolder");
            var facebookLogin  = this.Login1.FindControlAs <ThemeButton>("FacebookLogin");

            var twitterHolder = this.Login1.FindControlAs <PlaceHolder>("TwitterHolder");
            var twitterLogin  = this.Login1.FindControlAs <ThemeButton>("TwitterLogin");

            var googleHolder = this.Login1.FindControlAs <PlaceHolder>("GoogleHolder");
            var googleLogin  = this.Login1.FindControlAs <ThemeButton>("GoogleLogin");

            var facebookRegister = this.Login1.FindControlAs <ThemeButton>("FacebookRegister");
            var twitterRegister  = this.Login1.FindControlAs <ThemeButton>("TwitterRegister");
            var googleRegister   = this.Login1.FindControlAs <ThemeButton>("GoogleRegister");

            userName.Focus();

            /*
             *  RequiredFieldValidator usernameRequired = ( RequiredFieldValidator ) Login1.FindControl( "UsernameRequired" );
             *  RequiredFieldValidator passwordRequired = ( RequiredFieldValidator ) Login1.FindControl( "PasswordRequired" );
             *
             *  usernameRequired.ToolTip = usernameRequired.ErrorMessage = GetText( "REGISTER", "NEED_USERNAME" );
             *  passwordRequired.ToolTip = passwordRequired.ErrorMessage = GetText( "REGISTER", "NEED_PASSWORD" );
             */
            if (rememberMe != null)
            {
                rememberMe.Text = this.GetText("auto");
            }

            if (forumLogin != null)
            {
                forumLogin.Text = this.GetText("FORUM_LOGIN");
            }

            if (passwordRecovery != null)
            {
                passwordRecovery.Text = this.GetText("LOSTPASSWORD");
            }

            if (password != null && forumLogin != null)
            {
                password.Attributes.Add(
                    "onkeydown",
                    $@"if(event.which || event.keyCode){{if ((event.which == 13) || (event.keyCode == 13)) {{
                              document.getElementById('{forumLogin.ClientID}').click();return false;}}}} else {{return true}}; ");
            }

            if (registerLinkPlaceHolder != null && this.PageContext.IsGuest &&
                !this.Get <BoardSettings>().DisableRegistrations&& !Config.IsAnyPortal)
            {
                registerLinkPlaceHolder.Visible = true;

                registerLink.TextLocalizedTag = "REGISTER_INSTEAD";
            }

            if (this.Get <BoardSettings>().AllowSingleSignOn &&
                (Config.FacebookAPIKey.IsSet() || Config.TwitterConsumerKey.IsSet() || Config.GoogleClientID.IsSet()))
            {
                singleSignOnRow.Visible = true;

                var facebookEnabled = Config.FacebookAPIKey.IsSet() && Config.FacebookSecretKey.IsSet();
                var twitterEnabled  = Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet();
                var googleEnabled   = Config.GoogleClientID.IsSet() && Config.GoogleClientSecret.IsSet();

                var loginAuth = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("auth");

                if (loginAuth.IsNotSet())
                {
                    if (facebookEnabled)
                    {
                        facebookRegister.Visible           = true;
                        facebookRegister.Text              = this.GetTextFormatted("AUTH_CONNECT", "Facebook");
                        facebookRegister.TitleLocalizedTag = "AUTH_CONNECT_HELP";
                        facebookRegister.ParamTitle0       = "Facebook";
                    }

                    if (twitterEnabled)
                    {
                        twitterRegister.Visible           = true;
                        twitterRegister.Text              = this.GetTextFormatted("AUTH_CONNECT", "Twitter");
                        twitterRegister.TitleLocalizedTag = "AUTH_CONNECT_HELP";
                        twitterRegister.ParamTitle0       = "Twitter";
                    }

                    if (googleEnabled)
                    {
                        googleRegister.Visible           = true;
                        googleRegister.Text              = this.GetTextFormatted("AUTH_CONNECT", "Google");
                        googleRegister.TitleLocalizedTag = "AUTH_CONNECT_HELP";
                        googleRegister.ParamTitle0       = "Google";
                    }
                }
                else
                {
                    singleSignOnOptionsRow.Visible = true;

                    facebookRegister.Visible = false;
                    twitterRegister.Visible  = false;
                    googleRegister.Visible   = false;

                    userNameRow.Visible             = false;
                    passwordRow.Visible             = false;
                    registerLinkPlaceHolder.Visible = false;
                    passwordRecovery.Visible        = false;
                    forumLogin.Visible = false;
                    rememberMe.Visible = false;

                    cancelAuthLogin.Visible = true;

                    switch ((AuthService)Enum.Parse(typeof(AuthService), loginAuth, true))
                    {
                    case AuthService.twitter:
                    {
                        twitterHolder.Visible = twitterEnabled;

                        singleSignOnOptions.Items.Clear();

                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value    = "login",
                                Text     = this.GetTextFormatted("AUTH_LOGIN_EXISTING", "Twitter"),
                                Selected = true
                            });
                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value = "connect",
                                Text  =
                                    this.GetTextFormatted(
                                        "AUTH_CONNECT_ACCOUNT",
                                        "Twitter",
                                        this.GetText("AUTH_CONNECT_TWITTER"))
                            });

                        if (twitterEnabled)
                        {
                            try
                            {
                                var twitterLoginUrl = SingleSignOnUser.GenerateLoginUrl(AuthService.twitter, true);

                                // Redirect the user to Twitter for authorization.
                                twitterLogin.Attributes.Add("onclick", twitterLoginUrl);
                            }
                            catch (Exception exception)
                            {
                                this.Logger.Warn(
                                    exception,
                                    "YAF encountered an error when loading the Twitter Login Link");

                                twitterHolder.Visible = false;
                            }
                        }
                    }

                    break;

                    case AuthService.facebook:
                    {
                        facebookHolder.Visible = facebookEnabled;

                        singleSignOnOptions.Items.Clear();

                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value    = "login",
                                Text     = this.GetTextFormatted("AUTH_LOGIN_EXISTING", "Facebook"),
                                Selected = true
                            });
                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value = "connect",
                                Text  =
                                    this.GetTextFormatted(
                                        "AUTH_CONNECT_ACCOUNT",
                                        "Facebook",
                                        this.GetText("AUTH_CONNECT_FACEBOOK"))
                            });

                        if (facebookEnabled)
                        {
                            try
                            {
                                var facebookLoginUrl = SingleSignOnUser.GenerateLoginUrl(AuthService.facebook, true);

                                // Redirect the user to Twitter for authorization.
                                facebookLogin.Attributes.Add(
                                    "onclick",
                                    $"location.href='{facebookLoginUrl}'");
                            }
                            catch (Exception exception)
                            {
                                this.Logger.Warn(
                                    exception,
                                    "YAF encountered an error when loading the facebook Login Link");

                                facebookHolder.Visible = false;
                            }
                        }
                    }

                    break;

                    case AuthService.google:
                    {
                        googleHolder.Visible = googleEnabled;

                        singleSignOnOptions.Items.Clear();

                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value    = "login",
                                Text     = this.GetTextFormatted("AUTH_LOGIN_EXISTING", "Google"),
                                Selected = true
                            });
                        singleSignOnOptions.Items.Add(
                            new ListItem
                            {
                                Value = "connect",
                                Text  =
                                    this.GetTextFormatted(
                                        "AUTH_CONNECT_ACCOUNT",
                                        "Facebook",
                                        this.GetText("AUTH_CONNECT_GOOGLE"))
                            });

                        if (googleEnabled)
                        {
                            try
                            {
                                var googleLoginUrl = SingleSignOnUser.GenerateLoginUrl(AuthService.google, true);

                                // Redirect the user to Twitter for authorization.
                                googleLogin.Attributes.Add(
                                    "onclick",
                                    $"location.href='{googleLoginUrl}'");
                            }
                            catch (Exception exception)
                            {
                                this.Logger.Warn(
                                    exception,
                                    "YAF encountered an error when loading the Google Login Link");

                                googleHolder.Visible = false;
                            }
                        }
                    }

                    break;
                    }
                }
            }

            this.DataBind();
        }