Example #1
0
 public ActionResult Login(LoginInfo loginInfo)
 {
   return this.Login(loginInfo, redirectUrl => new RedirectResult(redirectUrl));
 }
Example #2
0
    protected virtual ActionResult Login(LoginInfo loginInfo, Func<string, ActionResult> redirectAction)
    {
      var result = this.accountRepository.Login(loginInfo.Email, loginInfo.Password);
      if (result)
      {
        var redirectUrl = loginInfo.ReturnUrl;
        if (string.IsNullOrEmpty(redirectUrl))
        {
          redirectUrl = this.accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AfterLoginPage, Context.Site.GetRootItem());
        }

        return redirectAction(redirectUrl);
      }

      this.ModelState.AddModelError("invalidCredentials", "Username or password is not valid.");

      return this.View(loginInfo);
    }
 public void _LoginShouldRedirectIfLoggedIn(Database db, [Content] DbItem item, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
 {
   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<JsonResult>();
   ((result as JsonResult).Data as LoginResult).RedirectUrl.Should().BeEquivalentTo(info.ReturnUrl);
 }
Example #4
0
 public ActionResult LoginDialog(LoginInfo loginInfo)
 {
   return this.Login(loginInfo, redirectUrl => this.Json(new LoginResult
   {
     RedirectUrl = redirectUrl
   }));
 }
 public void ShouldAddErrorToModelStateIfNotLoggedIn([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
 {
   repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => false);
   var controller = new AccountsController(repo, service, accountSetting, null, null);
   var result = controller.Login(info);
   controller.ModelState.IsValid.Should().BeFalse();
   controller.ModelState.Keys.Should().Contain("invalidCredentials");
 }
 public void _LoginShouldReturnViewIfNotValid(IAccountRepository repo, [NoAutoProperties] AccountsController controller, LoginInfo info)
 {
   var result = controller._Login(info);
   result.Should().BeOfType<ViewResult>();
 }
    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 LoginShouldReturnViewModelIfModelStateNotValid([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
 {
   var controller = new AccountsController(repo, service, accountSetting, null, null);
   controller.ModelState.AddModelError("Error", "Error");
   var result = controller.Login(info);
   result.Should().BeOfType<ViewResult>();
 }
 public void LoginShouldRedirectToReturnUrlIfLoggedIn([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting)
 {
   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(info.ReturnUrl);
 }
 public void _Login_LoggedIn_ShouldRedirect(Database db, [Content] DbItem item, User user, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting, IUserProfileService userProfileService)
 {
     userProfileService.ValidateUser(Arg.Any<User>()).ReturnsForAnyArgs(true);
     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<JsonResult>();
     ((result as JsonResult).Data as LoginResult).RedirectUrl.Should().BeEquivalentTo(info.ReturnUrl);
 }
        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 Login_ValidaData_ShouldRedirectToReturnUrl([Frozen] IAccountRepository repo, LoginInfo info, User user, INotificationService service, IAccountsSettingsService accountSetting, IUserProfileService userProfileService)
 {
     userProfileService.ValidateUser(Arg.Any<User>()).ReturnsForAnyArgs(true);
     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(info.ReturnUrl);
 }
Example #13
0
        protected virtual ActionResult Login(LoginInfo loginInfo, Func<string, ActionResult> redirectAction)
        {
            var user = this.accountRepository.Login(loginInfo.Email, loginInfo.Password);
            if (user == null)
            {
                this.ModelState.AddModelError("invalidCredentials", DictionaryPhraseRepository.Current.Get("/Accounts/Login/User Not Found", "Username or password is not valid."));
                return this.View(loginInfo);
            }

            if (!this.userProfileService.ValidateUser(user))
            {
                this.accountRepository.Logout();
                this.ModelState.AddModelError("invalidCredentials", DictionaryPhraseRepository.Current.Get("/Accounts/Login/Invalid User", "Sorry, your user details cannot be used on this website."));
                return this.View(loginInfo);
            }
            var redirectUrl = loginInfo.ReturnUrl;
            if (string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = this.accountsSettingsService.GetPageLinkOrDefault(Context.Item, Templates.AccountsSettings.Fields.AfterLoginPage, Context.Site.GetRootItem());
            }

            return redirectAction(redirectUrl);
        }