A little exercise with React: fun for a few days :)
View the Project on GitHub pdonorio/proof-frontend-assignment
We have APIs on a Flask backend to register and verify a user into our mongo database.
We need to create frontend views with React.js
:
A view for a logged user to see his profile (which is where the user is redirected if successfull at step 1).
Here’s the list of API calls to interact in the above request
If a user is registered and activated they can login by calling:
# default account already existing after startup up of the framework
USER=user@nomail.org
PASSWORD=test
http POST localhost:8080/auth/login email=$USER password=$PASSWORD
HTTP/1.0 200 OK
"data": {
"token": "..."
}
To request a registration the flow requires the following
USER=beta@tester.me
PASSWORD=verylongpassword
NAME=test
SURNAME=beta
http POST localhost:8080/auth/profile \
email=$USER password=$PASSWORD name=$NAME surname=$SURNAME
This call above tries to send an email to the specified address. NOTE: this is not an authenticated request.
To make it work you have to ensure you have the SMTP
configuration in place
(explained in another section of the documentation).
If you now login with the current profile which is not activated, you end up with:
http POST localhost:8080/auth/login email=test@test.test password=testtest
HTTP/1.0 401 UNAUTHORIZED
"Sorry, this account is not active"
So let’s activate the account. You received the token via email (or can find it in the logs of the backend server)
http PUT localhost:8080/auth/profile/activate/$ACTIVATION_TOKEN
HTTP/1.0 200 OK
[...]
"Response": {
"data": "Account activated",
"errors": null
}
}
If you try to activate with a wrong token:
http PUT localhost:8080/auth/profile/activate/blabla
HTTP/1.0 400 BAD REQUEST
"Invalid activation token"