2

In Habitat, the UserProfileService class has a method for validating users, which is called on login.

public bool ValidateUser(User user)
{
    if (!string.Equals(user.Domain.Name, Context.Site.Domain.Name, StringComparison.InvariantCultureIgnoreCase))
        return false;

    this.SetProfileIfEmpty(user);

    return this.GetUserDefaultProfileId() == user.Profile.ProfileItemId;
}

What is the purpose of the last line? What does Habitat need to confirm, before considering a user valid? The only thing I can see from following the code is that we try to find an Edit Profile page, but I'm sure I'm missing something.

1 Answer 1

3

It's just ensuring that the user has the default profile, because they are editing/reading/registrating the users with exactly the Default Profile. You can see in the Sitecore.Feature.Accounts.Controllers.AccountsController.Register

public ActionResult Register(RegistrationInfo registrationInfo)
{
    if (this.accountRepository.Exists(registrationInfo.Email))
    {
        this.ModelState.AddModelError(nameof(registrationInfo.Email), UserAlreadyExistsError);

        return this.View(registrationInfo);
    }

    try
    {
        // here is the registration with the default profile ID
        this.accountRepository.RegisterUser(registrationInfo.Email, registrationInfo.Password, this.userProfileService.GetUserDefaultProfileId());
        this.contactProfileService?.SetPreferredEmail(registrationInfo.Email);

        var link = this.getRedirectUrlService.GetRedirectUrl(AuthenticationStatus.Authenticated);
        return this.Redirect(link);
    }
    catch (MembershipCreateUserException ex)
    {
        Log.Error($"Can't create user with {registrationInfo.Email}", ex, this);
        this.ModelState.AddModelError(nameof(registrationInfo.Email), ex.Message);

        return this.View(registrationInfo);
    }
}
3
  • Thanks. This makes sense. So (in the Habitat world), this login mechanism would block access for any user without the Default Profile?
    – peaks
    Commented Mar 16, 2017 at 13:48
  • @peaks yes because they are only dealing with this Default Profile. Commented Mar 16, 2017 at 13:56
  • 1
    @peaks if it is the answer for you can you mark it as answer? Or if you have an questions just ask :) Commented Mar 17, 2017 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.