snu-quiqcl / wlm-server

Server for controlling and monitoring High Finesse wavelength meter
1 stars 0 forks source link

Handle sign in/out #15

Closed BECATRUE closed 6 days ago

BECATRUE commented 6 days ago

This resolves #4.

I implemented three APIs.

One can test these features using the code below.

import requests

BASE_URL = 'http://localhost:8000'

with requests.Session() as session:
    data = {'username': 'jaehun', 'password': 'OOOO'}
    response = session.post(BASE_URL + '/user/signin/', data=data)
    print(response.status_code)  # 200

    csrf_token = session.cookies.get('csrftoken')
    headers = {'X-CSRFToken': csrf_token}

    response = session.get(BASE_URL + '/user/me/', headers=headers)
    print(response.json())
    # {'id': 3, 'username': 'jaehun', 'password': 'OOOO', 'team': {'id': 1, 'name': 'blade'}}
    # 'password' is hashed.

    response = session.post(BASE_URL + '/user/signout/', headers=headers)
    print(response.status_code)  # 200