public IActionResult Join(int id) { Spel spel = _spelService.GetSpel(id); if (_spelService.GetSpellen(_authService.Get()).Count(x => !x.Afgelopen() && !x.Cancelled) > 0) { return(new RedirectResult("/spel")); } if (spel.Speler2 != null || spel.Afgelopen() || spel.Cancelled) { return(new RedirectResult("/spel")); } return(View(spel)); }
private object GetGameOrError(string token) { string decodedToken = ""; try { decodedToken = Base64UrlEncoder.Decode(token); } catch { return(StatusCode(404, "Game not found")); } Speler authenticatedUser = _authService.Get(); Spel game = _spelService.GetSpel(decodedToken); if (game == null) { return(StatusCode(404, "Game not found")); } if (authenticatedUser == null || (game.Speler1Token == decodedToken && game.Speler1.Id != authenticatedUser.Id) || (game.Speler2Token == decodedToken && game.Speler2.Id != authenticatedUser.Id)) { return(StatusCode(401, "You do not have access to this game.")); } return(game); }