Ejemplo n.º 1
0
        public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId,
                                   ILicensingService licenseService)
        {
            Version         = 2;
            LicenseKey      = org.LicenseKey;
            InstallationId  = installationId;
            Id              = org.Id;
            Name            = org.Name;
            BillingEmail    = org.BillingEmail;
            BusinessName    = org.BusinessName;
            Enabled         = org.Enabled;
            Plan            = org.Plan;
            PlanType        = org.PlanType;
            Seats           = org.Seats;
            MaxCollections  = org.MaxCollections;
            UseGroups       = org.UseGroups;
            UseDirectory    = org.UseDirectory;
            UseTotp         = org.UseTotp;
            MaxStorageGb    = org.MaxStorageGb;
            SelfHost        = org.SelfHost;
            UsersGetPremium = org.UsersGetPremium;
            Issued          = DateTime.UtcNow;

            if (billingInfo?.Subscription == null)
            {
                Expires = Refresh = Issued.AddDays(7);
                Trial   = true;
            }
            else if (billingInfo.Subscription.TrialEndDate.HasValue &&
                     billingInfo.Subscription.TrialEndDate.Value > DateTime.UtcNow)
            {
                Expires = Refresh = billingInfo.Subscription.TrialEndDate.Value;
                Trial   = true;
            }
            else
            {
                if (org.ExpirationDate.HasValue && org.ExpirationDate.Value < DateTime.UtcNow)
                {
                    // expired
                    Expires = Refresh = org.ExpirationDate.Value;
                }
                else if (billingInfo?.Subscription?.PeriodDuration != null &&
                         billingInfo.Subscription.PeriodDuration > TimeSpan.FromDays(180))
                {
                    Refresh = DateTime.UtcNow.AddDays(30);
                    Expires = billingInfo?.Subscription.PeriodEndDate.Value.AddDays(60);
                }
                else
                {
                    Expires = org.ExpirationDate.HasValue ? org.ExpirationDate.Value.AddMonths(11) : Issued.AddYears(1);
                    Refresh = DateTime.UtcNow - Expires > TimeSpan.FromDays(30) ? DateTime.UtcNow.AddDays(30) : Expires;
                }

                Trial = false;
            }

            Hash      = Convert.ToBase64String(ComputeHash());
            Signature = Convert.ToBase64String(licenseService.SignLicense(this));
        }
Ejemplo n.º 2
0
        public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId,
                                   ILicensingService licenseService, int?version = null)
        {
            Version          = version.GetValueOrDefault(7); // TODO: bump to version 8
            LicenseKey       = org.LicenseKey;
            InstallationId   = installationId;
            Id               = org.Id;
            Name             = org.Name;
            BillingEmail     = org.BillingEmail;
            BusinessName     = org.BusinessName;
            Enabled          = org.Enabled;
            Plan             = org.Plan;
            PlanType         = org.PlanType;
            Seats            = org.Seats;
            MaxCollections   = org.MaxCollections;
            UsePolicies      = org.UsePolicies;
            UseSso           = org.UseSso;
            UseGroups        = org.UseGroups;
            UseEvents        = org.UseEvents;
            UseDirectory     = org.UseDirectory;
            UseTotp          = org.UseTotp;
            Use2fa           = org.Use2fa;
            UseApi           = org.UseApi;
            UseResetPassword = org.UseResetPassword;
            MaxStorageGb     = org.MaxStorageGb;
            SelfHost         = org.SelfHost;
            UsersGetPremium  = org.UsersGetPremium;
            Issued           = DateTime.UtcNow;

            if (subscriptionInfo?.Subscription == null)
            {
                if (org.PlanType == PlanType.Custom && org.ExpirationDate.HasValue)
                {
                    Expires = Refresh = org.ExpirationDate.Value;
                    Trial   = false;
                }
                else
                {
                    Expires = Refresh = Issued.AddDays(7);
                    Trial   = true;
                }
            }
            else if (subscriptionInfo.Subscription.TrialEndDate.HasValue &&
                     subscriptionInfo.Subscription.TrialEndDate.Value > DateTime.UtcNow)
            {
                Expires = Refresh = subscriptionInfo.Subscription.TrialEndDate.Value;
                Trial   = true;
            }
            else
            {
                if (org.ExpirationDate.HasValue && org.ExpirationDate.Value < DateTime.UtcNow)
                {
                    // expired
                    Expires = Refresh = org.ExpirationDate.Value;
                }
                else if (subscriptionInfo?.Subscription?.PeriodDuration != null &&
                         subscriptionInfo.Subscription.PeriodDuration > TimeSpan.FromDays(180))
                {
                    Refresh = DateTime.UtcNow.AddDays(30);
                    Expires = subscriptionInfo?.Subscription.PeriodEndDate.Value.AddDays(60);
                }
                else
                {
                    Expires = org.ExpirationDate.HasValue ? org.ExpirationDate.Value.AddMonths(11) : Issued.AddYears(1);
                    Refresh = DateTime.UtcNow - Expires > TimeSpan.FromDays(30) ? DateTime.UtcNow.AddDays(30) : Expires;
                }

                Trial = false;
            }

            Hash      = Convert.ToBase64String(ComputeHash());
            Signature = Convert.ToBase64String(licenseService.SignLicense(this));
        }