Esempio n. 1
0
        public void UserApplicationService_Add_without_permission()
        {
            var currentUser = new UserBuilder().WithProfile(ProfileType.Standard).Builder();

            _userRepository.Add(currentUser);
            _unitOfWork.Commit();
            _requestScope.SetUserId(currentUser.Id);

            var model = new UserModel
            {
                Name     = "test",
                Email    = "*****@*****.**",
                Password = "******",
                Profile  = (short)ProfileType.Standard
            };

            _userApplicationService.Add(model);

            var result = _userRepository.Get(new Filter());

            result.totalItems.Should().Be(1);
            result.entities.Should().HaveCount(1);
            DomainNotificationHandler.HasNotifications().Should().BeTrue();
            DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.StandardProfileUserDoesNotHavePermission);
        }
Esempio n. 2
0
 public ActionResult <UserDTO> Post([FromBody] UserDTO user)
 {
     try
     {
         return(Ok(_userApplicationService.Add(user)));
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.GetExceptionMessage() }));
     }
 }
Esempio n. 3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

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

                if (result.Succeeded)
                {
                    await _userManager.AddClaimAsync(user, new Claim("Topic", "Logged"));

                    var userViewModel = new UserViewModel
                    {
                        IdentityId = Guid.Parse(user.Id),
                        Name       = model.Name,
                        Email      = user.Email
                    };
                    _userApplicationService.Add(userViewModel);
                    if (!IsValidOperation())
                    {
                        await _userManager.DeleteAsync(user);

                        return(View(model));
                    }

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 4
0
        public IActionResult CreateUser([FromBody] UserDTO userDTO)
        {
            var user = _userAppService.Add(userDTO);

            return(Ok(user));
        }
Esempio n. 5
0
 public IActionResult Add([FromBody] UserModel model)
 {
     _userApplicationService.Add(model);
     return(Response());
 }