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;


    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.


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);

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

        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);
| improve this answer | |
  • Thanks. This makes sense. So (in the Habitat world), this login mechanism would block access for any user without the Default Profile? – peaks Mar 16 '17 at 13:48
  • @peaks yes because they are only dealing with this Default Profile. – Tamás Tárnok Mar 16 '17 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 :) – Tamás Tárnok Mar 17 '17 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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