示例#1
0
        public virtual async Task <IActionResult> Register(string returnUrl = null)
        {
            if (AccountService.IsSignedIn(User))
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }
            if (!CurrentSite.AllowNewRegistration)
            {
                return(new StatusCodeResult(404));
            }
            // login is equivalent to register for new social auth users
            // if db auth is disabled just redirect
            if (CurrentSite.DisableDbAuth && CurrentSite.HasAnySocialAuthEnabled())
            {
                return(RedirectToAction("Login"));
            }

            ViewData["Title"] = StringLocalizer["Register"];

            returnUrl = IdentityServerIntegration.EnsureFolderSegmentIfNeeded(CurrentSite, returnUrl);
            //identityserver integration point
            var idProvider = await IdentityServerIntegration.GetAuthorizationContextAsync(returnUrl);

            if (!string.IsNullOrEmpty(idProvider))
            {
                // if IdP is passed, then bypass showing the login screen
                return(ExternalLogin(idProvider, returnUrl));
            }
            ViewData["ReturnUrl"] = returnUrl;

            var model = new RegisterViewModel
            {
                SiteId = CurrentSite.Id
            };

            if ((CurrentSite.CaptchaOnRegistration) && (!string.IsNullOrWhiteSpace(CurrentSite.RecaptchaPublicKey)))
            {
                model.RecaptchaSiteKey    = CurrentSite.RecaptchaPublicKey;
                model.UseInvisibleCaptcha = CurrentSite.UseInvisibleRecaptcha;
            }
            model.UseEmailForLogin           = CurrentSite.UseEmailForLogin;
            model.RegistrationPreamble       = CurrentSite.RegistrationPreamble;
            model.RegistrationAgreement      = CurrentSite.RegistrationAgreement;
            model.AgreementRequired          = !string.IsNullOrWhiteSpace(CurrentSite.RegistrationAgreement);
            model.ExternalAuthenticationList = await AccountService.GetExternalAuthenticationSchemes();

            var viewName = await CustomRegistration.GetRegisterViewName(CurrentSite, HttpContext);

            await CustomRegistration.HandleRegisterGet(
                CurrentSite,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
示例#2
0
        public virtual async Task <IActionResult> Login(string returnUrl = null)
        {
            if (AccountService.IsSignedIn(User))
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }

            returnUrl = IdentityServerIntegration.EnsureFolderSegmentIfNeeded(CurrentSite, returnUrl);
            //identityserver integration point
            var idProvider = await IdentityServerIntegration.GetAuthorizationContextAsync(returnUrl);

            if (!string.IsNullOrEmpty(idProvider))
            {
                // if IdP is passed, then bypass showing the login screen
                return(ExternalLogin(idProvider, returnUrl));
            }

            ViewData["Title"]     = StringLocalizer["Log In"];
            ViewData["ReturnUrl"] = returnUrl;

            var model = new LoginViewModel();

            var recaptchaKeys = await RecaptchaKeysProvider.GetKeys().ConfigureAwait(false);

            if ((CurrentSite.CaptchaOnLogin) && (!string.IsNullOrEmpty(recaptchaKeys.PublicKey)))
            {
                model.RecaptchaSiteKey    = recaptchaKeys.PublicKey;
                model.UseInvisibleCaptcha = recaptchaKeys.Invisible;
            }
            model.UseEmailForLogin = CurrentSite.UseEmailForLogin;
            model.LoginInfoTop     = CurrentSite.LoginInfoTop;
            model.LoginInfoBottom  = CurrentSite.LoginInfoBottom;
            var externalSchemes = await AccountService.GetExternalAuthenticationSchemes();

            model.ExternalAuthenticationList = externalSchemes.ToList();
            // don't disable db auth if there are no social auth providers configured
            model.DisableDbAuth = CurrentSite.DisableDbAuth && CurrentSite.HasAnySocialAuthEnabled();

            return(View(model));
        }