예제 #1
0
        public ActionResult LicensePlugin(string systemName, LicensePluginModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(HttpNotFound());
            }

            var isLicensable = IsLicensable(descriptor);

            if (!isLicensable)
            {
                return(HttpNotFound());
            }

            if (model.StoreLicenses != null)
            {
                foreach (var item in model.StoreLicenses)
                {
                    var result = LicenseChecker.Activate(item.LicenseKey, descriptor.SystemName, item.StoreUrl);

                    if (result == null)
                    {
                        // do nothing, skiped
                    }
                    else if (result.Success)
                    {
                        NotifySuccess(T("Admin.Configuration.Plugins.LicenseActivated"));
                    }
                    else
                    {
                        if (result.IsFailureWarning)
                        {
                            NotifyWarning(result.ToString());
                        }
                        else
                        {
                            NotifyError(result.ToString());
                        }

                        return(RedirectToAction("List"));
                    }
                }
            }

            return(RedirectToAction("List"));
        }
예제 #2
0
        public ActionResult LicensePlugin(string systemName, string licenseKey)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedPartialView());
            }

            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            bool singleLicenseForAllStores = false;
            bool isLicensable = false;

            if (!isLicensable)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var stores = _services.StoreService.GetAllStores();
            var model  = new LicensePluginModel
            {
                SystemName = systemName,
                Licenses   = new List <LicensePluginModel.LicenseModel>()
            };

            // validate store url
            foreach (var store in stores)
            {
                if (!_services.StoreService.IsStoreDataValid(store))
                {
                    model.InvalidDataStoreId = store.Id;
                    return(View(model));
                }
            }

            return(View(model));
        }
        public ActionResult LicensePlugin(string systemName, string licenseKey)
        {
            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var singleLicenseForAllStores = false;
            var isLicensable = LicenseChecker.IsLicensablePlugin(descriptor, out singleLicenseForAllStores);

            if (!isLicensable)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var stores = Services.StoreService.GetAllStores();
            var model  = new LicensePluginModel
            {
                SystemName    = systemName,
                StoreLicenses = new List <LicensePluginModel.StoreLicenseModel>()
            };

            // Validate store url.
            foreach (var store in stores)
            {
                if (!Services.StoreService.IsStoreDataValid(store))
                {
                    model.InvalidDataStoreId = store.Id;
                    return(View(model));
                }
            }

            if (singleLicenseForAllStores)
            {
                var licenseModel = new LicensePluginModel.StoreLicenseModel();
                var license      = PrepareLicenseLabelModel(licenseModel.LicenseLabel, descriptor);
                if (license != null)
                {
                    licenseModel.LicenseKey = license.TruncatedLicenseKey;
                }

                model.StoreLicenses.Add(licenseModel);
            }
            else
            {
                foreach (var store in stores)
                {
                    var licenseModel = new LicensePluginModel.StoreLicenseModel
                    {
                        StoreId   = store.Id,
                        StoreName = store.Name,
                        StoreUrl  = store.Url
                    };

                    var license = PrepareLicenseLabelModel(licenseModel.LicenseLabel, descriptor, store.Url);
                    if (license != null)
                    {
                        licenseModel.LicenseKey = license.TruncatedLicenseKey;
                    }

                    model.StoreLicenses.Add(licenseModel);
                }
            }

            return(View(model));
        }