public async Task CreateItem(SystemUserAuthenticateModel model)
        {
            model = await Validate(model);

            var systemUser = new SystemAuthenticateUser(model);

            systemUser.Password = _hashingService.EncryptString(model.Password);
            await _systemUsersManager.CreateItemAsync(systemUser);
        }
Beispiel #2
0
        public async Task CreateItem(AdminAuthenticateUserModel model)
        {
            model = await Validate(model);

            var adminUser = new AdminAuthenticateUser(model);

            adminUser.Password = _hashingService.EncryptString(model.Password);
            await _adminUsersManager.CreateItemAsync(adminUser);
        }
Beispiel #3
0
        public IActionResult Encrypt(string text)
        {
            try
            {
                string encryptedText = _hashingService.EncryptString(text);

                responseModels.Add("Encrypted text", encryptedText);
                var response = new ApiResponse(HttpStatusCode.OK, "Cypher text decrypted successfully.", responseModels);
                return(Ok(new { response }));
            }
            catch (Exception exception)
            {
                var response = new ApiResponse(HttpStatusCode.BadRequest, "Cypher decrypt NOT successful.", exception, null);
                return(BadRequest(new { response }));
            }
        }
        /// <summary>
        /// Creates multiple items in the System Users container.
        /// </summary>
        /// <param name="model">A SystemResetModel object.</param>
        /// <returns></returns>
        private async Task createContainerUsers(SystemResetModel model)
        {
            if (model.Users == null)
            {
                return;
            }

            foreach (SystemUserAuthenticateModel systemAuthenticationUserModel in model.Users)
            {
                //  Validate and populate lookup items.
                systemAuthenticationUserModel.EmailAddresses = await _systemEmailAddressService.Validate(systemAuthenticationUserModel.EmailAddresses);

                systemAuthenticationUserModel.PhoneNumbers = await _systemPhoneNumberService.Validate(systemAuthenticationUserModel.PhoneNumbers);

                //  Encrypt password.
                systemAuthenticationUserModel.Password = _hashingService.EncryptString(systemAuthenticationUserModel.Password);

                //  Persist item.
                await _systemUserService.CreateItem(systemAuthenticationUserModel);
            }
        }
        public async Task <CustomerModel> Create(CustomerModel model)
        {
            model = await Validate(model);

            model.AdminMoniker   = model.AdminMoniker.ToUpper();
            model.TenantMonikers = new List <string>()
            {
                model.AdminMoniker
            };

            //  Create customer entity
            CustomerEntity customerEntity = new CustomerEntity(model);

            //  Create customer item in system database.
            customerEntity = await _customersManager.CreateItemAsync(customerEntity);

            //  Create customer admin database.
            DatabaseResponse databaseResponse = await _adminService.CreateDatabase();

            if (databaseResponse.StatusCode != HttpStatusCode.Created)
            {
                throw new SystemDatabaseNotCreatedException();
            }

            //  Clone 'LookupItems' container and clone items from system database.
            var containerResponse = await _adminService.CreateContainer("LookupItems", "/canonicalName");

            if (containerResponse.StatusCode != HttpStatusCode.Created)
            {
                throw new AdminContainerNotCreatedException("LookupItems");
            }

            var systemLookupItemModels = await _systemLookupItemService.GetItems();

            var systemLookupItems = SystemLookupItem.Construct(systemLookupItemModels);

            foreach (SystemLookupItem systemLookupItem in systemLookupItems)
            {
                if (systemLookupItem.CloneToAdminDatabase)
                {
                    var adminLookupItemModel = new AdminLookupItemModel(systemLookupItem);
                    await _adminLookupItemsService.CreateItem(adminLookupItemModel);
                }
            }

            //  Create 'Users' container and clone items from system database.
            containerResponse = await _adminService.CreateContainer("Users", "/username");

            if (containerResponse.StatusCode != HttpStatusCode.Created)
            {
                throw new AdminContainerNotCreatedException("Users");
            }

            var systemAuthenticateUsers = await _systemUserService.GetItems();

            foreach (SystemAuthenticateUser systemAuthenticateUser in systemAuthenticateUsers)
            {
                if (systemAuthenticateUser.CloneToAdminDatabase)
                {
                    AdminAuthenticateUserModel adminAuthenticateUserModel = new AdminAuthenticateUserModel(systemAuthenticateUser);
                    await _adminUsersService.CreateItem(adminAuthenticateUserModel);
                }
            }

            //  Create customer 'admin' user.
            foreach (AdminAuthenticateUserModel adminUserModel in model.Users)
            {
                adminUserModel.NameFirst = adminUserModel.NameFirst.Replace("{moniker}", model.AdminMoniker.ToUpper());
                adminUserModel.Username  = adminUserModel.Username.Replace("{moniker}", model.AdminMoniker.ToLower());
                adminUserModel.DisplayAs = adminUserModel.DisplayAs.Replace("{moniker}", model.AdminMoniker.ToUpper());
                adminUserModel.EmailAddresses.ForEach(x => x.Address = x.Address.Replace("{moniker}", model.AdminMoniker.ToLower()));
                //for (int i = 0; i < adminUserModel.Roles.Count; i++) adminUserModel.Roles[i] = adminUserModel.Roles[i].Replace("{moniker}", model.AdminMoniker.ToUpper());

                var randomWord = await Helpers.GetRandomWordFromWordsApi();

                var joPassword = JObject.Parse(randomWord)["word"];
                adminUserModel.Password       = _hashingService.EncryptString(joPassword.ToString());
                adminUserModel.EmailAddresses = await _adminEmailAddressService.Validate(adminUserModel.EmailAddresses);

                adminUserModel.PhoneNumbers = await _adminPhoneNumberService.Validate(adminUserModel.PhoneNumbers);

                await _adminUsersService.CreateItem(adminUserModel);
            }

            //  Create Tenants container.
            containerResponse = await _adminService.CreateContainer("Tenants", "/moniker");

            if (containerResponse.StatusCode != HttpStatusCode.Created)
            {
                throw new AdminContainerNotCreatedException("Tenants");
            }

            model = new CustomerModel(customerEntity);

            return(model);
        }
 private string encryptString(string pass)
 {
     return(service.EncryptString(pass));
 }