aboutsummaryrefslogtreecommitdiff
path: root/api/social/friend_accept.py
blob: 83402742cc0e6d35ed797e0d27ea82423c07a10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Blueprint, request
from db import cursor, connection
from auth.login_token import token_login
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

    cursor.execute("update social set type = \"friendship\" where user_1_id = ? and user_2_id = ?",
            [user_1_id, user_2_id])
    connection.commit()

    io.emit("changedRelation", { "id": user_2_id }, room="user-"+user_1_id)
    io.emit("changedRelation", { "id": user_1_id }, room="user-"+user_2_id)

    return "", 200

dynamic_route = ["/social", accept]