public string GetDefaultRedirectUrl(AuthenticationStatus status)
        {
            switch (status)
            {
            case AuthenticationStatus.Unauthenticated:
                return(_accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.LoginPage, Context.Site.GetStartItem()));

            case AuthenticationStatus.Authenticated:
                return(_accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AfterLoginPage, Context.Site.GetStartItem()));

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
        public void RegisterShouldCallRegisterUserAndRedirectToHomePage(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] IAccountsSettingsService accountsSettingsService, [Frozen] IUserProfileService userProfileService)
        {
            accountsSettingsService.GetPageLinkOrDefault(Arg.Any <Item>(), Arg.Any <ID>(), Arg.Any <Item>()).Returns("/redirect");
            repo.Exists(Arg.Any <string>()).Returns(false);
            userProfileService.GetUserDefaultProfileId().Returns(profileItem.ID.ToString());

            var controller = new AccountsController(repo, notifyService, accountsSettingsService, userProfileService, null);
            var fakeSite   = new FakeSiteContext(new StringDictionary
            {
                {
                    "rootPath", "/sitecore/content"
                },
                {
                    "startItem", item.Name
                }
            }) as SiteContext;

            fakeSite.Database = db;
            Language.Current  = Language.Invariant;

            using (new SiteContextSwitcher(fakeSite))
            {
                var result = controller.Register(registrationInfo);
                result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/redirect");

                repo.Received(1).RegisterUser(registrationInfo.Email, registrationInfo.Password, Arg.Any <string>());
            }
        }
        public void LoginShouldAddModelStateErrorIfNotLoggedIn(Database db, [Content] DbItem item, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, [Frozen] IAccountsSettingsService accountSetting)
        {
            accountSetting.GetPageLinkOrDefault(Arg.Any <Item>(), Arg.Any <ID>(), Arg.Any <Item>()).Returns("/");
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                {
                    "rootPath", "/sitecore/content"
                },
                {
                    "startItem", item.Name
                }
            }) as SiteContext;

            fakeSite.Database = db;
            Language.Current  = Language.Invariant;

            using (new SiteContextSwitcher(fakeSite))
            {
                info.ReturnUrl = null;
                info.Email     = null;
                info.Password  = null;
                var controller = new AccountsController(repo, service, accountSetting, null, null);
                repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => true);
                var result = controller.Login(info);
                result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/");
            }
        }
        public void OnActionExecuting_RedirectEqualsCurrent_ShouldRedirectToRootPage(Database db, [Content] DbItem item, string afterLoginLink, [Frozen] IAccountsSettingsService accountsSettingsService, [Substitute] ActionExecutingContext filterContext, [Greedy] AccountsRedirectAuthenticatedAttribute redirectAuthenticatedAttribute)
        {
            //Arrange
            var siteContext = new FakeSiteContext(new StringDictionary
            {
                {
                    "rootPath", "/sitecore/content"
                },
                {
                    "startItem", item.Name
                }
            }) as SiteContext;

            siteContext.Database = db;

            accountsSettingsService.GetPageLinkOrDefault(Arg.Any <Item>(), Templates.AccountsSettings.Fields.AfterLoginPage, Arg.Any <Item>()).Returns(afterLoginLink);
            filterContext.HttpContext.Request.RawUrl.Returns(afterLoginLink);

            //Act
            using (new SiteContextSwitcher(siteContext))
                using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))
                {
                    redirectAuthenticatedAttribute.OnActionExecuting(filterContext);
                }

            //Assert
            filterContext.Result.Should().BeOfType <RedirectResult>().Which.Url.Should().NotBe(afterLoginLink);
        }
        public string GetDefaultRedirectUrl(AuthenticationStatus status)
        {
            switch (status)
            {
            case AuthenticationStatus.Unauthenticated:
                return(_accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.LoginPage, Context.Site.GetStartItem()));

            case AuthenticationStatus.Authenticated:
                using (new SecurityDisabler())
                {
                    // redirectUrl may be requested prior to access being granted by authentication
                    return(_accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AfterLoginPage, Context.Site.GetStartItem()));
                }

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
        public IEnumerable <FedAuthLoginButton> GetAll()
        {
            var returnUrl = _accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AfterLoginPage);
            var args      = new GetSignInUrlInfoArgs(Context.Site.Name, returnUrl);

            GetSignInUrlInfoPipeline.Run(_pipelineManager, args);
            if (args.Result == null)
            {
                throw new InvalidOperationException("Could not retrieve federated authentication logins");
            }

            return(args.Result.Select(CreateFedAuthLoginButton).ToArray());
        }
Exemple #7
0
        public ActionResult AccountsMenu()
        {
            var isLoggedIn       = Context.IsLoggedIn && Context.PageMode.IsNormal;
            var accountsMenuInfo = new AccountsMenuInfo
            {
                IsLoggedIn = isLoggedIn,
                LoginInfo  = !isLoggedIn?CreateLoginInfo() : null,
                                 UserFullName           = isLoggedIn ? Context.User.Profile.FullName : null,
                                 UserEmail              = isLoggedIn ? Context.User.Profile.Email : null,
                                 AccountsDetailsPageUrl = _accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AccountsDetailsPage)
            };

            return(View(accountsMenuInfo));
        }
        public void Login_ReturnUrlNotSet_ShouldRedirectToRoot(Database db, [Content] DbItem item, User user, [Frozen] IAccountRepository repo, IUserProfileService userProfileService, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
        {
            accountSetting.GetPageLinkOrDefault(Arg.Any <Item>(), Arg.Any <ID>(), Arg.Any <Item>()).Returns("/");
            userProfileService.ValidateUser(Arg.Any <User>()).ReturnsForAnyArgs(true);
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "rootPath", "/sitecore/content" },
                { "startItem", item.Name }
            }) as SiteContext;

            fakeSite.Database = db;
            Language.Current  = Language.Invariant;

            using (new SiteContextSwitcher(fakeSite))
            {
                info.ReturnUrl = null;
                var controller = new AccountsController(repo, service, accountSetting, userProfileService, null);
                repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => user);
                var result = controller.Login(info);
                result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/");
            }
        }
        public void LoginShouldRedirectToRootIfReturnUrlNotSet(Database db, [Content] DbItem item, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
        {
            accountSetting.GetPageLinkOrDefault(Arg.Any<Item>(), Arg.Any<ID>(), Arg.Any<Item>()).Returns("/");
              var fakeSite = new FakeSiteContext(new StringDictionary
              {
            {
              "rootPath", "/sitecore/content"
            },
            {
              "startItem", item.Name
            }
              }) as SiteContext;
              fakeSite.Database = db;
              Language.Current = Language.Invariant;

              using (new SiteContextSwitcher(fakeSite))
              {
            info.ReturnUrl = null;
            var controller = new AccountsController(repo, service, accountSetting, null);
            repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => true);
            var result = controller.Login(info);
            result.Should().BeOfType<RedirectResult>().Which.Url.Should().Be("/");
              }
        }