trOnGAtE

More Useful Features
Attempt To Fetch A Token From A User
The trongate_tokens module contains the _attempt_get_valid_token() method for situations where you may wish to fetch a valid token from an end user. This method allows you to:
- fetch a valid token from the end user, where the end user belongs to a particular user level
- fetch a valid token from the end user, where the end user belongs to a set of pre-defined user levels
- fetch any valid token from the end user
Confirm If The User Belongs To A Particular User Level
You can confirm if the user belongs to a particular user level by passing an integer into the _attempt_get_valid_token() method. The integer that gets passed into the method should match the value stored on the 'id' column, on trongate_user_levels, for the user level that you wish to check for.
For example:
//confirm if user has a user level of 'admin'
$this->module('trongate_tokens');
$token = $this->trongate_tokens->_attempt_get_valid_token(1);
Confirm If The User Belongs To A Set Of Pre-Defined User Levels
You can pass an array of integers into the _attempt_get_valid_token() method to confirm that the user belongs to a set of pre-defined user levels.
FOR EXAMPLE
Let's assume that you'd like to confirm if an end user has a role (i.e., a user level) of either 'admin' or 'member'.
Let's further assume that the trongate_user_levels table contains the following data:

As you can see, the user level of 'admin' has an 'id' of 1 and 'member' has an 'id' of 2. We create an array made up of those two values and immediately pass our array into the _attempt_get_valid_token() method, like so:
//confirm if user has role of 'admin' or 'member'
$this->module('trongate_tokens');
$token = $this->trongate_tokens->_attempt_get_valid_token([1,2]);
Confirm If The User Has Any Valid Token
If we invoke the _attempt_get_valid_token() method without passing in any arguments, then Trongate will attempt to fetch and return a valid token from the user, irrespective of the user's role (i.e., the user level). For example,
​
​//confirm if user has any valid token
​$this->module('trongate_tokens');
​$token = $this->trongate_tokens->_attempt_get_valid_token();
​
HELP & SUPPORT
If you have a question or a comment relating to anything you've see here, please goto the Help Bar.