This commit is contained in:
@@ -374,7 +374,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
await Task.Delay(nFailDelay);
|
await Task.Delay(nFailDelay);
|
||||||
return StatusCode(401, new ApiErrorResponse(ApiErrorCode.AUTHENTICATION_FAILED));
|
return StatusCode(401, new ApiErrorResponse(ApiErrorCode.AUTHENTICATION_FAILED));
|
||||||
}
|
}
|
||||||
|
|
||||||
//vet the expiry
|
//vet the expiry
|
||||||
var utcNow = new DateTimeOffset(DateTime.Now.ToUniversalTime(), TimeSpan.Zero);
|
var utcNow = new DateTimeOffset(DateTime.Now.ToUniversalTime(), TimeSpan.Zero);
|
||||||
if (user.PasswordResetCodeExpire < utcNow.DateTime)
|
if (user.PasswordResetCodeExpire < utcNow.DateTime)
|
||||||
@@ -396,7 +396,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">User id</param>
|
/// <param name="id">User id</param>
|
||||||
/// <param name="apiVersion">From route path</param>
|
/// <param name="apiVersion">From route path</param>
|
||||||
/// <returns>NoContent</returns>
|
/// <returns>New concurrency code</returns>
|
||||||
[HttpPost("request-reset-password/{id}")]
|
[HttpPost("request-reset-password/{id}")]
|
||||||
public async Task<IActionResult> SendPasswordResetCode([FromRoute] long id, ApiVersion apiVersion)
|
public async Task<IActionResult> SendPasswordResetCode([FromRoute] long id, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
@@ -408,11 +408,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
bool successfulOperation = await biz.SendPasswordResetCode(id);
|
uint res = await biz.SendPasswordResetCode(id);
|
||||||
if (successfulOperation == false)
|
if (res == 0)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
return NoContent();
|
return Ok(ApiOkResponse.Response(new
|
||||||
|
{
|
||||||
|
concurrency = res
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|||||||
@@ -318,25 +318,25 @@ namespace AyaNova.Biz
|
|||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
// GENERATE AND EMAIL Password reset code
|
// 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);
|
User dbObject = await ct.User.Include(o => o.UserOptions).FirstOrDefaultAsync(z => z.Id == userId);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrWhiteSpace(dbObject.UserOptions.EmailAddress))
|
if (string.IsNullOrWhiteSpace(dbObject.UserOptions.EmailAddress))
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "EmailAddress");
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "EmailAddress");
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
var ServerUrl = ServerGlobalOpsSettingsCache.Notify.AyaNovaServerURL;
|
var ServerUrl = ServerGlobalOpsSettingsCache.Notify.AyaNovaServerURL;
|
||||||
if (string.IsNullOrWhiteSpace(ServerUrl))
|
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.");
|
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.");
|
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);
|
var ResetCode = Hasher.GetRandomAlphanumericString(32);
|
||||||
@@ -366,7 +366,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//Log modification and save context
|
//Log modification and save context
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified, "SendPasswordResetCode"), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified, "SendPasswordResetCode"), ct);
|
||||||
return true;
|
return dbObject.Concurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user