From ceeb30fd4f444ed369950c32d1e2e6ab5eaf160d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 29 Mar 2021 11:16:56 +0200 Subject: [PATCH] adapt to anon login --- app/config/collections.php | 2 +- app/controllers/api/account.php | 6 +++--- src/Appwrite/Utopia/Response/Model/Session.php | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 5d6c2d6491..d023cae514 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -334,7 +334,7 @@ $collections = [ 'key' => 'providerUid', 'type' => Database::SYSTEM_VAR_TYPE_TEXT, 'default' => '', - 'required' => true, + 'required' => false, 'array' => false, ], [ diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 20043177b0..b2f382c895 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -650,10 +650,10 @@ App::post('/v1/account/sessions/anonymous') $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $session = new Document(array_merge( [ - '$collection' => Database::SYSTEM_COLLECTION_TOKENS, + '$collection' => Database::SYSTEM_COLLECTION_SESSIONS, '$permissions' => ['read' => ['user:' . $user['$id']], 'write' => ['user:' . $user['$id']]], 'userId' => $user->getId(), - 'type' => Auth::TOKEN_TYPE_LOGIN, + 'provider' => Auth::SESSION_PROVIDER_ANONYMOUS, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expiry, 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -665,7 +665,7 @@ App::post('/v1/account/sessions/anonymous') $detector->getDevice() )); - $user->setAttribute('tokens', $session, Document::SET_TYPE_APPEND); + $user->setAttribute('sessions', $session, Document::SET_TYPE_APPEND); Authorization::setRole('user:'.$user->getId()); diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index 7db7fdee36..d79d6cddc5 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -31,20 +31,20 @@ class Session extends Model ->addRule('provider', [ 'type' => self::TYPE_STRING, 'description' => 'Session Provider.', - 'default' => 0, - 'example' => 1592981250, + 'default' => '', + 'example' => 'email', ]) ->addRule('providerUid', [ 'type' => self::TYPE_STRING, 'description' => 'Session Provider User ID.', - 'default' => 0, - 'example' => 1592981250, + 'default' => '', + 'example' => 'user@example.com', ]) ->addRule('providerToken', [ 'type' => self::TYPE_STRING, 'description' => 'Session Provider Token.', - 'default' => 0, - 'example' => 1592981250, + 'default' => '', + 'example' => '1592981250', ]) ->addRule('ip', [ 'type' => self::TYPE_STRING,