src/Model/ApiToken.php
public static function retrieveOrCreateToken(Model $user, $ipAddress)
    {
        try {
            $token = self::findFirst(new AndGroup([
                new Equals("AuthenticatedUserID", $user->UniqueIdentifier),
                new Equals("IpAddress", $ipAddress),
                new GreaterThan("Expires", "now", true)
            ]));
            $token->Expires = ApiSettings::singleton()->tokenExpiration;
            $token->save();
        } catch (RecordNotFoundException $ex) {
            $token = self::createToken($user, $ipAddress);
        }

        return $token;
    }
public static function retrieveOrCreateToken(Model $user, $ipAddress)
    {
        try {
            $token = self::findFirst(new AndGroup([
                new Equals("AuthenticatedUserID", $user->UniqueIdentifier),
                new Equals("IpAddress", $ipAddress),
                new GreaterThan("Expires", "now", true)
            ]));
            $token->Expires = ApiSettings::singleton()->tokenExpiration;
            $token->save();
        } catch (RecordNotFoundException $ex) {
            $token = self::createToken($user, $ipAddress);
        }

        return $token;
    }
public static function retrieveOrCreateToken ( Model $ user , $ ipAddress ) { try { $ token = self :: findFirst ( new AndGroup ( [ new Equals ( "AuthenticatedUserID" , $ user -> UniqueIdentifier ) , new Equals ( "IpAddress" , $ ipAddress ) , new GreaterThan ( "Expires" , "now" , true ) ] ) ) ; $ token -> Expires = ApiSettings :: singleton ( ) -> tokenExpiration ; $ token -> save ( ) ; } catch ( RecordNotFoundException $ ex ) { $ token = self :: createToken ( $ user , $ ipAddress ) ; } return $ token ; }
Looks up an existing valid token for the user at the specified IP address. If none is found, it
creates a new one.

@param Model $user
@param string $ipAddress Usually the current HTTP requester's IP, retrieved from $_SERVER[REMOTE_ADDR]
@return ApiToken
Looks up an existing valid token for the user at the specified IP address . If none is found it creates a new one .