src/Model/ApiToken.php
public static function validateToken($tokenString)
    {
        $tokens = ApiToken::find(new AndGroup(
            [
                new Equals("Token", $tokenString),
                new GreaterThan("Expires", "now", true)
            ]
        ));

        if (count($tokens) != 1) {
            throw new TokenInvalidException();
        }

        /** @var ApiToken $token */
        $token = $tokens[0];
        $settings = ApiSettings::singleton();
        if ($settings->extendTokenExpirationOnUse) {
            $token->Expires = $settings->tokenExpiration;
            $token->save();
        }

        return $token->AuthenticatedUser;
    }
public static function validateToken($tokenString)
    {
        $tokens = ApiToken::find(new AndGroup(
            [
                new Equals("Token", $tokenString),
                new GreaterThan("Expires", "now", true)
            ]
        ));

        if (count($tokens) != 1) {
            throw new TokenInvalidException();
        }

        /** @var ApiToken $token */
        $token = $tokens[0];
        $settings = ApiSettings::singleton();
        if ($settings->extendTokenExpirationOnUse) {
            $token->Expires = $settings->tokenExpiration;
            $token->save();
        }

        return $token->AuthenticatedUser;
    }
public static function validateToken ( $ tokenString ) { $ tokens = ApiToken :: find ( new AndGroup ( [ new Equals ( "Token" , $ tokenString ) , new GreaterThan ( "Expires" , "now" , true ) ] ) ) ; if ( count ( $ tokens ) != 1 ) { throw new TokenInvalidException ( ) ; } /** @var ApiToken $token */ $ token = $ tokens [ 0 ] ; $ settings = ApiSettings :: singleton ( ) ; if ( $ settings -> extendTokenExpirationOnUse ) { $ token -> Expires = $ settings -> tokenExpiration ; $ token -> save ( ) ; } return $ token -> AuthenticatedUser ; }
Validates a given token string is valid and returns the authenticated user model.

@param $tokenString
@return mixed
@throws \Rhubarb\Scaffolds\TokenBasedRestApi\Exceptions\TokenInvalidException Thrown if the token is invalid.
Validates a given token string is valid and returns the authenticated user model .