示例#1
0
        public Client MapToClientModel(ClientCreateDto dto)
        {
            var client = new Client
            {
                ClientName    = string.IsNullOrEmpty(dto.ClientName) ? dto.ClientId : dto.ClientName,
                ClientId      = dto.ClientId,
                ClientSecrets = dto.ClientSecrets?.Select(x => new Secret(x.Sha256())).ToList(),
                AlwaysIncludeUserClaimsInIdToken = true,
                AllowOfflineAccess           = true,
                AllowAccessTokensViaBrowser  = true,
                AbsoluteRefreshTokenLifetime = dto.AbsoluteRefreshTokenLifetime == null ? Int32.MaxValue : (int)dto.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime          = dto.AccessTokenLifetime == null ? Int32.MaxValue : (int)dto.AccessTokenLifetime,
                AuthorizationCodeLifetime    = dto.AuthorizationCodeLifetime == null ? Int32.MaxValue : (int)dto.AuthorizationCodeLifetime,
                ConsentLifetime             = dto.ConsentLifetime == null ? Int32.MaxValue : (int)dto.ConsentLifetime,
                IdentityTokenLifetime       = dto.IdentityTokenLifetime == null ? Int32.MaxValue : (int)dto.IdentityTokenLifetime,
                SlidingRefreshTokenLifetime = dto.SlidingRefreshTokenLifetime == null ? Int32.MaxValue : (int)dto.SlidingRefreshTokenLifetime,
                RedirectUris           = dto.RedirectUris,
                PostLogoutRedirectUris = dto.PostLogoutRedirectUris
            };

            #region default AllowedScopes
            client.AllowedScopes.Add(IdentityServerConstants.StandardScopes.OpenId);
            client.AllowedScopes.Add(IdentityServerConstants.StandardScopes.Profile);
            client.AllowedScopes.Add(IdentityServerConstants.TokenTypes.AccessToken);
            client.AllowedScopes.Add(IdentityServerConstants.TokenTypes.IdentityToken);
            #endregion

            return(client);
        }
示例#2
0
        public async Task Should_Not_CreateClient_When_Payload_Data_Is_Missing()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            var client = new ClientCreateDto
            {
                TenantId      = createdTenant.TenantId,
                FirstName     = "",
                LastName      = "any",
                ContactNumber = "any",
                EmailAddress  = "any",
                Country       = "any",
                ClientType    = ClientType.Free.ToString()
            };
            var payload = JsonConvert.SerializeObject(client);

            // Act
            var createClientResponse = await customHttpClient.PostAsync("/api/clients", new StringContent(payload, Encoding.UTF8, "application/json"));

            // Assert
            createClientResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var createClientResponseBody = await createClientResponse.Content.ReadAsStringAsync();

            createClientResponseBody.Should().Contain("The FirstName field is required");
        }
示例#3
0
 public void Map(Client client, out ClientCreateDto output)
 {
     output = new ClientCreateDto
     {
         Name = client.Name,
     };
 }
示例#4
0
 public void Map(ClientCreateDto clientCreateDto, out Client output)
 {
     output = new Client
     {
         Name = clientCreateDto.Name
     };
 }
        public virtual async Task <ClientDto> CreateAsync(ClientCreateDto clientCreate)
        {
            var clientIdExists = await ClientRepository.CheckClientIdExistAsync(clientCreate.ClientId);

            if (clientIdExists)
            {
                throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, clientCreate.ClientId]);
            }
            var client = new Client(GuidGenerator.Create(), clientCreate.ClientId)
            {
                ClientName  = clientCreate.ClientName,
                Description = clientCreate.Description
            };

            foreach (var grantType in clientCreate.AllowedGrantTypes)
            {
                client.AddGrantType(grantType);
            }

            client = await ClientRepository.InsertAsync(client);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <Client, ClientDto>(client));
        }
