Public API for a society manager application

Matt Coles 1aa2e61ad2 Version bump 9 years ago
routes 469fa577a4 Implement API route for viewing a created society 9 years ago
utils e69ffbc87b Add routes for society creation and update slug for user operations 9 years ago
.gitignore bbf1e79460 Linting stuff 9 years ago
LICENSE 0c6209f476 Add license and readme 10 years ago
README.md dc08f6e55f Update README.md 9 years ago
index.js 8fcfaca431 Implement route for creating new societies 9 years ago
package.json 1aa2e61ad2 Version bump 9 years ago

README.md

ip-project-server

Server for Integrated Project, powered by Express.js and Redis, listens only on HTTPS now, currently using a self-signed cert, will have to play with trust authorities on the ionic side. Also at the moment server responds to ALL requests, cause it's easier to do testing with GET, will also set up unit tests in good time. Everything in the API documentation is working as described.

HTTPS Screenshot

Installation

Instructions are for OSX El Capitan at time of writing.

First install the Redis server:

brew install redis

Then clone this repository:

git clone https://github.com/Alpha-Atom/ip-project-server.git

And finally, install the dependencies

npm install

Running

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. Useful for checking if the server is running :)

/user/register/

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

{
    "user": "FooBar", // Desired username goes here
    "password": "hunter2" // Desired password goes 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.

/user/auth/

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": "FooBar", // Username goes here
    "password": "hunter2", // Password goes here
}

Using this will then generate a new authentication key, invalidating any existing authentication key for that account. Note that you do not need to use /auth/ after registering as a new auth key is already generated.

{
    "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 that the login request was malformed.

/society/create/

To create a new society, a POST request should be sent with the following data:

{
    "society": "FooBarSociety", // The name of the society to be created.
    "admins": ["FooBar", "BarFoo", "FarBoo"], // List of initial admins to be added, this list MUST include the user creating the society
    "description": "A description of the FooBarSociety society.",
    "auth": "$2a$10$.X9YrNyd2R7b2ycAumHn.ONiINs2bCkRDupugu6sjZkUkPmXSaSra"
}

If the society does not already exist, the new values will be added to the database and a response will be sent looking like this:

{
    "success": 1, // Indicates if a society was successfully created.
    "society": {
        "name": "FooBarSociety",
        "admins": ["FooBar", "BarFoo", "FarBoo"],
        "description": "A description of the FooBarSociety society.",
        "users": ["FooBar", "BarFoo", "FarBoo"] // At this point the users will simply be the admin list
    }, // An object representing the society
    "error": 0
}

The error codes are as follows, 1 indicates a malformed request, 2 indicates that a society with that name already exists, and 3 indicates that the user does not have authorisation to create that society. (Note that the admin list must contain the username that is creating it.)

/society/view/:society_name

To view a created society, :society_name, a GET request should be sent with no data. The response will then be formed as follows:

{
    "society": { // Society object containing information about the society
        "name": "FooBarSociety",
        "admins": ["FooBar", "BarFoo", "FarBoo"],
        "description": "A description of the FooBarSociety society.",
        "users": ["FooBar", "BarFoo", "FarBoo"]
    },
    "error": 0 // Error code if an error occured, 0 indicates no error.
}

The error codes are as follows, 1 indicates that the society does not exist.