Public API for a society manager application

Matt Coles 1e5894c839 Update README.md to include API specification 9 år sedan
.gitignore b9234d83fd Update .gitignore 9 år sedan
LICENSE 0c6209f476 Add license and readme 10 år sedan
README.md 1e5894c839 Update README.md to include API specification 9 år sedan
index.js a093259817 Add login and register functions, allow using GET for testing purposes 9 år sedan
package.json 272fa26135 Initial Commit 10 år sedan

README.md

ip-project-server

Server for Integrated Project, powered by Express.js and Redis

To run, first start Redis:

redis-server

Then start the Express framework using:

node index.js

API

/hello/:name/

Returns "Hello :name!" or simply "Hello World!" if no name is present. :)

/register/

In order to register a new user account, a POST request should be sent, with the following data:

{
    "user": desired_username_here,
    "password": desired_password_here
}

The server will then respond with a JSON object that looks something like this:

{
    "registered": 1, // Value is 1 or 0 based on whether registration was
    successful
    "auth-key": $2a$10$.X9YrNyd2R7b2ycAumHn.ONiINs2bCkRDupugu6sjZkUkPmXSaSra, //
    Value is an authentication key to be used in API requests
    "error": 0 // Error code, if an error occured. 0 indicates no error.
}

The value of the error code will be 1 if the username already exists.

/login/

In order to log into an account, or essentially request a new authentication token, a POST request should be sent with the following data:

{
    "user": username_here,
    "password": password_here, // Optional field if auth-key is present
    "auth-key": auth_key_here // Optional field if password is present
}

Using the auth-key will reset and generate a new authentication key, whereas password will simply get the current auth-key. In either case the following data will be returned:

{
    "logged_in": 1, // Value is 1 or 0 whether or not the login was successful
    "auth-key": $2a$10$.X9YrNyd2R7b2ycAumHn.ONiINs2bCkRDupugu6sjZkUkPmXSaSra, //
    Only present if logged_in == 1, to be used in API requests
    "error": 0 // Error code, if an error occured. 0 indicates no error.
}

The error codes are as follows, 1 indicates the username could not be found, 2 indicates that the password is invalid and 3 indicates the provided authentication key was invalid.