Post Processing Hook to set Subscription Timeout?

Posted by Community Admin on 05-Aug-2018 20:33

Post Processing Hook to set Subscription Timeout?

All Replies

Posted by Community Admin on 07-Mar-2012 00:00

My Ecommerce application is to provide access to Private Sitefinity Blog Content for a period of a year, just like a magazine subscription.

I have Ecommerce working to grant the user the correct Role Permissions after their purchase but I need a method of having their Role expire 365 days from the date of purchase.

Posted by Community Admin on 12-Mar-2012 00:00

Hello Rick,

You can use any .Net based Job Scheduler for doing this task. For this example I am using Quartz.net . You can add it to your project by using Nuget (http://nuget.org/packages/Quartz/1.0.3 )

Then add this below code to your application. Please feel free to change the code below according to your needs.

using System;
using System.Linq;
using Quartz;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Abstractions;
 
namespace SitefinityWebApp
    public class HourlyJob : IJob
    
        public HourlyJob()
        
        
 
        public static void ScheduleJob(IScheduler sc)
        
            JobDetail job = new JobDetail("HourlyJob", "ExecuteTask", typeof(HourlyJob));
            sc.ScheduleJob(job, TriggerUtils.MakeHourlyTrigger("HourlyTrigger"));
            sc.Start();
        
 
        public void Execute(JobExecutionContext context)
        
            try
            
                Guid roleId = Guid.NewGuid(); //Id of the role you want to remove the user from.
                RoleManager roleManager = RoleManager.GetManager();
                UserManager userManager = UserManager.GetManager();
 
                var role = roleManager.GetRole(roleId);
                var users = userManager.GetUsers();
                foreach (var user in users)
                
                    if (roleManager.IsUserInRole(user.Id, role.Id) && MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(user.Id,role.Id))
                    
                        roleManager.RemoveUserFromRole(user.Id, role);
                    
                
            
            catch (Exception ex)
            
                Log.Write(ex);
            
        
 
        private bool MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(Guid userId, Guid roleId)
        
            //Add your custom logic here
            return true;
        
    

and in Global.asax in your Application_Start method, register the Job using the snippet below.
protected void Application_Start(object sender, EventArgs e)
    HourlyJob.ScheduleJob(new StdSchedulerFactory().GetScheduler());

Let us know if need further assistance.

Greetings,
Venkata Koppaka
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 28-Jun-2017 00:00

Is this still the best method of implementation of a membership with time limit? I am now using SF version 10.0

 

This thread is closed