Beispiel #1
0
        public ShopConnectorConnectionRecord InsertConnection(ConnectionModel model)
        {
            var utcNow = DateTime.UtcNow;
            ShopConnectorConnectionRecord connection = null;

            if (model.IsForExport)
            {
                var    hmac = new HmacAuthentication();
                string publicKey, secretKey;

                for (var i = 0; i < 9999; ++i)
                {
                    if (hmac.CreateKeys(out publicKey, out secretKey) && !_connectionRepository.TableUntracked.Any(x => x.PublicKey == publicKey))
                    {
                        connection = new ShopConnectorConnectionRecord
                        {
                            IsActive    = true,
                            IsForExport = model.IsForExport,
                            Url         = model.Url,
                            PublicKey   = publicKey,
                            SecretKey   = secretKey,
                            LimitedToManufacturerIds = string.Join(",", model.LimitedToManufacturerIds ?? new int[0]),
                            LimitedToStoreIds        = string.Join(",", model.LimitedToStoreIds ?? new int[0]),
                            CreatedOnUtc             = utcNow,
                            UpdatedOnUtc             = utcNow
                        };
                        break;
                    }
                }
            }
            else
            {
                connection = new ShopConnectorConnectionRecord
                {
                    IsActive    = true,
                    IsForExport = model.IsForExport,
                    Url         = model.Url,
                    PublicKey   = model.PublicKey,
                    SecretKey   = model.SecretKey,
                    LimitedToManufacturerIds = string.Join(",", model.LimitedToManufacturerIds ?? new int[0]),
                    LimitedToStoreIds        = string.Join(",", model.LimitedToStoreIds ?? new int[0]),
                    CreatedOnUtc             = utcNow,
                    UpdatedOnUtc             = utcNow
                };
            }

            if (connection != null)
            {
                _connectionRepository.Insert(connection);
                ConnectionCache.Remove();
            }

            return(connection);
        }
        public virtual bool CreateKeys(User user)
        {
            if (user != null)
            {
                var    hmac = new HmacAuthentication();
                string key1, key2;

                for (int i = 0; i < 9999; ++i)
                {
                    if (hmac.CreateKeys(out key1, out key2) && !_userRepository.GetAll().Any(x => x.PublicKey.ToLower().Equals(key1.ToLower())))
                    {
                        user.PublicKey = key1;
                        user.SecretKey = key2;
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        public bool CreateKeys(int customerId)
        {
            if (customerId != 0)
            {
                var    hmac = new HmacAuthentication();
                var    userData = WebApiCachingUserData.Data();
                string key1, key2;

                for (int i = 0; i < 9999; ++i)
                {
                    if (hmac.CreateKeys(out key1, out key2) && !userData.Exists(x => x.PublicKey.IsCaseInsensitiveEqual(key1)))
                    {
                        var apiUser = new WebApiUserCacheData
                        {
                            CustomerId = customerId,
                            PublicKey  = key1,
                            SecretKey  = key2,
                            Enabled    = true
                        };

                        RemoveKeys(customerId);

                        var attribute = new GenericAttribute
                        {
                            EntityId = customerId,
                            KeyGroup = "Customer",
                            Key      = WebApiCachingUserData.Key,
                            Value    = apiUser.ToString()
                        };

                        _genericAttributeService.InsertAttribute(attribute);

                        WebApiCachingUserData.Remove();
                        return(true);
                    }
                }
            }
            return(false);
        }