Skip to content

The backend server for the Squeegee Whiteboard application

License

Notifications You must be signed in to change notification settings

squeegee-whiteboard/server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Squeegee Whiteboard - Server

The server for the Squeegee Whiteboard application

Build Status

Usage

To start the server: npm start.

To lint the code: npm run lint.

To start the dev server (auto reload on code change): npm run dev.

Debug Messages

To insert debug messages, use the debug package: https://github.com/visionmedia/debug. Essentially:

const Debug = require('debug');

const debug = Debug('your:tag:here');

// ...

debug('debug message');

And then run the dev server (or regular server, using npm start) with: DEBUG=your:tag:here npm run dev to get only debug messages from that specific tag. Alternatively, to get debug messages from all tags use: DEBUG=* npm run dev. For more info, see the above link to the debug project on github.

REST API Documentation

Currently uses port 3000 by default.

Normal Endpoints

  • POST - /auth/register
  • POST - /auth/login

JWT Endpoints

  • PATCH - /changeUser/username

  • PATCH - /changeUser/email

  • PATCH - /changeUser/password

  • GET - /changeUser/info

  • POST - /changeBoard/create

  • PATCH - /changeBoard/name

  • PUT - /changeBoard/addMember

  • DELETE - /changeBoard/delete

  • GET - /boardInfo/owned

  • GET - /boardInfo/member

  • GET - /boardInfo/isMember

Normal Endpoints

These endpoints don't require an auth token, but will return one. It should be stored in the browser's local storage. Example using axios (common js request library):

axios.post('http://localhost:3000/loginUser', {
        email,
        password,
    }).then((response) => {
        localStorage.setItem('JWT', response.data.token);
    });

POST - /auth/register

Registers a new user. Email must be unique. Returns your auth token on success.

Input

POST request to the endpoint url.

Ex: localhost:3000/auth/register

JSON object in the form:

{
	"email": <email>,
	"password": <password in plaintext>,
	"username": <username>
}

Ex:

{
	"email": "joel@squeegee.xyz",
	"password": "hunter2",
	"username": "cool joe"
}

Output

JSON object in the form:

{
    "success": true,
    "token": <json auth token>,
    "message": <success message>
}

Ex:

{
    "success": true,
    "token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv",
    "message": "User successfully created."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Email is already in use."
}

POST - /auth/login

Logs the user in. Returns your auth token on success.

Input

POST request to the endpoint url.

Ex: localhost:3000/auth/login

JSON object in the form:

{
	"email": <email>,
	"password": <password in plaintext>
}

Ex:

{
	"email": "joel@squeegee.xyz",
	"password": "hunter2"
}

Output

JSON object in the form:

{
    "success": true,
    "token": <json auth token>,
    "message": <success message>
}

Ex:

{
    "success": true,
    "token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv",
    "message": "User logged in."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Incorrect email or password."
}

JWT Endpoints

These endpoints require the auth token acquired through register or login. Auth token is included in the request headers. Ex: Authorization JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv

Example using axios (common js request library):

const authToken = localStorage.getItem('JWT');
await axios.get('http://localhost:3000/updateUsername', {
          params: {
            username: newUsername,
          },
          headers: { Authorization: `JWT ${authToken}` },
        });

PATCH - /changeUser/username

Changes the user's name. Requires a user's auth token in the message header.

Input

PATCH request to the endpoint url.

Ex: localhost:3000/changeUser/username

JSON object in the form:

{
	"username": <username you want to change to>
}

Ex:

{
	"username": "joel"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "Username updated."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Invalid auth token."
}

PATCH - /changeUser/email

Changes the user's email. Requires a user's auth token in the message header.

Input

PATCH request to the endpoint url.

Ex: localhost:3000/changeUser/email

JSON object in the form:

{
	"email": <email you want to change to>
}

Ex:

{
	"email": "joel@squeegee.xyz"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "Email updated."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Invalid auth token."
}

PATCH - /changeUser/password

Changes the user's password. Requires a user's auth token in the message header.

Input

PATCH request to the endpoint url.

Ex: localhost:3000/changeUser/password

JSON object in the form:

{
    "oldPassword": <password changing from>,
    "newPassword": <password changing to>
}

Ex:

{
	"oldPassword": "hunter2",
    "newPassword": "letmein"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "Password updated."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to update password."
}

GET - /changeUser/info

Gets the logged in user's username and email address. Does not get password, since passwords aren't even stored as plaintext.

Input

GET request to the endpoint url.

