This commit is contained in:
2020-11-19 23:25:21 +00:00
parent 7474c77004
commit 0467f5f185
2 changed files with 13 additions and 10 deletions

View File

@@ -374,7 +374,7 @@ namespace AyaNova.Api.Controllers
await Task.Delay(nFailDelay);
return StatusCode(401, new ApiErrorResponse(ApiErrorCode.AUTHENTICATION_FAILED));
}
//vet the expiry
var utcNow = new DateTimeOffset(DateTime.Now.ToUniversalTime(), TimeSpan.Zero);
if (user.PasswordResetCodeExpire < utcNow.DateTime)
@@ -396,7 +396,7 @@ namespace AyaNova.Api.Controllers
/// </summary>
/// <param name="id">User id</param>
/// <param name="apiVersion">From route path</param>
/// <returns>NoContent</returns>
/// <returns>New concurrency code</returns>
[HttpPost("request-reset-password/{id}")]
public async Task<IActionResult> SendPasswordResetCode([FromRoute] long id, ApiVersion apiVersion)
{
@@ -408,11 +408,14 @@ namespace AyaNova.Api.Controllers
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
bool successfulOperation = await biz.SendPasswordResetCode(id);
if (successfulOperation == false)
uint res = await biz.SendPasswordResetCode(id);
if (res == 0)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return NoContent();
return Ok(ApiOkResponse.Response(new
{
concurrency = res
}));
}
//------------------------------------------------------

View File

@@ -318,25 +318,25 @@ namespace AyaNova.Biz
/////////////////////////////////////////////
// GENERATE AND EMAIL Password reset code
//
internal async Task<bool> SendPasswordResetCode(long userId)
internal async Task<uint> SendPasswordResetCode(long userId)
{
User dbObject = await ct.User.Include(o => o.UserOptions).FirstOrDefaultAsync(z => z.Id == userId);
if (dbObject == null)
{
AddError(ApiErrorCode.NOT_FOUND);
return false;
return 0;
}
if (string.IsNullOrWhiteSpace(dbObject.UserOptions.EmailAddress))
{
AddError(ApiErrorCode.VALIDATION_REQUIRED, "EmailAddress");
return false;
return 0;
}
var ServerUrl = ServerGlobalOpsSettingsCache.Notify.AyaNovaServerURL;
if (string.IsNullOrWhiteSpace(ServerUrl))
{
await NotifyEventProcessor.AddOpsProblemEvent("User::SendPasswordResetCode - The OPS Notification setting is empty for AyaNova Server URL. This prevents Notification system from linking events to openable objects.");
AddError(ApiErrorCode.VALIDATION_REQUIRED, "ServerUrl", "Error: no server url configured in notification settings. Can't direct user to server for login. Set server URL and try again.");
return false;
return 0;
}
var ResetCode = Hasher.GetRandomAlphanumericString(32);
@@ -366,7 +366,7 @@ namespace AyaNova.Biz
//Log modification and save context
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified, "SendPasswordResetCode"), ct);
return true;
return dbObject.Concurrency;
}