Trongate Docs
switch to dark modeswitch to dark mode
More Useful Features

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

Just To Let You Know
If a valid token is not found on the user's device then the _attempt_get_valid_token() method will return a boolean with a value of false.

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'
$token = $this->trongate_tokens->_attempt_get_valid_token(1);

Just To Let You Know
The code above assumes that the user level of 'admin' is stored on the 'trongate_user_levels' table, with an id of 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.  


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:

screenshot from PHPMyAdmin, showing trongate_user_levels

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'
$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
​$token = $this->trongate_tokens->_attempt_get_valid_token();


If you have a question or a comment relating to anything you've see here, please goto the Help Bar.