public async Task<ActionResult> UndoCorona([FromQuery] int userId) { User user = null; // You can only mark yourself as having corona if (UserUtilities.GetUserId(httpContextAccessor.HttpContext.User) != userId) { return Unauthorized(); } user = await DataAccess.Get<User, int>(userId); user.AtRisk = false; await user.UpdateAsync(); try { await VisitAccess.UpdateVisitStatus(userId, SqlConstants.DateTimeMin, false); } catch (Exception ex) { throw new Exception("Failed to update user as not having covid", ex); } return new OkResult(); }
public async Task <ActionResult <string> > Get([FromQuery] int userId = 0) { // TODO: Make sure userId IS current user var response = await VisitAccess.GetVisitResponseFor(userId); StringBuilder sb = new StringBuilder(); var text = JsonConvert.SerializeObject(response); var result = new OkObjectResult(text); return(result); }
public bool CanJoin(Player p, bool ignorePerms = false) { if (p == null) { return(true); } if (!VisitAccess.CheckDetailed(p, ignorePerms)) { return(false); } if (Server.lockdown.Contains(name)) { Player.Message(p, "The level " + name + " is locked."); return(false); } return(true); }
public async Task<ActionResult> MarkAsPositive([FromBody] UserAtRiskRequest request) { var userId = request.UserId; User user = null; // You can only mark yourself as having corona if (UserUtilities.GetUserId(httpContextAccessor.HttpContext.User) != userId) { return Unauthorized(); } try { user = await DataAccess.Get<User, int>(userId); if (user.AtRisk) { return new OkResult(); } } catch { return Unauthorized(); } request.ToPersistedData(user); var targetedDay = DateTime.Today.AddDays(-18); await VisitAccess.UpdateVisitStatus(userId, targetedDay); user.AtRisk = true; await user.UpdateAsync(); try { var affectedUserIds = await RiskAccess.GetUsersAffectedBy(userId, targetedDay); await RiskAccess.PrepareUsersForNotification(affectedUserIds, DateTime.Now); } catch (Exception ex) { throw new Exception("Failed to notify user", ex); } return new OkResult(); }
public bool CanJoin(Player p) { if (p.IsConsole) { return(true); } bool skip = p.summonedMap != null && p.summonedMap.CaselessEq(name); LevelPermission plRank = skip ? LevelPermission.Nobody : p.Rank; if (!VisitAccess.CheckDetailed(p, plRank)) { return(false); } if (Server.lockdown.Contains(name)) { p.Message("The level " + name + " is locked."); return(false); } return(true); }
public async Task <ActionResult> DeleteData(int userId) { var claims = httpContextAccessor.HttpContext.User; var claim = claims.FindFirst(ClaimTypes.NameIdentifier); if (claim != null && int.TryParse(claim.Value, out int claimUserId)) { if (userId != claimUserId) { return(Unauthorized()); } await VisitAccess.DeleteVisitsByUser(userId); } else { return(Unauthorized()); } return(new OkResult()); }