Example #1
0
 public static bool HasValidSubscription(this UserServiceResponse serviceStackAccount)
 {
     return
         (serviceStackAccount != null &&
          serviceStackAccount.Expiry != null &&
          serviceStackAccount.Expiry > DateTime.Now);
 }
 private void UpdateDiscourseAccountStatus(DiscourseUser discourseUser, UserServiceResponse existingCustomerSubscription, int throttleRequestTime = 2000)
 {
     try
     {
         Thread.Sleep(throttleRequestTime);
         if ((discourseUser.NeedsApproval() || discourseUser.IsSuspended()) && existingCustomerSubscription.HasValidSubscription())
         {
             Log.Info("Approving user '{0}'.".Fmt(discourseUser.Email));
             ApproveUser(discourseUser);
         }
     }
     catch (Exception e)
     {
         Log.Error("Failed to update Discourse for user '{0}'. - {1}".Fmt(discourseUser.Email, e.Message));
     }
 }
Example #3
0
        public UserServiceResponse GetUserSubscription(string emailAddress)
        {
            UserServiceResponse result = null;

            try
            {
                result = serviceUrl.Fmt(emailAddress).GetJsonFromUrl()
                         .FromJson <UserServiceResponse>();
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw;
            }

            return(result);
        }
        private UserServiceResponse GetDiscourseUserServiceStackSubscription(DiscourseUser discourseUser)
        {
            UserServiceResponse existingCustomerSubscription = null;

            try
            {
                existingCustomerSubscription = ServiceStackAccountClient.GetUserSubscription(discourseUser.Email);
            }
            catch (Exception e)
            {
                Log.Error("Failed to check user {0} subscription. Retrying... - {1}".Fmt(discourseUser.Username, e.Message));
                try
                {
                    existingCustomerSubscription = ServiceStackAccountClient.GetUserSubscription(discourseUser.Email);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to check user {0} subscription. Cancelling sync. - {1}".Fmt(discourseUser.Username, ex.Message));
                    return(existingCustomerSubscription);
                }
            }
            return(existingCustomerSubscription);
        }