Back-end of HBTU Connect App
Install Docker and Docker Compose on your machine. And run the following command
- create a
.flaskenv
file in root directory. and add following content to it.
FLASK_APP=server
FLASK_ENV=development
- create a
.env
file in root directory. and add following content to it.
SECRET_KEY=<YOUR SECRET KEY>
JWT_SECRET_KEY=<YOU JWT SECRET KEY>
MONGO_URI=<YOUR MONGODB CONNECT URI STRING>
- Build the server container image in the docker host with all the requirements installed in it.
docker build . server
- Start the development server inside the docker container on the port 5000
docker run -it -p 5000:5000 -v $(pwd):/server server
- You can access the api at any of the mentioned address
- create a
.flaskenv
file in root directory. and add following content to it.
FLASK_APP=server
FLASK_ENV=development
- create a
.env
file in root directory. and add following content to it.
SECRET_KEY=<YOUR SECRET KEY>
JWT_SECRET_KEY=<YOU JWT SECRET KEY>
MONGO_URI=<YOUR MONGODB CONNECT URI STRING>
CORS origins are put under the /server/config.py in origins list
-
to install all the dependencies.
pip install -r requirements.txt
-
to run the app use the following command
flask run
/api/register
: to register an user./api/login
: for logging in a user./api/logout/access
: to revoke access token/api/logout/refresh
: to revoke refresh token/api/token/refresh
: use refresh token to get new access token
Request
{
"username": "test",
"email": "[email protected]",
"password": "password",
"rollNumber": "170000001"
"firstName": "test",
"lastName": "admin",
"phone": "9000000000",
"branch": "cse",
"year": "first",
"gender": "male"
}
Response
{
access_token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTQ4Mjk0NDcsIm5iZiI6MTU5NDgyOTQ0NywianRpIjoiYzAxZjIwZjctOGUwOS00YjMzLWI5YjEtYjEzZWUwNTgxNDAyIiwiZXhwIjoxNTk0OTE1ODQ3LCJpZGVudGl0eSI6IjE3MDEwNDA2NUBoYnR1LmFjLmluIiwiZnJlc2giOmZhbHNlLCJ0eXBlIjoiYWNjZXNzIn0.RtmztSPxoIyOex1Ozu3ins2wMuUZse-wlkONAK-jFN0"
msg:"User with username yv_official has been successfully created"
username:"yv_official"
refresh_token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTQ4Mjk0NDcsIm5iZiI6MTU5NDgyOTQ0NywianRpIjoiMTVkMzI1OTItOTQyZS00ZDViLWI5YzAtMzFlMTY3OTc5ODE4IiwiZXhwIjoxNTk3NDIxNDQ3LCJpZGVudGl0eSI6IjE3MDEwNDA2NUBoYnR1LmFjLmluIiwidHlwZSI6InJlZnJlc2gifQ.H1gZ0qGr6qeU6-7Wd24nZ3pJDINMG_mrl9yoMfz-04g"
}
Request
{
"username": "test",
"password": "password"
}
Response
{
access_token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTQ4Mjk0NDcsIm5iZiI6MTU5NDgyOTQ0NywianRpIjoiYzAxZjIwZjctOGUwOS00YjMzLWI5YjEtYjEzZWUwNTgxNDAyIiwiZXhwIjoxNTk0OTE1ODQ3LCJpZGVudGl0eSI6IjE3MDEwNDA2NUBoYnR1LmFjLmluIiwiZnJlc2giOmZhbHNlLCJ0eXBlIjoiYWNjZXNzIn0.RtmztSPxoIyOex1Ozu3ins2wMuUZse-wlkONAK-jFN0"
msg:"Logged in as test"
name:"test admin"
refresh_token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTQ4Mjk0NDcsIm5iZiI6MTU5NDgyOTQ0NywianRpIjoiMTVkMzI1OTItOTQyZS00ZDViLWI5YzAtMzFlMTY3OTc5ODE4IiwiZXhwIjoxNTk3NDIxNDQ3LCJpZGVudGl0eSI6IjE3MDEwNDA2NUBoYnR1LmFjLmluIiwidHlwZSI6InJlZnJlc2gifQ.H1gZ0qGr6qeU6-7Wd24nZ3pJDINMG_mrl9yoMfz-04g"
userId:"5f0b5f328bf03756503c7959"
username:"test"
}
Key will be Authorization
and
value will be Bearer <YOUR TOKEN>