示例#6
0
        public string SendEmailToClient(ClientCreateDto client)
        {
            string subject     = "Room Booking Notification at Peace Hotel";
            string senderEmail = "*****@*****.**";
            string password    = "******";
            string messageBody = "This is to notify you have successfully registered at Peace Hotel";

            try
            {
                var smtpClient = new SmtpClient("smtp.gmail.com")//173.194.76.108
                {
                    Port        = 587,
                    Credentials = new NetworkCredential(senderEmail, password),
                    EnableSsl   = true,
                };

                var mailMessage = new MailMessage
                {
                    From    = new MailAddress(senderEmail),
                    Subject = subject,
                    Body    = messageBody
                };
                mailMessage.To.Add(client.Email);

                smtpClient.Send(mailMessage);
                return("sent");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
示例#7
0
        public static async Task <ClientReadDto> CreateClient(HttpClient httpClient, Guid tenantId)
        {
            var client = new ClientCreateDto
            {
                TenantId      = tenantId,
                FirstName     = "any",
                LastName      = "any",
                ContactNumber = "any",
                EmailAddress  = "any",
                Country       = "any",
                ClientType    = ClientType.Free.ToString()
            };
            var payload = JsonConvert.SerializeObject(client);

            var createClientResponse = await httpClient.PostAsync("/api/clients", new StringContent(payload, Encoding.UTF8, "application/json"));

            var createClientResponseBody = await createClientResponse.Content.ReadAsStringAsync();

            var createdClient = JsonConvert.DeserializeObject <ClientReadDto>(createClientResponseBody);

            createClientResponse.StatusCode.Should().Be(HttpStatusCode.Created);
            createdClient.TenantId.Should().Be(tenantId);

            return(createdClient);
        }
示例#8
0
 public Client Create(ClientCreateDto clientToCreate, byte[] passwordHash, byte[] passwordSalt)
 {
     return(new Client
     {
         Id = 1,
         Name = clientToCreate.Name
     });
 }
示例#9
0
        public async Task <Client> AddClient(ClientCreateDto client)
        {
            var _client = _mapper.Map <Client>(client);

            _db.Clients.Add(_client);
            int result = await _db.SaveChangesAsync();

            return(result > 0 ? _client : null);
        }
示例#10
0
        public ActionResult Create(ClientCreateDto client)
        {
            var result = _clientService.Create(client);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.ClientId },
                       result
                       ));
        }
示例#11
0
        public void CreateClient_ValidObjectPassed_ReturnsCreatedAtRouteResult()
        {
            var testItem = new ClientCreateDto()
            {
                Firstname = "Fernando", Lastname = "Zabala", Document = "A1242"
            };
            var response = controller.CreateClient(testItem);

            Assert.IsType <CreatedAtRouteResult>(response.Result);
        }
示例#12
0
        public async Task <ActionResult> Create(ClientCreateDto model)
        {
            var result = await _clientService.Create(model);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.ClientId },
                       result
                       ));
        }
        public async Task Should_Create_Update_Success()
        {
            var input = new ClientCreateDto
            {
                ClientId   = "test",
                ClientName = "test-name"
            };

            (await _clientAppService.CreateAsync(input)).ShouldNotBeNull();
        }
示例#14
0
        public ClientGetDto Create(ClientCreateDto clientToCreate)
        {
            byte[] salt = passwordService.GenerateSalt(32);
            byte[] hash = passwordService.GenerateHash(clientToCreate.Password, salt, 12, 32);
            clientToCreate.Password = null;
            Client       client = clientRepository.Create(clientToCreate, hash, salt);
            ClientGetDto output;

            clientMap.Map(client, out output);
            return(output);
        }
示例#15
0
        public async Task Create(ClientCreateDto model)
        {
            var entry = new Client
            {
                Name = model.Name
            };

            await _context.AddAsync(entry);

            await _context.SaveChangesAsync();
        }
        public ClientDto Create(ClientCreateDto model)
        {
            var entry = _mapper.Map <Client>(model);

            entry.SignedUpAt = DateTime.Now;

            _context.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <ClientDto>(GetById(entry.ClientId)));
        }
示例#17
0
        public async Task <ClientDto> CreateAsync(ClientCreateDto model)
        {
            var entity = new Client {
                Name = model.Name
            };
            await _context.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(_mapper.Map <ClientDto>(entity));
        }
示例#18
0
        public async Task <ActionResult <ClientReadDto> > CreateClient(ClientCreateDto clientCreateDto)
        {
            if (await _tenantsRepo.GetTenantById(clientCreateDto.TenantId) == null)
            {
                return(BadRequest(new { Error = "Invalid Tenant Id" }));
            }

            var clientToAdd = _mapper.Map <Client>(clientCreateDto);
            var newClient   = await _clientsRepo.CreateClient(clientToAdd);

            return(CreatedAtRoute(nameof(GetClientById), new { newClient.ClientId }, _mapper.Map <ClientReadDto>(newClient)));
        }
示例#19
0
        public void CreateClient_InvalidObjectPassed_ReturnsBadRequestResult()
        {
            var testItem = new ClientCreateDto()
            {
                Firstname = "Fernando", Lastname = "", Document = ""
            };

            controller.ModelState.AddModelError("Lastname", "Required");
            var response = controller.CreateClient(testItem);

            Assert.IsType <BadRequestResult>(response.Result);
        }
示例#20
0
        public async Task <int> Create(ClientCreateDto dto, string userId)
        {
            var createdClient = _mapper.Map <ClientDbEntity>(dto);

            createdClient.CreatedBy = userId;

            await _dbContext.Clients.AddAsync(createdClient);

            await _dbContext.SaveChangesAsync();

            return(createdClient.Id);
        }
