-
Notifications
You must be signed in to change notification settings - Fork 0
Authentication
Dylan Havelock edited this page Feb 12, 2020
·
4 revisions
The following needs to be in the header of all HTTP requests:
To edit a user's attributes (e.g. target macros), perform the following request:
{
"Authorization": "Token <your user token>"
}In order to obtain a Token, you need to log in first. This is done using the following request:
// URL
/rest-auth/login/ (POST)
// Request
{
"username": <user email>,
"email": <user email>,
"password": <user password>
}
// Response
{
"key": <user token>, // will look something like this "490b7517f78c801f7cdbcd92beeff629d2ce7d4f"
}Note: for simplicity, the username and email will both be the user's email
To create a new user, perform the following request:// URL
/rest-auth/registration/ (POST)
// Request
{
"username": <user email>,
"password1": <password>,
"password2": <password>,
"email": <user email>
}
// Response
{
"key": <user token>, // will look something like this "490b7517f78c801f7cdbcd92beeff629d2ce7d4f"
}Note: for simplicity, the username and email will both be the user's email
To get a user's profile and attributes:// URL
/rest-auth/user/ (GET)
// Request
{}
// Response
{
"pk": 8,
"username": "dylan.havelock@mail.mcgill.ca",
"email": "dylan.havelock@mail.mcgill.ca",
"first_name": "Dylan",
"last_name": "Havelock",
"protein_target": "190",
"carb_target": "300",
"fat_target": "130"
}// URL
/rest-auth/user/ (PUT)
// Request
{
"username": "dylan.havelock@mail.mcgill.ca",
"protein_target": "190",
"carb_target": "300",
"fat_target": "130"
}
// Response
{
"pk": 8,
"username": "dylan.havelock@mail.mcgill.ca",
"email": "dylan.havelock@mail.mcgill.ca",
"first_name": "Dylan",
"last_name": "Havelock",
"protein_target": "190",
"carb_target": "300",
"fat_target": "130"
}Note: all 3 target macro fields must be present in the request