Jump to content

Change User Role (or any other field) via API after a specific time


Recommended Posts

Posted

Hey folks,

does anybody have an idea how I can change field values after a set time via API? I know how to change values of fields, but have no idea how could create a automatic change. 

Example: I have a user created via Formbuilder or any other API method. This user has the Role Gold and after 30 days it should change to silver. Since Roles are just fields like any other field there must be a cool solution for this.

Appreciate any ideas :)

Posted

Sorry, nothing specific but there are several possibilities including autoload module, a cron job and maybe the new cool and shiny Iftrunner...Gotta go, but sure you'll get better answers :-)

Posted

When you change the user to Gold put the current date or expiration date in another field. Setup a really simple module to hook on login. Then it can test the date field and role to see if it's an expired Gold user and change their role. Maybe even redirect them.

$this->addHookAfter('Session::loginSuccess', $this, 'hookAfterLogin');

and

    public function hookAfterLogin ($event) {
        $user =  $event->arguments[0];
        foreach($user->roles as $role){

            do things...
        }

    }
 

Edit: More here http://wiki.processwire.com/index.php/Module_Creation#How_to_attach_hooks_with_a_module

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...