Skip to content

Commit

Permalink
New api_token_is_used() function
Browse files Browse the repository at this point in the history
Move the logic to determine whether a token has been used from
api_tokens_page.php to the api_tokens API where it belongs.

The check against date_used has been changed from '=== 0' to '<= 1' to
reflect the change in schema definition in step 206.

Fixes #20472
  • Loading branch information
dregad committed Jun 11, 2016
1 parent 17c05b5 commit 1f678c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api_tokens_page.php
Expand Up @@ -87,7 +87,7 @@

$u_date_created = date( $t_date_format, $u_date_created );

if ( (int)$u_date_used === 0 ) {
if( api_token_is_used( $t_token ) ) {
$u_date_used = lang_get( 'api_token_never_used' );
} else {
$u_date_used = date( $t_date_format, $u_date_used );
Expand Down Expand Up @@ -115,4 +115,4 @@
<?php
}

html_page_bottom();
html_page_bottom();
10 changes: 10 additions & 0 deletions core/api_token_api.php
Expand Up @@ -152,6 +152,16 @@ function api_token_get_all( $p_user_id ) {
return $t_rows;
}

/**
* Determines whether the specified token has ever been used.
* @param array $p_token token to check
* @return bool True if used
* @access public
*/
function api_token_is_used( array $p_token ) {
return (int)$p_token['date_used'] <= 1;
}

/**
* Updates the last used timestamp for the api token.
*
Expand Down

0 comments on commit 1f678c2

Please sign in to comment.