Esempio n. 1
0
        public async Task <AuthenticationResult> RegisterAsync(string email, string password)
        {
            var user = await _userManager.FindByEmailAsync(email);

            if (user != null)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "User with this email address already exists" }
                });
            }
            var newUserId = Guid.NewGuid();
            var newUser   = new ApplicationUser
            {
                Id       = newUserId.ToString(),
                Email    = email,
                UserName = email
            };

            var createdUser = await _userManager.CreateAsync(newUser, password);

            if (!createdUser.Succeeded)
            {
                return(new AuthenticationResult
                {
                    Errors = createdUser.Errors.Select(x => x.Description)
                });
            }
            return(await _jwtFactory.GenerateAuthenticationResultForUserAsync(newUser));
        }