예제 #1
0
        public User MapFrom(NewUserCommand command)
        {
            var user = new User(command.Name, command.Email, command.Password, DateTime.Now);

            command.Phones.ForEach(phone => user.Phones.Add(new Phone(user.Id, phone.Ddd, phone.Number)));
            return(user);
        }
예제 #2
0
        public async Task <IActionResult> Create([FromBody] NewUserCommand request)
        {
            request.IsGuest = true;
            var result = await Mediator.Send(request);

            return(Created(string.Empty, result));
        }
예제 #3
0
        public async Task <IActionResult> New(NewUserCommand command)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Inválido", "Dados para login inválidos");
                return(BadRequest());
            }

            var user   = new User(command.Email, command.Password);
            var result =
                await _userService.Create(user, user.Password);

            if (result.Succeeded)
            {
                var userCreated = await _userService.GetByEmail(user.Email);

                if (userCreated == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                var signInResult = await _userService.SignIn(userCreated, command.Password, true);

                if (signInResult.IsLockedOut)
                {
                    return(StatusCode(StatusCodes.Status423Locked));
                }

                return(RedirectToAction("Start", "Office"));
            }

            return(Unauthorized());
        }
예제 #4
0
        public void CriaUserCorretamente_UserCriado()
        {
            // Arrange
            var newUserCommand = new NewUserCommand(NAME, EMAIL, PASSWORD);

            newUserCommand.Phones.Add(new NewPhoneCommand(DDD1, PHONE1));
            newUserCommand.Phones.Add(new NewPhoneCommand($"({DDD2})", PHONE2));

            // Act
            var user = new UserMapper().MapFrom(newUserCommand);

            // Assert
            Assert.IsNotNull(user);
            Assert.AreNotEqual(Guid.Empty, user.Id);
            Assert.IsNotNull(user.Phones);
            Assert.IsTrue(user.Phones.Any());
            Assert.AreEqual(2, user.Phones.Count);

            Assert.AreEqual(NAME, user.Name);
            Assert.AreEqual(EMAIL, user.Email);
            Assert.IsTrue(new Encryption().ComparePasswords(PASSWORD, user.Password));

            Assert.AreEqual(user.Phones.First().Ddd, DDD1);
            Assert.AreEqual(user.Phones.First().Number, PHONE1);

            Assert.AreEqual(user.Phones.Last().Ddd, DDD2.OnlyNumbers());
            Assert.AreEqual(user.Phones.Last().Number, PHONE2.OnlyNumbers());
        }
예제 #5
0
        public Guid Create(NewUserCommand command)
        {
            try
            {
                var existUser = UserRepository.GetByEmail(command.Email);

                if (existUser == null)
                {
                    existUser = UserRepository.GetByUserName(command.NickName);
                }

                AssertConcern.AssertArgumentTrue(existUser == null, "Usuário já cadastrado");

                var user = new User(command.NickName, command.Email, AccountType.Normal, SubscriptionType.Gratuity);
                user.GenerateNewId();
                user.PasswordHash = SecurityService.Encrypt(command.Password);
                UserRepository.Save(user);
                AssertConcern.AssertArgumentNotGuidEmpty(user.UserId, "Id do usuário de domínio criado incorretamente");

                Uow.Commit();

                return(user.UserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        public IActionResult Register(NewUserCommand user)
        {
            bool result = _mediator.Send(user).Result;

            if (result)
            {
                return(RedirectToAction("Login"));
            }

            return(View());
        }
예제 #7
0
 public UserPageVM()
 {
     Usuarios             = new ObservableCollection <User>(UserQueries.GetUsers());
     Empleados            = new List <IdName>(PersonaQueries.GetEmpleadosDropDown());
     Roles                = new ObservableCollection <Role>(UserQueries.GetRoles());
     SelectedRole         = new Role();
     NuevoUsuarioCommand  = new NewUserCommand(this);
     UpdateUsuarioCommand = new UpdateUserCommand(this);
     NewPasswordCommand   = new UpdateUserPassword(this);
     NewUser              = new User();
 }
예제 #8
0
        public IHttpActionResult CreateNewUser(NewUserCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Dados inválidos para criação da conta"));
            }

            var userId = UserAppService.Create(command);

            return(Ok(userId));
        }
예제 #9
0
        public NewUserCommandResult New([FromBody] NewUserCommand command)
        {
            command.setRequestHost(HttpContext.Request.Host.ToString());

            _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method });

            NewUserCommandResult result = (NewUserCommandResult)_userHandler.Handle(command);

            _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode });

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }
예제 #10
0
        public async Task <IActionResult> Post([FromBody] NewUserCommand command)
        {
            if (ModelState.IsValid)
            {
                await _createUserUseCase.Handle(
                    new CreateUserRequest(command.Email, command.PasswordHash),
                    _createUserPresenter
                    );

                if (_createUserPresenter.Succeeded)
                {
                    return(Created($"api/user/{_createUserPresenter.Id}", _createUserPresenter.ContentResult));
                }
                else
                {
                    return(_createUserPresenter.ContentResult);
                }
            }

            return(BadRequest(ModelState));
        }
예제 #11
0
        public async Task <IActionResult> Create([FromBody] NewUserCommand request)
        {
            var result = await Mediator.Send(request);

            return(Created("GetUser", result));
        }
예제 #12
0
        public async Task <IHttpActionResult> Post([FromBody] NewUserCommand command)
        {
            var result = await _commandHandler.ExecuteAsync(command);

            return(ProcessResult(result));
        }
예제 #13
0
        public IHttpActionResult NewUser(NewUserCommand command)
        {
            var response = _mediator.Request(command);

            return(Created("", response.Data));
        }
예제 #14
0
 public IActionResult AddUser([FromBody] NewUserCommand command)
 {
     return(_commandHandler.ExecuteCommand(command, UserId));
 }
예제 #15
0
 public IActionResult Login(NewUserCommand user)
 {
     return(_mediator.Send(user).Result ? RedirectToAction("Index", "Home") as IActionResult : View());
 }