-
Notifications
You must be signed in to change notification settings - Fork 194
Model Tokens
kip9 edited this page Feb 5, 2014
·
1 revision
Model | Extends | Table | Path |
---|---|---|---|
Tokens_Model | Plain_Model | tokens | /application/models/tokens_model.php |
$this->load->model('tokens_model', 'tokens');
Constant | Value | Description |
---|---|---|
DEFAULT_TOKEN_VALID_TIME_SECONDS | 86400 | Default token validity time in seconds |
TYPE_FORGOT_PASSWORD | FORGOT_PASSWORD | Constant defining token type for recovering forgot passwords |
Called automatically which in turn calls the parent constructor and sets the model $data_types
properties.
Used to create new records in the tokens table. Currently there is one type of tokens : FORGOT_PASSWORD
used to recover forgotten password by user.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$options | array | array() | Yes | An associative array that contains the column names and the values for the record to be created. Array keys are the column names for each value. |
$this->load->model('tokens_model', 'token');
$createdToken = $this->token->create(array(
'token_type' => Tokens_model::TYPE_FORGOT_PASSWORD,
'user_id' => $user->user_id
)
);
// If token was created
if (isset($createdToken->token_id)) {
// Good to go
}
Checks if given tokenValue exists and is still valid for use. Behaviour depends on argument passed:
- if it is string (tokenValue), then it runs check directly on database using queries,
- if argument is array, it assumes object was already retrieved from database and checks it's properties for validity (active flag and valid_until field)
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$tokenValue | string|object | Yes | Token value as a string or retrieved from database token object. |
$this->load->model('tokens_model', 'token');
if ($this->token->isValid('abcdefghijkl')) {
$this->data['token_valid'] = true;
}
Mark selected token as used in the database.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$tokenValue | string | Yes | Token value as a string. |
$this->load->model('tokens_model', 'token');
$token = 'ABCDEFGH';
if (! $this->token->useToken($token)) {
log_message('DEBUG', 'Failed to mark token ' . $token . ' as used in DB');
}```