Include user URI and session URI in GET /session/
This makes it so that we can log out by doing a DELETE on /session/ by URI.
This commit is contained in:
parent
1fbe9558bf
commit
ded63dc932
|
@ -3,6 +3,7 @@ import json
|
||||||
import flask
|
import flask
|
||||||
import sepiida.endpoints
|
import sepiida.endpoints
|
||||||
import sepiida.fields
|
import sepiida.fields
|
||||||
|
import sepiida.routing
|
||||||
|
|
||||||
import vanth.auth
|
import vanth.auth
|
||||||
import vanth.errors
|
import vanth.errors
|
||||||
|
@ -14,9 +15,10 @@ class Session(sepiida.endpoints.APIEndpoint):
|
||||||
ENDPOINT = '/session/'
|
ENDPOINT = '/session/'
|
||||||
SIGNATURE = sepiida.fields.JSONObject(s={
|
SIGNATURE = sepiida.fields.JSONObject(s={
|
||||||
'name' : sepiida.fields.String(methods=['GET']),
|
'name' : sepiida.fields.String(methods=['GET']),
|
||||||
'username' : sepiida.fields.String(),
|
|
||||||
'password' : sepiida.fields.String(methods=['POST']),
|
'password' : sepiida.fields.String(methods=['POST']),
|
||||||
'uri' : sepiida.fields.URI('session', methods=['GET'])
|
'uri' : sepiida.fields.URI('session', methods=['GET']),
|
||||||
|
'user' : sepiida.fields.URI('user', methods=['GET']),
|
||||||
|
'username' : sepiida.fields.String(),
|
||||||
})
|
})
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def post(payload):
|
def post(payload):
|
||||||
|
@ -28,10 +30,14 @@ class Session(sepiida.endpoints.APIEndpoint):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(uuid): # pylint: disable=unused-argument
|
def get(uuid): # pylint: disable=unused-argument
|
||||||
user = vanth.auth.current_user()
|
user = vanth.auth.current_user()
|
||||||
del user['password']
|
|
||||||
if not user:
|
if not user:
|
||||||
raise vanth.errors.ResourceDoesNotExist("You are not currently authenticated and therefore do not have a session")
|
raise vanth.errors.ResourceDoesNotExist("You are not currently authenticated and therefore do not have a session")
|
||||||
return user
|
return {
|
||||||
|
'name' : user['name'],
|
||||||
|
'uri' : sepiida.routing.uri('session', flask.session['uuid']),
|
||||||
|
'user' : user['uri'],
|
||||||
|
'username' : user['username'],
|
||||||
|
}
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
payload = self.get(None)
|
payload = self.get(None)
|
||||||
|
|
|
@ -45,6 +45,7 @@ def require_user():
|
||||||
)
|
)
|
||||||
|
|
||||||
flask.g.current_user = user[0]
|
flask.g.current_user = user[0]
|
||||||
|
flask.g.session = sepiida.routing.uri('session', flask.session['uuid'])
|
||||||
|
|
||||||
def current_user():
|
def current_user():
|
||||||
return getattr(flask.g, 'current_user', None)
|
return getattr(flask.g, 'current_user', None)
|
||||||
|
|
Loading…
Reference in New Issue