Esempio n. 1
0
        public async Task <ActionResult <object> > RegisterAsync(RegisterRequest request)
        {
            var user = new User();

            request.CopyToModel(user);
            var result = await _userManager.CreateAsync(user, request.Password);

            if (result.Succeeded)
            {
                // generate a jwt token
                var token = _tokenManager.GenerateToken(user);

                return(Ok(new
                {
                    authToken = token,
                    firstName = "",
                    lastName = ""
                }));
            }
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return(BadRequest());
        }