https://github.com/TownbyHelio/user-system-backend
- SQLite 3
- NodeJS
- Express
API, panel web server and database in one application. I tried to keep it as simple as possible and do everything my own way.
It includes:
- User registration
- Email confirmation (OBS: it does not actually send you an email, so you will have to manually check the
email_confirmations
table on the database in order to know the confirmation code) - Password and email changes (OBS: codes are stored in
password_changes
table) - Friendships among users
- Friend requests
- Simple authentication (cookie)
-
Clone the repository
-
Run
npm install
-
Run
npm start
3.1. The port is 1001
localhost:1001/panel
- Panel where you can send requests
localhost:1001/api/...
- API endpoints (for example: localhost:1001/api/getUser
)
-
The database is automatically created inside
db/
asmain.db
when you run the program, along with the schemas inschemas.json
-
CTRL + C
closes the server
The response is always a json object containing a success
boolean property (very self-describing). In case the code does not succeed, it will return an errorCode
(number) and errorMessage
(string), both describing the error. The possible error codes for each endpoint can be found below within their respective sections.
W.I.P.
Click me
Params (exclusive, in can set only one of them in your request):
name
: stringid
: number
{
//guaranteed:
"success": boolean,
//if (!success) {
"errorCode": number,
"errorMessage": string,
//}
//if (success) {
"found": boolean,
//if (found) {
"id": number,
"username": string,
"description": string,
"emailConfirmed": boolean
//}
//}
}
1000 - One, and only one of the arguments must be defined 1001 - Wrong param type 1010 - Error trying to get user
Request: .../api/getUser/?name=helio
Success Response:
{
"success": true,
"found": true,
"id": 1,
"username": "helio",
"description": "my password is not 'verystrongpassword123'",
"emailConfirmed": false
}
Error Response:
{
"success": false,
"errorCode": 1010,
"errorMessage": "An error occurred when trying to get user from the database"
}
Click me
Body:
{
"username": string,
"password": string,
"email": string
}
{
//guaranteed:
"success": boolean,
//if (!success) {
"errorCode": number,
"errorMessage": string,
//}
//if (success) {
"id": number,
"cookie": string,
//}
}
1000 - Invalid argument type 'username' 1001 - Invalid argument type 'password' 1002 - Invalid argument type 'email'
1010 - Invalid username length 1011 - Invalid username characters
1012 - Invalid password length 1013 - Invalid password characters
1014 - Invalid email
1015 - Error creating user 1016 - Error trying to find user 1017 - Error creating confirmation
1018 - Error checking for unique username 1019 - Username is taken
1020 - Error checking for unique email 1021 - Email is taken
Request:
{
"username": "helio",
"email": "helio@gmail.com",
"password": "verystrongpassword123"
}
Success Response:
{
"success": true,
"id": 1,
"cookie": "53YpouBTWwjkiry9DM0ckgncfAniTGsSpvML7zcOL5TJL6pa5LPJan6fPtX6uay37fL9HoqHe3NfRUxgOpWaGe9fxK6FGl8hzGO7qN59CrFwdqQI9dFXxns5n0l8tuS3"
}
Error Response:
{
"success": false,
"errorCode": 1014,
"errorMessage": "Invalid email"
}