Skip to content

Commit

Permalink
VCST-885: check contact lock on register by invitation (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev authored Jun 3, 2024
1 parent 3518604 commit 14ab212
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public virtual async Task<IdentityResultResponse> Handle(RegisterByInvitationCom
return SetResponse(IdentityResult.Failed(errors));
}

var contact = await _memberService.GetByIdAsync(user.MemberId) as Contact;
if (contact == null)
{
var errors = _environment.IsDevelopment() ? new[] { new IdentityError { Code = "ContactNotFound", Description = "Contact not found" } } : null;
return SetResponse(IdentityResult.Failed(errors));
}

// check lockout
if (contact.Status == ModuleConstants.ContactStatuses.Locked)
{
var errors = _environment.IsDevelopment() ? new[] { new IdentityError { Code = "ContactLocked", Description = "Contact locked" } } : null;
return SetResponse(IdentityResult.Failed(errors));
}

var identityResult = await userManager.ResetPasswordAsync(user, Uri.UnescapeDataString(request.Token), request.Password);
if (!identityResult.Succeeded)
{
Expand All @@ -71,27 +85,18 @@ public virtual async Task<IdentityResultResponse> Handle(RegisterByInvitationCom
return SetResponse(identityResult);
}

var contact = await _memberService.GetByIdAsync(user.MemberId) as Contact;
if (contact == null)
{
var errors = _environment.IsDevelopment() ? new[] { new IdentityError { Code = "ContactNotFound", Description = "Contact not found" } } : null;
identityResult = IdentityResult.Failed(errors);
}
else
{
UpdateContact(contact, request);

await _memberService.SaveChangesAsync(new Member[] { contact });
UpdateContact(contact, request);

// associate order
if (!string.IsNullOrEmpty(request.CustomerOrderId))
{
await TransferOrderAsync(request.CustomerOrderId, user.Id, contact.FullName, cancellationToken);
}
await _memberService.SaveChangesAsync([contact]);

await SendRegistrationNotificationAsync(user, contact, cancellationToken);
// associate order
if (!string.IsNullOrEmpty(request.CustomerOrderId))
{
await TransferOrderAsync(request.CustomerOrderId, user.Id, contact.FullName, cancellationToken);
}

await SendRegistrationNotificationAsync(user, contact, cancellationToken);

return SetResponse(identityResult);
}

Expand Down

0 comments on commit 14ab212

Please sign in to comment.