Ejemplo n.º 1
0
        public override void Uninstall()
        {
            WebApiCaching.Remove(WebApiControllingCacheData.Key);
            WebApiCaching.Remove(WebApiUserCacheData.Key);

            _settingService.DeleteSetting <WebApiSettings>();

            _permissionService.UninstallPermissions(new WebApiPermissionProvider());

            _localizationService.DeleteLocaleStringResources(this.PluginDescriptor.ResourceRootKey);
            _localizationService.DeleteLocaleStringResources("Plugins.FriendlyName.Api.WebApi", false);

            base.Uninstall();
        }
Ejemplo n.º 2
0
        public ActionResult SaveGeneralSettings(WebApiConfigModel model)
        {
            if (!HasPermission(false) || !ModelState.IsValid)
            {
                return(Configure());
            }

            model.Copy(_webApiSettings, false);
            _settingService.SaveSetting(_webApiSettings);

            WebApiCaching.Remove(WebApiControllingCacheData.Key);

            return(Configure());
        }
Ejemplo n.º 3
0
        public override void Install()
        {
            _permissionService.InstallPermissions(new WebApiPermissionProvider());

            var apiSettings = new WebApiSettings()
            {
                LogUnauthorized   = true,
                ValidMinutePeriod = WebApiGlobal.DefaultTimePeriodMinutes
            };

            _settingService.SaveSetting <WebApiSettings>(apiSettings);

            _localizationService.ImportPluginResourcesFromXml(this.PluginDescriptor);

            base.Install();

            WebApiCaching.Remove(WebApiControllingCacheData.Key);
            WebApiCaching.Remove(WebApiUserCacheData.Key);
        }
Ejemplo n.º 4
0
        public void RemoveKeys(int customerId)
        {
            if (customerId != 0)
            {
                var data = (
                    from a in _genericAttributes.Table
                    where a.EntityId == customerId && a.KeyGroup == "Customer" && a.Key == WebApiUserCacheData.Key
                    select a).ToList();

                if (data.Count > 0)
                {
                    foreach (var itm in data)
                    {
                        _genericAttributeService.DeleteAttribute(itm);
                    }

                    WebApiCaching.Remove(WebApiUserCacheData.Key);
                }
            }
        }
Ejemplo n.º 5
0
        public bool CreateKeys(int customerId)
        {
            if (customerId != 0)
            {
                var    hmac = new HmacAuthentication();
                var    userData = WebApiCaching.UserData();
                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      = WebApiUserCacheData.Key,
                            Value    = apiUser.ToString()
                        };

                        _genericAttributeService.InsertAttribute(attribute);

                        WebApiCaching.Remove(WebApiUserCacheData.Key);
                        return(true);
                    }
                }
            }
            return(false);
        }