public void AssertBanUserReturnsFalseOnNullCurrent() { User ToBan = new User() { IsBanned = false, Party = null, PartyId = null, Token = null, Strikes = 0 }; Assert.False(AuthHelper.BanUser(ToBan, null, null)); }
public async Task <ActionResult <string> > Kick([FromForm] string email) { if (email == null) { return(BadRequest("Body is null")); } User ToKick = await _userManager.FindByEmailAsync(email).ConfigureAwait(false); User CurrentUser = await _userManager.GetUserAsync(HttpContext.User).ConfigureAwait(false); if (ToKick == null) { return(NotFound("User does not exist")); } if (CurrentUser == null) { return(Unauthorized("Need to log in first")); } Party KickFrom = _context.Parties.Where(p => p == ToKick.Party || p.Id == ToKick.PartyId).FirstOrDefault(); if (KickFrom == null) { return(NotFound("Party does not exist")); } if (KickFrom.PartyHost != CurrentUser || KickFrom.PartyHost.Id != CurrentUser.Id) { return(Forbid("Not a host user")); } ToKick.Strikes += 1; if (ToKick.Strikes >= 3) { AuthHelper.BanUser(ToKick, CurrentUser, _context); return(Ok(new { Success = true })); } KickFrom.KickedMembers.Add(ToKick); KickFrom.PartyMembers.Remove(ToKick); _context.SaveChanges(); return(Ok(new { Success = true })); }
public void AssertBanUserReturnsFalseOnNullToBan() { Assert.False(AuthHelper.BanUser(null, null, null)); }