示例#21
0
        public ClientDto Create(ClientCreateDto model)
        {
            var entry = new Client
            {
                Name         = model.Name,
                ClientNumber = model.ClientNumber,
                Country_Id   = model.Country_Id
            };

            _context.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <ClientDto>(entry));
        }
        public async Task <IActionResult> CreateClient(string id, ClientCreateDto client)
        {
            if (ModelState.IsValid)
            {
                bool success = await _clientService.CreateClientAsync(client);

                if (success)
                {
                    return(RedirectToAction("Index", "User"));
                }
            }
            //TODO need validation
            return(View(client));
        }
示例#23
0
        public void CreateClient_ValidObjectPassed_ReturnsResponseHasCreatedItem()
        {
            var testItem = new ClientCreateDto()
            {
                Firstname = "Fernando", Lastname = "Zabala", Document = "A1242"
            };

            var response = controller.CreateClient(testItem).Result as CreatedAtRouteResult;
            var item     = response.Value as ClientReadDto;

            Assert.IsType <ClientReadDto>(item);
            Assert.Equal(testItem.Firstname, item.Firstname);
            Assert.Equal(testItem.Lastname, item.Lastname);
            Assert.Equal(testItem.Document, item.Document);
        }
示例#24
0
        public async Task <IActionResult> CreateClient([FromBody] ClientCreateDto client)
        {
            if (client == null)
            {
                _logger.LogError("Client object sent from client is null");
                return(BadRequest("Client object is null"));
            }
            var clientEntity = _mapper.Map <Client>(client);

            await _service.CreateClient(clientEntity);

            var createdClient = _mapper.Map <ClientReadDto>(clientEntity);

            return(CreatedAtRoute("ClientById", new { id = clientEntity.ClientId }, clientEntity));
        }
示例#25
0
        public async Task <IActionResult> RegisterClient(ClientCreateDto clientCreateDto)
        {
            Client client = mapper.Map <Client>(clientCreateDto);

            if (client.CountryId == 0)
            {
                await countryService.Create(client.Country);

                client.CountryId = client.Country.Id;
            }
            client.Country = null;

            await clientService.Create(client);

            return(NoContent());
        }
示例#26
0
        public ActionResult <ClientReadDto> CreateClient(ClientCreateDto clientCreateDto)
        {
            if (clientCreateDto.Firstname.Equals("") || clientCreateDto.Lastname.Equals("") || clientCreateDto.Document.Equals(""))
            {
                return(BadRequest());
            }

            var clientEntity = mapper.Map <Client>(clientCreateDto);

            repository.CreateClient(clientEntity);
            repository.SaveChanges();

            var clientReadDto = mapper.Map <ClientReadDto>(clientEntity);

            return(CreatedAtRoute(nameof(GetClientById), new { Id = clientReadDto.Id }, clientReadDto));
        }
示例#27
0
        public async Task <ClientDto> Create(ClientCreateDto model)
        {
            var result = new Client
            {
                Name      = model.Name,
                SurNames  = model.SurNames,
                Telephone = model.Telephone,
                Address   = model.Address,
                Notes     = model.Notes,
                CountryId = model.CountryId
            };
            await _context.AddAsync(result);

            await _context.SaveChangesAsync();

            return(_mapper.Map <ClientDto>(result));
        }
示例#28
0
        public void Map_MapsClientCreateDtoToClient()
        {
            ClientCreateDto clientCreateDto = new ClientCreateDto
            {
                Name     = "Test",
                Password = "******"
            };

            Client client;

            ClientMap clientMap = new ClientMap();

            clientMap.Map(clientCreateDto, out client);

            Assert.Equal("Test", client.Name);
            Assert.Equal(0, client.Id);
        }
示例#29
0
        public IActionResult Create(long customerId, [FromBody] ClientCreateDto clientCreateDto)
        {
            bool uowStatus = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();
                clientCreateDto.CustomerId = customerId;
                Client client = _clientCreateAssembler.toEntity(clientCreateDto);
                _clientRepository.Create(client);
                _unitOfWork.Commit(uowStatus);
                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("client Created!")));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto("Internal Server Error")));
            }
        }
        public async Task Create(ClientCreateDto model)
        {
            int quantityUsers = _context.Users.Count();

            var user = new Client
            {
                UserId   = quantityUsers + 1,
                Email    = model.Email,
                UserName = model.Email,
                Name     = model.Name
            };

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

            await _userManager.AddToRoleAsync(user, RoleHelper.CLIENT);

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo registrar el usuario.");
            }
        }