Create a user profile and then log-in through the Sitecore API.
In your Visual Studio Solution setup:
-
Reference the Sitecore.Commerce.Connect.CommerceServer and
Sitecore.Commerce.dll.
-
Pick the class in your solution where you would like to create and log in a
user.
-
To create the user profile, copy and paste the following code:
var customerServiceProvider = new Sitecore.Commerce.Services.Customers.CustomerServiceProvider();
var userName = @"CommerceUsers\testUser";
var password = @"mY_P@ssw0rd";
var email = @"TestUser@test.net";
var shopName = Sitecore.Context.Site.Name;
// create the user
var result = customerServiceProvider.CreateUser(new Sitecore.Commerce.Services.Customers.CreateUserRequest(userName, password, email, shopName));
if (result.CommerceUser != null)
{
// if the user was created, log in the user
var isLoggedIn = Sitecore.Security.Authentication.AuthenticationManager.Login(userName, password, false);
-
Log in.