Ex: `localhost:3000/changeUser/info'

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>,
    "username": <user's username>,
    "email": <user's email>
}

Ex:

{
    "success": true,
    "message": "Successfully retrieved user info.",
    "username": "JollyJoel",
    "email": "joel@email.com"
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to retrieve owned boards"
}

POST - /changeBoard/create

Creates a board and adds the creating user as an owner.

Input

POST request to the endpoint url.

Ex: localhost:3000/changeBoard/create

JSON object in the form:

{
    "name": <board name>
}

Ex:

{
	"name": "ex name"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>,
    "board_id": <base64 board identifier string>,
    "board_preview": <svg text>
}

Ex:

{
    "success": true,
    "message": "Board created.",
    "board_id": "dhohohi32y948234",
    "board_preview": "... svg text ...",
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to create board."
}

PATCH - /changeBoard/name

Creates a board and adds the creating user as an owner.

Any member or admin can change a board name.

Input

PATCH request to the endpoint url.

Ex: localhost:3000/changeBoard/name

JSON object in the form:

{
    "name": <board name>,
    "board_id": <base64 board identifier string>
}

Ex:

{
    "name": "ex name",
    "board_id": "askjdhqiuhiuqoij3920"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "Board name updated."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to update name."
}

PUT - /changeBoard/addMember

Creates a board and adds the creating user as an owner.

Input

PUT request to the endpoint url.

Ex: `localhost:3000/changeBoard/addMember'

JSON object in the form:

{
    "board_id": <base64 board identifier string>

Ex:

{
	"board_id": "iuhd929823h9dh2"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "User added to board."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to add user to board."
}

POST - /changeBoard/delete

Creates a board and adds the creating user as an owner.

Any member or admin can delete a board.

Input

POST request to the endpoint url.

Ex: `localhost:3000/changeBoard/delete'

JSON object in the form:

{
    "board_id": <base64 board identifier string>
}

Ex:

{
	"board_id": "kjshf2982u39823u"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>
}

Ex:

{
    "success": true,
    "message": "Board deleted."
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to delete board."
}

GET - /boardInfo/owned

Gets the list of boards owned by the user. If user owns no board, return empty list.

Input

GET request to the endpoint url.

Ex: `localhost:3000/boardInfo/owned'

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>,
    "boards": [
        {
            "board_id": <base64 board identifier string>,
            "board_name": <board name>,
            "board_preview": <svg text>,
        },
        ...
    ]
}

Ex:

{
    "success": true,
    "message": "Successfully retrieved boards.",
    "boards": [
        {
            "board_id": "sdaksjka2y92723h2dhui2d",
            "board_name": "AwesomeBoard",
            "board_preview": "... svg text ...",
        },
        {
            "board_id": "dasdajdajkk28832",
            "board_name": "secondBoard",
            "board_preview": "... svg text ...",
        }
    ]
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to retrieve owned boards"
}

GET - /boardInfo/member

Gets the list of boards the user is a member of. If user is not a member of any boards, return empty list.

Admin can see all boards.

Input

GET request to the endpoint url.

Ex: `localhost:3000/boardInfo/member'

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>,
    "boards": [
        {
            "board_id": <base64 board identifier string>,
            "board_name": <board name>,
            "board_preview": <svg text>,
        },
        ...
    ]
}

Ex:

{
    "success": true,
    "message": "Successfully retrieved boards.",
    "boards": [
       {
            "board_id": "asdsadaaggasdasd",
            "board_name": "AwesomeBoard",
            "board_preview": "... svg text ...",
        },
        {
            "board_id": "safaf4f28282",
            "board_name": "secondBoard",
            "board_preview": "... svg text ...",
        },
        {
            "board_id": "ferf343364436346",
            "board_name": "Someone Else's Board",
            "board_preview": "... svg text ...",
        }
    ]
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Failed to retrieve member boards"
}

GET - /boardInfo/isMember

Returns if a user is a member of a board or not.

Admin is considered member of all boards

Input

GET request to the endpoint url.

Ex: localhost:3000/boardInfo/isMember

JSON object in the form:

{
    "board_id": <base64 board identifier string>
}

Ex:

{
    "board_id": "hd292898h239hd2"
}

Output

JSON object in the form:

{
    "success": true,
    "message": <success message>,
    "is_member": <true/false>
}

Ex:

{
    "success": true,
    "message": "Member found."
    "is_member": true
}

On Error

JSON object in the form:

{
    "success": false,
    "message": <failure message>
}
{
    "success": false,
    "message": "Could not access API server."
}

About

The backend server for the Squeegee Whiteboard application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published