public IActionResult ExtendLoginTimer([FromBody] ValidationForUpdateDto validation) { try { Guid id = validation.access_token; var validationEntity = _repository.Validation.CheckAccessToken(id); if (validationEntity == null) { _logger.LogError($"No valid token with access key: {id} has been found in the db."); return(Ok(false)); } else { _logger.LogInfo($"Returned validation with access key: {id}"); var validationResult = _mapper.Map <Validation>(validationEntity); DateTime dt = DateTime.Now; dt = dt.AddMinutes(30); validationResult.expiration_date = dt; _repository.Validation.updateTokenExpirationTime(validationResult); _repository.Save(); return(Ok(true)); } } catch (Exception ex) { _logger.LogError($"Something went wrong inside GetValidationByToken action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public IActionResult logout([FromBody] string item) { try { Guid token = Guid.Parse(item); if (token.GetType() != typeof(Guid)) { _logger.LogError("User object sent from client is null."); return(BadRequest("User object is null")); } var validationEntity = _repository.Validation.CheckAccessToken(token); if (validationEntity == null) { _logger.LogError($"validation with access token: {token}, hasn't been found in db."); return(NotFound()); } ValidationForUpdateDto val = new ValidationForUpdateDto(); DateTime dt = DateTime.Now; val.access_token = validationEntity.access_token; val.user_id = validationEntity.userId; val.creation_date = validationEntity.Creation_date; val.expiration_date = dt; _mapper.Map(val, validationEntity); _repository.Validation.updateTokenExpirationTime(validationEntity); _repository.Save(); return(Ok("logged out")); } catch (Exception ex) { _logger.LogError($"Something went wrong inside logout action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }