Example #1
0
        public override async Task <ClientDto> CreateAsync(ClientDto model)
        {
            PasswordHasher passwordHasher = new PasswordHasher();

            Client client = DtoToEntity(model);

            client.ClientId = UnitHelper.GenerateNewGuid();

            client.SecretKey = UnitHelper.GenerateNewGuid();

            client.Secret = passwordHasher.HashPassword(client.SecretKey);

            client.MongoName = (REST_MONGO_NAME + "_" + client.ClientId);

            client.MongoConnectionString = (MONGO_PREFIX + model.MongoConnectionString + "/" + client.MongoName);

            _repository.Add(client);

            await _unitOfWork.CommitAsync();

            var username = model.Email;

            var password = UnitHelper.RandomString("");

            var userProfile = await _userProfileService.CreateAsync(username, password, PulseIdentityRole.ClientAdmin);

            await _userProfileService.AddClientUserAsync(userProfile.UserId, client.ClientId, client.SecretKey);

            return(EntityToDto(client));
        }
        public async Task <IEnumerable <string> > GenerateLicenseKeyAsync(string clientId, int number)
        {
            IList <string> licenses = new List <string>();

            for (int i = 0; i < number; i++)
            {
                var username = UnitHelper.RandomString();
                var password = UnitHelper.RandomString();

                var userProfile = await _userProfileService.CreateAsync(username, password, PulseIdentityRole.Kiosk);

                await _userProfileService.AddClientUserAsync(userProfile.UserId, clientId);

                string passwordHash = password.GeneratePasswordHash();

                var encryptionUserDto = await CreateEncryptionUserAsync(username, password, passwordHash, userProfile.UserId);

                _repository.Add(new KioskSecurity
                {
                    MachineId        = userProfile.UserId,
                    LicenseKey       = userProfile.UserId,
                    IsActive         = false,
                    EncryptionUserId = encryptionUserDto.Id,
                    ClientId         = clientId,
                });

                await _unitOfWork.CommitAsync();

                licenses.Add(userProfile.UserId);
            }

            return(licenses);
        }