From ae6999aee31a7db2fface293104aa4e2eaf6cd0d Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 15 Feb 2020 20:34:16 +0200 Subject: [PATCH] Updated session ID --- app/controllers/api/account.php | 12 ++++++------ app/views/console/account/index.phtml | 6 +++--- public/dist/scripts/app-all.js | 8 ++++---- public/dist/scripts/app-dep.js | 6 +++--- public/dist/scripts/app.js | 2 +- public/scripts/dependencies/appwrite.js | 6 +++--- tests/e2e/Services/Account/AccountBase.php | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c38c973d4..5d4258e09 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -848,7 +848,7 @@ $utopia->delete('/v1/account') } ); -$utopia->delete('/v1/account/sessions/:sessionUid') +$utopia->delete('/v1/account/sessions/:sessionId') ->desc('Delete Account Session') ->label('scope', 'account') ->label('webhook', 'account.sessions.delete') @@ -857,17 +857,17 @@ $utopia->delete('/v1/account/sessions/:sessionUid') ->label('sdk.method', 'deleteSession') ->label('sdk.description', '/docs/references/account/delete-session.md') ->label('abuse-limit', 100) - ->param('sessionUid', null, function () { return new UID(); }, 'Session unique ID. Use the string \'current\' to delete the current device session.') + ->param('sessionId', null, function () { return new UID(); }, 'Session unique ID. Use the string \'current\' to delete the current device session.') ->action( - function ($sessionUid) use ($response, $request, $user, $projectDB, $webhook, $audit) { - $sessionUid = ($sessionUid === 'current') + function ($sessionId) use ($response, $request, $user, $projectDB, $webhook, $audit) { + $sessionId = ($sessionId === 'current') ? Auth::tokenVerify($user->getAttribute('tokens'), Auth::TOKEN_TYPE_LOGIN, Auth::$secret) - : $sessionUid; + : $sessionId; $tokens = $user->getAttribute('tokens', []); foreach ($tokens as $token) { /* @var $token Document */ - if (($sessionUid == $token->getUid()) && Auth::TOKEN_TYPE_LOGIN == $token->getAttribute('type')) { + if (($sessionId == $token->getUid()) && Auth::TOKEN_TYPE_LOGIN == $token->getAttribute('type')) { if (!$projectDB->deleteDocument($token->getUid())) { throw new Exception('Failed to remove token from DB', 500); } diff --git a/app/views/console/account/index.phtml b/app/views/console/account/index.phtml index a394216c2..99e74c54c 100644 --- a/app/views/console/account/index.phtml +++ b/app/views/console/account/index.phtml @@ -130,7 +130,7 @@ data-failure-param-alert-text="Logout failed" data-failure-param-alert-classname="error"> - + @@ -213,7 +213,7 @@ data-failure-param-alert-text="Logout from Session Failed" data-failure-param-alert-classname="error"> - + @@ -234,7 +234,7 @@ data-failure="alert" data-failure-param-alert-text="Logout from Session Failed" data-failure-param-alert-classname="error"> - + diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index 1af6b2d2c..35c843a04 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -50,13 +50,13 @@ return http.put(path,{'content-type':'application/json',},payload);},getSessions if(password===undefined){throw new Error('Missing required parameter: "password"');} let path='/account/sessions';let payload={};if(email){payload['email']=email;} if(password){payload['password']=password;} -return http.post(path,{'content-type':'application/json',},payload);},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload);},deleteCurrentSession:function(){let path='/account/sessions/current';let payload={};return http.delete(path,{'content-type':'application/json',},payload);},createOAuthSession:function(provider,success,failure){if(provider===undefined){throw new Error('Missing required parameter: "provider"');} +return http.post(path,{'content-type':'application/json',},payload);},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload);},createOAuthSession:function(provider,success,failure){if(provider===undefined){throw new Error('Missing required parameter: "provider"');} if(success===undefined){throw new Error('Missing required parameter: "success"');} if(failure===undefined){throw new Error('Missing required parameter: "failure"');} let path='/account/sessions/oauth/{provider}'.replace(new RegExp('{provider}','g'),provider);let payload={};if(success){payload['success']=success;} if(failure){payload['failure']=failure;} -return http.get(path,{'content-type':'application/json',},payload);},deleteSession:function(sessionUid){if(sessionUid===undefined){throw new Error('Missing required parameter: "id"');} -let path='/account/sessions/{sessionUid}'.replace(new RegExp('{sessionUid}','g'),sessionUid);let payload={};return http.delete(path,{'content-type':'application/json',},payload);},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"');} +return http.get(path,{'content-type':'application/json',},payload);},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "id"');} +let path='/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}','g'),sessionId);let payload={};return http.delete(path,{'content-type':'application/json',},payload);},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"');} let path='/account/verification';let payload={};if(url){payload['url']=url;} return http.post(path,{'content-type':'application/json',},payload);},updateVerification:function(userId,secret,passwordB){if(userId===undefined){throw new Error('Missing required parameter: "userId"');} if(secret===undefined){throw new Error('Missing required parameter: "secret"');} @@ -2397,7 +2397,7 @@ children[prop]=template.cloneNode(true);element.appendChild(children[prop]);(ind container.set('$index',originalIndex,true,false);container.set('$prefix',originalPrefix,true,false);container.set('$as',originalAs,true,false);element.dispatchEvent(new Event('looped'));};let template=(element.children.length===1)?element.children[0]:window.document.createElement('li');echo();container.bind(element,expr+'.length',echo);let path=(expr+'.length').split('.');while(path.length){container.bind(element,path.join('.'),echo);path.pop();}}});window.ls.container.get('view').add({selector:'data-ls-template',template:false,repeat:true,controller:function(element,view,http,expression,document){let template=expression.parse(element.getAttribute('data-ls-template'));let type=element.getAttribute('data-type')||'url';element.innerHTML='';if('script'===type){let inlineTemplate=document.getElementById(template);if(inlineTemplate&&inlineTemplate.innerHTML){element.innerHTML=inlineTemplate.innerHTML;element.dispatchEvent(new CustomEvent('template-loaded',{bubbles:true,cancelable:false}));} else{element.innerHTML='Missing template "'+template+'"';} return;} -http.get(template).then(function(element){return function(data){element.innerHTML=data;view.render(element);element.dispatchEvent(new CustomEvent('template-loaded',{bubbles:true,cancelable:false}));}}(element),function(){throw new Error('Failed loading template');});}});window.ls.error=function(){return function(error){console.error("ERROR-APP",error);};};window.addEventListener("error",function(event){console.error("ERROR-EVENT:",event.error.message,event.error.stack);});document.addEventListener("account.deleteSession",function(){window.location="/auth/signin";});document.addEventListener("account.create",function(){let container=window.ls.container;let form=container.get('serviceForm');let sdk=container.get('console');let promise=sdk.account.createSession(form.email,form.password);promise.then(function(){window.location='/console';},function(error){window.location='/auth/signup?failure=1';});});(function(window){"use strict";window.ls.container.set('alerts',function(window){return{list:[],ids:0,counter:0,max:5,add:function(message,time){var scope=this;message.id=scope.ids++;scope.counter++;scope.list.unshift(message);if(scope.counter>scope.max){scope.list.pop();scope.counter--;} +http.get(template).then(function(element){return function(data){element.innerHTML=data;view.render(element);element.dispatchEvent(new CustomEvent('template-loaded',{bubbles:true,cancelable:false}));}}(element),function(){throw new Error('Failed loading template');});}});window.ls.error=function(){return function(error){console.error("ERROR-APP",error);};};window.addEventListener("error",function(event){console.error("ERROR-EVENT:",event.error.message,event.error.stack);});document.addEventListener("account.deleteSession",function(){window.location="/auth/signin";});document.addEventListener("account.create",function(){let container=window.ls.container;let form=container.get('serviceForm');let sdk=container.get('console');let promise=sdk.account.createSession(form.email,form.password);container.set("serviceForm",formData,true,true);promise.then(function(){window.location='/console';},function(error){window.location='/auth/signup?failure=1';});});(function(window){"use strict";window.ls.container.set('alerts',function(window){return{list:[],ids:0,counter:0,max:5,add:function(message,time){var scope=this;message.id=scope.ids++;scope.counter++;scope.list.unshift(message);if(scope.counter>scope.max){scope.list.pop();scope.counter--;} if(time>0){window.setTimeout(function(message){return function(){scope.remove(message.id)}}(message),time);} return message.id;},remove:function(id){let scope=this;for(let index=0;index';} return;} -http.get(template).then(function(element){return function(data){element.innerHTML=data;view.render(element);element.dispatchEvent(new CustomEvent('template-loaded',{bubbles:true,cancelable:false}));}}(element),function(){throw new Error('Failed loading template');});}});window.ls.error=function(){return function(error){console.error("ERROR-APP",error);};};window.addEventListener("error",function(event){console.error("ERROR-EVENT:",event.error.message,event.error.stack);});document.addEventListener("account.deleteSession",function(){window.location="/auth/signin";});document.addEventListener("account.create",function(){let container=window.ls.container;let form=container.get('serviceForm');let sdk=container.get('console');let promise=sdk.account.createSession(form.email,form.password);promise.then(function(){window.location='/console';},function(error){window.location='/auth/signup?failure=1';});});(function(window){"use strict";window.ls.container.set('alerts',function(window){return{list:[],ids:0,counter:0,max:5,add:function(message,time){var scope=this;message.id=scope.ids++;scope.counter++;scope.list.unshift(message);if(scope.counter>scope.max){scope.list.pop();scope.counter--;} +http.get(template).then(function(element){return function(data){element.innerHTML=data;view.render(element);element.dispatchEvent(new CustomEvent('template-loaded',{bubbles:true,cancelable:false}));}}(element),function(){throw new Error('Failed loading template');});}});window.ls.error=function(){return function(error){console.error("ERROR-APP",error);};};window.addEventListener("error",function(event){console.error("ERROR-EVENT:",event.error.message,event.error.stack);});document.addEventListener("account.deleteSession",function(){window.location="/auth/signin";});document.addEventListener("account.create",function(){let container=window.ls.container;let form=container.get('serviceForm');let sdk=container.get('console');let promise=sdk.account.createSession(form.email,form.password);container.set("serviceForm",formData,true,true);promise.then(function(){window.location='/console';},function(error){window.location='/auth/signup?failure=1';});});(function(window){"use strict";window.ls.container.set('alerts',function(window){return{list:[],ids:0,counter:0,max:5,add:function(message,time){var scope=this;message.id=scope.ids++;scope.counter++;scope.list.unshift(message);if(scope.counter>scope.max){scope.list.pop();scope.counter--;} if(time>0){window.setTimeout(function(message){return function(){scope.remove(message.id)}}(message),time);} return message.id;},remove:function(id){let scope=this;for(let index=0;indexassertEquals($response['headers']['status-code'], 201); - $sessionUid = $response['body']['$uid']; + $sessionId = $response['body']['$uid']; $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_'.$this->getProject()['$uid']]; /** @@ -121,7 +121,7 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 400); return array_merge($data, [ - 'sessionUid' => $sessionUid, + 'sessionId' => $sessionId, 'session' => $session, ]); } @@ -219,7 +219,7 @@ trait AccountBase public function testGetAccountSessions($data):array { $session = (isset($data['session'])) ? $data['session'] : ''; - $sessionUid = (isset($data['sessionUid'])) ? $data['sessionUid'] : ''; + $sessionId = (isset($data['sessionId'])) ? $data['sessionId'] : ''; /** * Test for SUCCESS @@ -235,7 +235,7 @@ trait AccountBase $this->assertIsArray($response['body']); $this->assertNotEmpty($response['body']); $this->assertCount(1, $response['body']); - $this->assertEquals($sessionUid, $response['body'][0]['$uid']); + $this->assertEquals($sessionId, $response['body'][0]['$uid']); $this->assertIsArray($response['body'][0]['OS']); $this->assertEquals('Windows', $response['body'][0]['OS']['name']);