Ejemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] BasicRegisterRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var addUserResult = await _userRepository.AddUserAsync(request);

            if (!addUserResult.Succeed)
            {
                return(Problem(addUserResult.Errors));
            }
            var user = addUserResult.Data;

            // Generates tokens
            var generateTokensResult = _jwtService.Generate(user.Id, request.Name, request.Email);

            if (generateTokensResult.Succeed)
            {
                return(BadRequest(generateTokensResult.Errors));
            }
            var tokens = generateTokensResult.Data;

            // Cookies
            Response.Cookies.Append("pritz_jwt", tokens.Token, new Microsoft.AspNetCore.Http.CookieOptions
            {
            });

            return(Ok(tokens));
        }
Ejemplo n.º 2
0
        public Task <DataResponse <User> > AddUserAsync(BasicRegisterRequest request)
        {
            var user = new User
            {
                Name        = request.Name,
                Credentials = new Credentials
                {
                    Pitz = new PitzCredentials
                    {
                        Email    = request.Email,
                        Password = request.Password
                    }
                }
            };

            UsersDB.Add(user);

            return(Task.FromResult(new DataResponse <User>(true, user)));
        }