When I call the FindByNameOrEmailAsync method from postman it returns the user. But once I send the values through UI, the method returns null. Though the value is bound to the usernameOrEmailAddress variable and come to the method, it returns null.
Can someone help me?
<input type="email" id="emailInput" class="form-control" maxlength="255" placeholder="Enter your email" required />
<button id="requestResetEmail" class="btn btn-primary btn-block btn-flat">Request password reset</button>
abp.ui.setBusy(
$('#LoginArea'),
abp.ajax({
url: abp.appPath + 'Account/ForgotPassword',
type: 'POST',
data: JSON.stringify({
usernameOrEmailAddress: $('#emailInput').val(),
returnUrl: window.location.hash
})
})
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await
_userManager.FindByNameOrEmailAsync(model.UsernameOrEmailAddress);
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user.Id)))
{
return View("ForgotPasswordConfirmation");
}
}
else
{
return View(model);
}
}
You need to set the correct tenant.
If the username or email address is unique across tenants, inject IUnitOfWorkManager
and do:
using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var user = await _userManager.FindByNameOrEmailAsync(model.UsernameOrEmailAddress);
// ...
}
If _unitOfWorkManager.Current
is null
, wrap the above code in:
using (var uow = _unitOfWorkManager.Begin())
{
// Above code goes here
uow.Complete();
}