public function getTokenForUser(User $user, int $validForSeconds = null, array $additionalData = []): string
    {
        $tokenData = [
            'user_id' => $user->id,
            'generated' => time(),
            'validForSeconds' => $validForSeconds,
            'additionalData' => $additionalData,
        ];
        $tokenDataString = serialize($tokenData);
        $encrypted = Security::encrypt($tokenDataString, Configure::read('Security.cryptKey'));

        return base64_encode($encrypted);
    }
public function getTokenForUser(User $user, int $validForSeconds = null, array $additionalData = []): string
    {
        $tokenData = [
            'user_id' => $user->id,
            'generated' => time(),
            'validForSeconds' => $validForSeconds,
            'additionalData' => $additionalData,
        ];
        $tokenDataString = serialize($tokenData);
        $encrypted = Security::encrypt($tokenDataString, Configure::read('Security.cryptKey'));

        return base64_encode($encrypted);
    }
public function getTokenForUser ( User $ user , int $ validForSeconds = null , array $ additionalData = [ ] ) : string { $ tokenData = [ 'user_id' => $ user -> id , 'generated' => time ( ) , 'validForSeconds' => $ validForSeconds , 'additionalData' => $ additionalData , ] ; $ tokenDataString = serialize ( $ tokenData ) ; $ encrypted = Security :: encrypt ( $ tokenDataString , Configure :: read ( 'Security.cryptKey' ) ) ; return base64_encode ( $ encrypted ) ; }
Generates a serialized, encrypted and base64-encoded for identifying a user,
usually for using it in an URL

@param \App\Model\Entity\User $user The user Entity
@param int $validForSeconds how long the token should be valid
@param array $additionalData Optional additional data for storage in the encrypted token
@return string
Generates a serialized encrypted and base64 - encoded for identifying a user usually for using it in an URL