HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/CMS/App_Code/CMSModules/Licenses/LicenseNewControlExtender.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using CMS;
using CMS.Base;
using CMS.EventLog;
using CMS.ExtendedControls;
using CMS.FormControls;
using CMS.Helpers;
using CMS.LicenseProvider;
using CMS.Membership;


[assembly: RegisterCustomClass("LicenseNewControlExtender", typeof(LicenseNewControlExtender))]

/// <summary>
/// License new page extender.
/// </summary>
public class LicenseNewControlExtender : ControlExtender<UIForm>
{
    public override void OnInit()
    {
        Control.OnAfterValidate += Control_OnAfterValidate;
    }


    private void Control_OnAfterValidate(object sender, EventArgs e)
    {
        try
        {
            string licenseKey = ValidationHelper.GetString(Control.GetFieldValue("LicenseKey"), String.Empty).Trim();
            LicenseKeyInfo lk = new LicenseKeyInfo();
            lk.LoadLicense(licenseKey, "");

            switch (lk.ValidationResult)
            {
                case LicenseValidationEnum.Valid:
                    using (new CMSActionContext { AllowLicenseRedirect = false })
                    {
                        UserInfoProvider.ClearLicenseValues();
                        Functions.ClearHashtables();
                    }
                    return;

                case LicenseValidationEnum.Expired:
                    Control.ValidationErrorMessage = ResHelper.GetString("Licenses_License_New.LicenseNotValid.Expired");
                    break;

                case LicenseValidationEnum.Invalid:
                    Control.ValidationErrorMessage = ResHelper.GetString("Licenses_License_New.LicenseNotValid.Invalid");
                    break;

                case LicenseValidationEnum.NotAvailable:
                    Control.ValidationErrorMessage = ResHelper.GetString("Licenses_License_New.LicenseNotValid.NotAvailable");
                    break;

                case LicenseValidationEnum.WrongFormat:
                    Control.ValidationErrorMessage = ResHelper.GetString("Licenses_License_New.LicenseNotValid.WrongFormat");
                    break;
            }

            Control.StopProcessing = true;
            Control.ShowValidationErrorMessage = true;
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("License", "NEW", ex);
            Control.ValidationErrorMessage = ResHelper.GetString("general.saveerror");
        }
    }
}