aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-25 11:25:56 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-25 11:25:56 +0100
commit390f822a7257b03fe721f556b150b5c23a5aa0ae (patch)
tree87f00a61bf13cdf55e05afbd5cf4f02c1aa5569d /api
parenta58a34f4d312cfd392477631215821826db4fa3f (diff)
@auth_required in /social/accept endpoint
Diffstat (limited to 'api')
-rw-r--r--api/events.py3
-rw-r--r--api/social/friend_accept.py17
2 files changed, 6 insertions, 14 deletions
diff --git a/api/events.py b/api/events.py
index 8974666..c811be4 100644
--- a/api/events.py
+++ b/api/events.py
@@ -10,10 +10,13 @@ import time
def get_token(environ):
cookie = environ.get("HTTP_COOKIE")
if not cookie: return None
+
parsed = cookies.SimpleCookie()
parsed.load(cookie)
+
token = parsed.get("token")
if not token: return None
+
return token.value
@io.on("connect")
diff --git a/api/social/friend_accept.py b/api/social/friend_accept.py
index 8340274..cd11159 100644
--- a/api/social/friend_accept.py
+++ b/api/social/friend_accept.py
@@ -1,25 +1,14 @@
from flask import Blueprint, request
from db import cursor, connection
-from auth.login_token import token_login
+from social.create_relation import two_person_endpoint
from socket_io import io
import time
accept = Blueprint('accept', __name__)
@accept.route("/accept", methods = ['POST'])
-def route():
- data = request.get_json()
-
- user_1_id = data.get("id") or ""
- token = request.cookies.get("token") or ""
-
- if not token: return "", 401
- user_2_id = token_login(token) or ""
-
- if not user_1_id or \
- not user_2_id:
- return "", 403
-
+@two_person_endpoint
+def route(user_1_id, user_2_id):
cursor.execute("update social set type = \"friendship\" where user_1_id = ? and user_2_id = ?",
[user_1_id, user_2_id])
connection.commit()