Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…core into dev
  • Loading branch information
tatarincev committed Feb 6, 2020
2 parents 4c5509c + c84a8b8 commit b718191
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
45 changes: 18 additions & 27 deletions VirtoCommerce.Storefront/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,35 +301,30 @@ public async Task<ActionResult> Login([FromForm] Login login, [FromQuery]string
}
login.UserName = login.UserName?.Trim();

var user = await _signInManager.UserManager.FindByNameAsync(login.UserName);

if (user == null)
{
WorkContext.Form.Errors.Add(SecurityErrorDescriber.LoginFailed());
return View("customers/login", WorkContext);
}

if (!new CanUserLoginToStoreSpecification(user).IsSatisfiedBy(WorkContext.CurrentStore) || new IsUserSuspendedSpecification().IsSatisfiedBy(user))
{
WorkContext.Form.Errors.Add(SecurityErrorDescriber.UserCannotLoginInStore());
return View("customers/login", WorkContext);
}

var loginResult = await _signInManager.PasswordSignInAsync(login.UserName, login.Password, login.RememberMe, lockoutOnFailure: true);

if (loginResult.Succeeded)
{
var user = await _signInManager.UserManager.FindByNameAsync(login.UserName);

// Check that current user can sing in to current store
if (new CanUserLoginToStoreSpecification(user).IsSatisfiedBy(WorkContext.CurrentStore) && new IsUserSuspendedSpecification().IsSatisfiedBy(user) == false)
{
await _publisher.Publish(new UserLoginEvent(WorkContext, user));
return StoreFrontRedirect(returnUrl);
}
else
{
WorkContext.Form.Errors.Add(SecurityErrorDescriber.UserCannotLoginInStore());
await _signInManager.SignOutAsync();
loginResult = Microsoft.AspNetCore.Identity.SignInResult.NotAllowed;
}
await _publisher.Publish(new UserLoginEvent(WorkContext, user));
return StoreFrontRedirect(returnUrl);
}

if (loginResult.RequiresTwoFactor)
{
var user = await _signInManager.UserManager.FindByNameAsync(login.UserName);
if (user == null)
{
WorkContext.Form.Errors.Add(SecurityErrorDescriber.OperationFailed());
return View("customers/login", WorkContext);
}

var selectedProvider = _options.TwoFactorAuthenticationNotificationGateway;

var userManager = _signInManager.UserManager;
Expand All @@ -355,12 +350,7 @@ public async Task<ActionResult> Login([FromForm] Login login, [FromQuery]string
return View("customers/login", WorkContext);
}

twoFactorNotification = new TwoFactorSmsNotification(WorkContext.CurrentStore.Id, WorkContext.CurrentLanguage)
{
Token = code,
Recipient = phoneNumber,
};

twoFactorNotification = new TwoFactorSmsNotification(WorkContext.CurrentStore.Id, WorkContext.CurrentLanguage) { Token = code, Recipient = phoneNumber, };
}
else // "Email"
{
Expand All @@ -371,6 +361,7 @@ public async Task<ActionResult> Login([FromForm] Login login, [FromQuery]string
Recipient = GetUserEmail(user)
};
}

var sendingResult = await SendNotificationAsync(twoFactorNotification);

if (sendingResult.IsSuccess != true)
Expand Down
6 changes: 3 additions & 3 deletions VirtoCommerce.Storefront/Controllers/BulkOrderController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -117,12 +116,13 @@ private async Task EnsureThatCartExistsAsync()
private async Task<string[]> TryAddItemsToCartAsync(BulkOrderItem[] bulkOrderItems)
{
var skus = bulkOrderItems.Select(i => i.Sku).ToList();
var filter = $"code:{string.Join(",", skus)}";
//TODO: Need to replace from indexed search to special method GetProductByCodes when it will be presents in the catalog API
var productSearchResult = await _catalogService.SearchProductsAsync(new ProductSearchCriteria
{
PageSize = skus.Count(),
PageSize = skus.Count,
ResponseGroup = ItemResponseGroup.Variations | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.Inventory | ItemResponseGroup.ItemProperties,
Terms = new[] { new Term { Name = "code", Value = string.Join(",", skus) } }
Terms = filter.ToTerms().ToList()
});
//Because product stores in index all codes of it variations and the catalog search returns only main product we need to this concat with variations
var foundSkusProductsWithVariationsMap = productSearchResult.Products.Concat(productSearchResult.Products.SelectMany(x => x.Variations))
Expand Down

0 comments on commit b718191

Please sign in to comment.