示例#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 = LicenseChecker.IsLicensablePlugin(descriptor);
            if (!isLicensable)
                return HttpNotFound();

            if (model.Licenses != null)
            {
                foreach (var item in model.Licenses)
                {
                    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 = LicenseChecker.IsLicensablePlugin(descriptor, out singleLicenseForAllStores);

            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);
                }
            }

            if (singleLicenseForAllStores)
            {
                var licenseModel = new LicensePluginModel.LicenseModel();
                var license = LicenseChecker.GetLicense(systemName, "");

                if (license != null)
                    licenseModel.LicenseKey = license.TruncatedLicenseKey;

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

                    var license = LicenseChecker.GetLicense(systemName, store.Url);

                    if (license != null)
                        licenseModel.LicenseKey = license.TruncatedLicenseKey;

                    model.Licenses.Add(licenseModel);
                }
            }

            return View(model);
        }