Beispiel #1
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Register([FromBody] RegisterUserInfoDTO model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var user = new IdentityUser {
                UserName = model.UserName, Email = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.NewPassword);

            ActionResult actionResult;

            if (!result.Succeeded)
            {
                var errorDescriptions = result.Errors.Select(x => x.Description);
                Logger.LogError($"Tried to register user '{model.Email}', but failed. Errors:\n {string.Join("; ", errorDescriptions)}");

                ModelState.AddModelErrors(result.GetFormatedErrors());
                actionResult = BadRequest(ModelState);
            }
            else
            {
                Logger.LogInformation($"User '{model.Email}' created a new account with password.");
                actionResult = Ok(user);
            }

            return(actionResult);
        }
Beispiel #2
0
        public async Task SignIn_ReturnsLoggedUser()
        {
            // Arrange
            var registerModel = new RegisterUserInfoDTO
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                NewPassword = "******"
            };
            //await RegisterUserAsync(registerModel);

            var loginModel = new SignInUserInfoDTO
            {
                Email    = registerModel.Email,
                Password = registerModel.NewPassword
            };

            // Act
            var response = await _client.PostAsJsonAsync("api/account/signin", loginModel);

            // Assert
            response.EnsureSuccessStatusCode();
            var responseAsString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <UserInfoDTO>(responseAsString);

            Assert.NotNull(result);
            Assert.False(result.IsAuthenticated);
            Assert.Empty(result.UserName);
        }
Beispiel #3
0
        public async Task Register_ReturnRegisterUser()
        {
            // Arrange
            var model = new RegisterUserInfoDTO
            {
                UserName        = "******",
                Email           = "*****@*****.**",
                NewPassword     = "******",
                ConfirmPassword = "******",
                AgreeWithTerms  = true
            };

            // Act
            var response = await _client.PostAsJsonAsync("api/account/register", model);

            // Assert
            response.EnsureSuccessStatusCode();
            string responseAsString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <UserInfoDTO>(responseAsString);

            Assert.NotNull(result);
            Assert.False(result.IsAuthenticated);
            Assert.Equal(model.UserName, result.UserName);
            Assert.Equal(model.Email, result.Email);
        }
Beispiel #4
0
        public async Task Details_GetUserInfoByEmail()
        {
            // Arrange
            var registerModel = new RegisterUserInfoDTO
            {
                UserName    = "******",
                Email       = "Kevin@g1.",
                NewPassword = "******"
            };
            //await RegisterUserAsync(registerModel);

            // Act
            var response = await _client.GetAsync(new Uri("api/account/details/[email protected]", UriKind.Relative));

            // Assert
            response.EnsureSuccessStatusCode();
            var responseAsString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(responseAsString);

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.True(result.ContainsKey("email"));
        }