Beispiel #1
0
        public async Task <IActionResult> GetGame([FromRoute] int gameId)
        {
            Game   game       = repo.GetGame(gameId);
            WAUser gameAuthor = await repo.GetGameAuthor(game);

            var genre   = repo.GetGenreById(game.GenreId);
            var gameDto = new GameDto()
            {
                Descr  = game.Descr,
                Name   = game.Name,
                Id     = game.Id,
                Genre  = genre.Descr,
                Author = new UserDto()
                {
                    Username = gameAuthor.UserName
                }
            };

            if (gameDto != null)
            {
                return(StatusCode(200, responses.GameFoundResponse(gameDto)));
            }
            else
            {
                return(StatusCode(500, ErrorResponse.ServerError));
            }
        }
        private async Task <(ClaimsIdentity, WAUser)> GetClaimsIdentity(LoginDto loginDto)
        {
            ClaimsIdentity identity = null;
            WAUser         user     = null;

            if (!string.IsNullOrEmpty(loginDto.Email) && !string.IsNullOrEmpty(loginDto.Password))
            {
                // get the user to verifty
                var userToVerify = await userManager.FindByEmailAsync(loginDto.Email);

                if (userToVerify != null)
                {
                    // check the credentials
                    if (await userManager.CheckPasswordAsync(userToVerify, loginDto.Password))
                    {
                        identity = await Task.FromResult(jwtFactory.GenerateClaimsIdentity(loginDto.Email, userToVerify.Id));

                        user = userToVerify;
                    }
                }
            }
            // return claims identity and user
            return(identity, user);
        }