Пример #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> Logout(IdentityServerLogoutViewModel model)
        {
            await AccountService.SignOutAsync();

            // set this so UI rendering sees an anonymous user
            HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());

            // get context information (client name, post logout redirect URI and iframe for federated signout)
            var logoutModel = await IdentityServerIntegration.GetLogoutContextModelAsync(model.LogoutId);

            return(View("LoggedOut", logoutModel));
        }
Пример #3
0
        public virtual async Task <IActionResult> Logout(string logoutId)
        {
            var clientId = await IdentityServerIntegration.GetLogoutContextClientIdAsync(logoutId);

            if (!string.IsNullOrEmpty(clientId))
            {
                // if the logout request is authenticated, it's safe to automatically sign-out
                return(await Logout(new IdentityServerLogoutViewModel { LogoutId = logoutId }));
            }

            var vm = new IdentityServerLogoutViewModel
            {
                LogoutId = logoutId
            };

            return(View(vm));
        }
Пример #4
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));
        }