public async Task <ActionResult> Register(Register formModel) { var anonymousShoppingCart = WorkContext.CurrentCart; var user = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = formModel.Email, Password = formModel.Password, UserName = formModel.Email, }; var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(user); if (result.Succeeded == true) { user = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(user.UserName); var contact = new VirtoCommerceCustomerModuleWebModelContact { Id = user.Id, Emails = new List <string> { formModel.Email }, FullName = string.Join(" ", formModel.FirstName, formModel.LastName), }; if (string.IsNullOrEmpty(contact.FullName)) { contact.FullName = formModel.Email; } contact = await _customerApi.CustomerModuleCreateContactAsync(contact); await _commerceCoreApi.StorefrontSecurityPasswordSignInAsync(formModel.Email, formModel.Password); var identity = CreateClaimsIdentity(formModel.Email); _authenticationManager.SignIn(identity); await MergeShoppingCartsAsync(formModel.Email, anonymousShoppingCart); return(StoreFrontRedirect("~/account")); } else { ModelState.AddModelError("form", result.Errors.First()); } return(View("customers/register", WorkContext)); }
public async Task <ActionResult> Register(Register formModel) { var user = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = formModel.Email, Password = formModel.Password, UserName = formModel.Email, UserType = "Customer", StoreId = WorkContext.CurrentStore.Id, }; //Register user in VC Platform (create security account) var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(user); if (result.Succeeded == true) { //Load newly created account from API var storefrontUser = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(user.UserName); //Next need create corresponding Customer contact in VC Customers (CRM) module //Contacts and account has the same Id. var customer = formModel.ToWebModel(); customer.Id = storefrontUser.Id; customer.UserId = storefrontUser.Id; customer.UserName = storefrontUser.UserName; customer.IsRegisteredUser = true; customer.AllowedStores = storefrontUser.AllowedStores; await _customerService.CreateCustomerAsync(customer); await _commerceCoreApi.StorefrontSecurityPasswordSignInAsync(storefrontUser.UserName, formModel.Password); var identity = CreateClaimsIdentity(customer); _authenticationManager.SignIn(identity); //Publish user login event await _userLoginEventPublisher.PublishAsync(new UserLoginEvent(WorkContext, WorkContext.CurrentCustomer, customer)); return(StoreFrontRedirect("~/account")); } else { ModelState.AddModelError("form", result.Errors.First()); } return(View("customers/register", WorkContext)); }
/// <summary> /// Create a new user /// </summary> /// <param name="user"></param> /// <returns>Task of ApiResponse (VirtoCommercePlatformCoreSecuritySecurityResult)</returns> public async System.Threading.Tasks.Task<ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult>> StorefrontSecurityCreateAsyncWithHttpInfo (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { // verify the required parameter 'user' is set if (user == null) throw new ApiException(400, "Missing required parameter 'user' when calling StorefrontSecurityCreate"); var path_ = "/api/storefront/security/user"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); String postBody = null; // to determine the Accept header String[] http_header_accepts = new String[] { "application/json", "text/json" }; String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts); if (http_header_accept != null) headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts)); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json pathParams.Add("format", "json"); postBody = Configuration.ApiClient.Serialize(user); // http body (model) parameter // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); int statusCode = (int) response.StatusCode; if (statusCode >= 400) throw new ApiException (statusCode, "Error calling StorefrontSecurityCreate: " + response.Content, response.Content); else if (statusCode == 0) throw new ApiException (statusCode, "Error calling StorefrontSecurityCreate: " + response.ErrorMessage, response.ErrorMessage); return new ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult>(statusCode, response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (VirtoCommercePlatformCoreSecuritySecurityResult) Configuration.ApiClient.Deserialize(response, typeof(VirtoCommercePlatformCoreSecuritySecurityResult))); }
/// <summary> /// Create a new user /// </summary> /// <param name="user"></param> /// <returns>Task of VirtoCommercePlatformCoreSecuritySecurityResult</returns> public async System.Threading.Tasks.Task<VirtoCommercePlatformCoreSecuritySecurityResult> StorefrontSecurityCreateAsync (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult> response = await StorefrontSecurityCreateAsyncWithHttpInfo(user); return response.Data; }
/// <summary> /// Create a new user /// </summary> /// <param name="user"></param> /// <returns>VirtoCommercePlatformCoreSecuritySecurityResult</returns> public VirtoCommercePlatformCoreSecuritySecurityResult StorefrontSecurityCreate (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult> response = StorefrontSecurityCreateWithHttpInfo(user); return response.Data; }
/// <summary> /// Update user details by user ID /// </summary> /// <param name="user">User details.</param> /// <returns>VirtoCommercePlatformCoreSecuritySecurityResult</returns> public VirtoCommercePlatformCoreSecuritySecurityResult SecurityUpdateAsync (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult> response = SecurityUpdateAsyncWithHttpInfo(user); return response.Data; }
public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await _authenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest); } CustomerInfo customer; var user = await _commerceCoreApi.StorefrontSecurityGetUserByLoginAsync(loginInfo.Login.LoginProvider, loginInfo.Login.ProviderKey); if (user != null) { customer = await GetStorefrontCustomerByUserAsync(user); } else { var newUser = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = loginInfo.Email, UserName = string.Join("--", loginInfo.Login.LoginProvider, loginInfo.Login.ProviderKey), UserType = "Customer", StoreId = WorkContext.CurrentStore.Id, Logins = new List<VirtoCommercePlatformCoreSecurityApplicationUserLogin> { new VirtoCommercePlatformCoreSecurityApplicationUserLogin { LoginProvider = loginInfo.Login.LoginProvider, ProviderKey = loginInfo.Login.ProviderKey } } }; var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(newUser); if (result.Succeeded == true) { var storefrontUser = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(newUser.UserName); await _customerService.CreateCustomerAsync(new CustomerInfo { Id = storefrontUser.Id, UserId = storefrontUser.Id, UserName = storefrontUser.UserName, FullName = loginInfo.ExternalIdentity.Name, IsRegisteredUser = true, AllowedStores = storefrontUser.AllowedStores }); customer = await GetStorefrontCustomerByUserAsync(storefrontUser); } else { return new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError); } } var identity = CreateClaimsIdentity(customer); _authenticationManager.SignIn(identity); await _userLoginEventPublisher.PublishAsync(new UserLoginEvent(WorkContext, WorkContext.CurrentCustomer, customer)); return StoreFrontRedirect(returnUrl); }
public async Task<ActionResult> Register(Register formModel) { var user = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = formModel.Email, Password = formModel.Password, UserName = formModel.Email, UserType = "Customer", StoreId = WorkContext.CurrentStore.Id, }; //Register user in VC Platform (create security account) var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(user); if (result.Succeeded == true) { //Load newly created account from API var storefrontUser = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(user.UserName); //Next need create corresponding Customer contact in VC Customers (CRM) module //Contacts and account has the same Id. var customer = formModel.ToWebModel(); customer.Id = storefrontUser.Id; customer.UserId = storefrontUser.Id; customer.UserName = storefrontUser.UserName; customer.IsRegisteredUser = true; customer.AllowedStores = storefrontUser.AllowedStores; await _customerService.CreateCustomerAsync(customer); await _commerceCoreApi.StorefrontSecurityPasswordSignInAsync(storefrontUser.UserName, formModel.Password); var identity = CreateClaimsIdentity(customer); _authenticationManager.SignIn(identity); //Publish user login event await _userLoginEventPublisher.PublishAsync(new UserLoginEvent(WorkContext, WorkContext.CurrentCustomer, customer)); return StoreFrontRedirect("~/account"); } else { ModelState.AddModelError("form", result.Errors.First()); } return View("customers/register", WorkContext); }
/// <summary> /// Create new user /// </summary> /// <param name="user">User details.</param> /// <returns>ApiResponse of VirtoCommercePlatformCoreSecuritySecurityResult</returns> public ApiResponse< VirtoCommercePlatformCoreSecuritySecurityResult > SecurityCreateAsyncWithHttpInfo (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { // verify the required parameter 'user' is set if (user == null) throw new ApiException(400, "Missing required parameter 'user' when calling VirtoCommercePlatformApi->SecurityCreateAsync"); var path_ = "/api/platform/security/users/create"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); Object postBody = null; // to determine the Content-Type header String[] httpContentTypes = new String[] { "application/json", "text/json", "application/x-www-form-urlencoded" }; String httpContentType = Configuration.ApiClient.SelectHeaderContentType(httpContentTypes); // to determine the Accept header String[] httpHeaderAccepts = new String[] { "application/json", "text/json" }; String httpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(httpHeaderAccepts); if (httpHeaderAccept != null) headerParams.Add("Accept", httpHeaderAccept); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json pathParams.Add("format", "json"); if (user.GetType() != typeof(byte[])) { postBody = Configuration.ApiClient.Serialize(user); // http body (model) parameter } else { postBody = user; // byte array } // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, httpContentType); int statusCode = (int) response.StatusCode; if (statusCode >= 400 && (statusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404)) throw new ApiException (statusCode, "Error calling SecurityCreateAsync: " + response.Content, response.Content); else if (statusCode == 0) throw new ApiException (statusCode, "Error calling SecurityCreateAsync: " + response.ErrorMessage, response.ErrorMessage); return new ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult>(statusCode, response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (VirtoCommercePlatformCoreSecuritySecurityResult) Configuration.ApiClient.Deserialize(response, typeof(VirtoCommercePlatformCoreSecuritySecurityResult))); }
public async Task <ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await _authenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } CustomerInfo customer; var user = await _commerceCoreApi.StorefrontSecurityGetUserByLoginAsync(loginInfo.Login.LoginProvider, loginInfo.Login.ProviderKey); if (user != null) { customer = await GetStorefrontCustomerByUserAsync(user); } else { var newUser = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = loginInfo.Email, UserName = string.Join("--", loginInfo.Login.LoginProvider, loginInfo.Login.ProviderKey), UserType = "Customer", StoreId = WorkContext.CurrentStore.Id, Logins = new List <VirtoCommercePlatformCoreSecurityApplicationUserLogin> { new VirtoCommercePlatformCoreSecurityApplicationUserLogin { LoginProvider = loginInfo.Login.LoginProvider, ProviderKey = loginInfo.Login.ProviderKey } } }; var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(newUser); if (result.Succeeded == true) { var storefrontUser = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(newUser.UserName); await _customerService.CreateCustomerAsync(new CustomerInfo { Id = storefrontUser.Id, UserId = storefrontUser.Id, UserName = storefrontUser.UserName, FullName = loginInfo.ExternalIdentity.Name, IsRegisteredUser = true, AllowedStores = storefrontUser.AllowedStores }); customer = await GetStorefrontCustomerByUserAsync(storefrontUser); } else { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError)); } } var identity = CreateClaimsIdentity(customer); _authenticationManager.SignIn(identity); await _userLoginEventPublisher.PublishAsync(new UserLoginEvent(WorkContext, WorkContext.CurrentCustomer, customer)); return(StoreFrontRedirect(returnUrl)); }
/// <summary> /// Create a new user /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="user"></param> /// <returns>Task of ApiResponse (VirtoCommercePlatformCoreSecuritySecurityResult)</returns> public async System.Threading.Tasks.Task<ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult>> StorefrontSecurityCreateAsyncWithHttpInfo (VirtoCommercePlatformCoreSecurityApplicationUserExtended user) { // verify the required parameter 'user' is set if (user == null) throw new ApiException(400, "Missing required parameter 'user' when calling CommerceCoreModuleApi->StorefrontSecurityCreate"); var localVarPath = "/api/storefront/security/user"; var localVarPathParams = new Dictionary<String, String>(); var localVarQueryParams = new Dictionary<String, String>(); var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary<String, String>(); var localVarFileParams = new Dictionary<String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (user.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(user); // http body (model) parameter } else { localVarPostBody = user; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int) localVarResponse.StatusCode; if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404)) throw new ApiException (localVarStatusCode, "Error calling StorefrontSecurityCreate: " + localVarResponse.Content, localVarResponse.Content); else if (localVarStatusCode == 0) throw new ApiException (localVarStatusCode, "Error calling StorefrontSecurityCreate: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); return new ApiResponse<VirtoCommercePlatformCoreSecuritySecurityResult>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (VirtoCommercePlatformCoreSecuritySecurityResult) Configuration.ApiClient.Deserialize(localVarResponse, typeof(VirtoCommercePlatformCoreSecuritySecurityResult))); }
public async Task<ActionResult> Register(Register formModel) { var anonymousShoppingCart = WorkContext.CurrentCart; var user = new VirtoCommercePlatformCoreSecurityApplicationUserExtended { Email = formModel.Email, Password = formModel.Password, UserName = formModel.Email, }; var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(user); if (result.Succeeded == true) { user = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(user.UserName); var contact = new VirtoCommerceCustomerModuleWebModelContact { Id = user.Id, Emails = new List<string> { formModel.Email }, FullName = string.Join(" ", formModel.FirstName, formModel.LastName), }; if (string.IsNullOrEmpty(contact.FullName)) { contact.FullName = formModel.Email; } contact = await _customerApi.CustomerModuleCreateContactAsync(contact); await _commerceCoreApi.StorefrontSecurityPasswordSignInAsync(formModel.Email, formModel.Password); var identity = CreateClaimsIdentity(formModel.Email); _authenticationManager.SignIn(identity); await MergeShoppingCartsAsync(formModel.Email, anonymousShoppingCart); return StoreFrontRedirect("~/account"); } else { ModelState.AddModelError("form", result.Errors.First()); } return View("customers/register", WorkContext); }