backend package

Submodules

backend.app module

app.py

Entrypoint for Bruintutor backend. All API endpoints start with /api

backend.app.create_app(test_config=None)[source]

Create and configure the app.

Parameters

test_config – configuration file for the app

backend.auth module

auth.py

Authentication API endpoints. All routes start with /api/auth All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.auth.getuid()[source]

GET get currently logged in user from session cookie

Notes

Implicitly sends session cookie with request

Returns

uid – Unique identification for user.

Return type

int

backend.auth.login()[source]

POST login as a user.

Parameters
  • email (str) –

  • password (str) –

Returns

uid – unique ID that idenfies this user.

Return type

int

Raises
  • InvalidEmail – Email does not exist in system.

  • InvalidPassword – Password does not exist in system.

Notes

This function also sets a encrypted session cookie which can only be decrypted server-side.

See also

backend.auth.getuid

getuid from session cookie.

backend.auth.logout()[source]

POST clear the current session cookie for a logged in user

Notes

Returns an empty session cookie, in addition to an empty payload.

backend.auth.register()[source]

POST Register a new user.

Parameters
  • firstName (str) –

  • lastName (str) –

  • email (str) –

  • password (str) –

  • isTutor (bool) –

Returns

uid – unique ID that idenfies this user.

Return type

int

Raises
  • BadRequest – Some part of the required parameters is missing.

  • UsersExists – User with the same email has already registered.

backend.class_list module

class_list.py

Endpoints for retrieving a list of all classes. All routes start with /api/classList All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.class_list.class_list()[source]

POST Get the class list for a given subject.

Parameters

subjectArea (str) –

Returns

uid – list of all classes associated with the given subject area.

Return type

list[str]

Raises

BadRequest – Some part of the required parameters is missing.

backend.form_response module

form_response.py

Helper methods for generating response objects. All response objects are generated like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}
backend.form_response.errorResponse(msg='')[source]

Formulate a response return that is an error. :param msg: error message to return to frontend. :type msg: str

Returns

_ – object suitable for reply over HTTP with a correctly formulated JSON body.

Return type

Response object

backend.form_response.jsonResponse(body={})[source]

Formulate a response return that is successful. :param body: dictionary of keys and their values to send with as the response :type body: dict

Returns

_ – object suitable for reply over HTTP with a correctly formulated JSON body.

Return type

Response object

backend.match module

match.py

Endpoints for operations related to matching users. All routes start with /api/match All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.match.get_user_list()[source]

POST get associated users of a given user.

Parameters

uid (int) – UID for the interested user

Returns

userList – string list of uids associated with the requested user

Return type

list[int]

Raises

BadRequest – Some part of the required parameters is missing.

backend.match.tutor_respond()[source]

POST [for tutors] respond to an incoming connection request. Backend adds both members to each other’s list.

Parameters
  • studentID (int) – UID for the student

  • tutorID (int) – UID of the tutor

Notes

returns an empty response body on success.

Raises

BadRequest – Some part of the required parameters is missing.

backend.message module

message.py

Endpoints for operations related to matching users. All routes start with /api/message All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.message.add()[source]

POST submit a message. :param from: UID for the originator, as string :type from: str :param to: UID of the recipient, as string :type to: str :param msg: message content :type msg: str :param createdDate: :type createdDate: timestamp

Notes

returns an empty response body on success.

Raises

BadRequest – Some part of the required parameters is missing.

backend.message.get()[source]

POST submit a message. :param uid1: UID for the originator, as string :type uid1: str :param uid2: UID of the recipient, as string :type uid2: str

Returns

messages – list of messages from uid1 to uid2

Return type

list(Message)

Notes

the Message object is exactly the request parameters of add/

Raises

BadRequest – Some part of the required parameters is missing.

See also

backend.message.add

contents of the Message object

backend.message.sortByDate(msg)[source]

helper function in redis search. unused during communication

backend.notification module

notification.py

Endpoints for operations related to matching users. All routes start with /api/notification All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.notification.add()[source]

POST get currently pending notifications

Parameters
  • uid (str) – UID to set the notification for

  • notification (Notification) – Notification object (see notes)

Returns

notifications

Return type

list(Notification)

Notes

the Notification object is structure as the following:

{
    msg: str
    notificationId: str
    createDate: timestamp
    read: bool
    type: "INITIATE" or "MESSAGE"
    from: str
    to: uid
}
Raises

BadRequest – Some part of the required parameters is missing.

backend.notification.delete()[source]

POST delete a given notification

Parameters
  • uid (str) –

  • notificationId (str) –

Notes

Method returns an empty object on success.

See also

backend.notification.get

notificationId

backend.notification.get()[source]

POST get currently pending notifications

Parameters

uid (str) – UID for the user requesting notifications

Returns

notifications

Return type

list(Notification)

Notes

the Notification objects returned by this endpoint each additionally contain a notificationId, which uniquely identifies them.

See also

backend.notification.add

implementation of Notification

backend.profile module

profile.py

Endpoints for operations related to matching users. All routes start with /api/profile All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.profile.edit()[source]

POST change attributes of a user profile.

Parameters
  • firstName (str) –

  • lastName (str) –

  • major (str) –

  • year (int) –

  • classes (list(str)) –

  • uid (str) –

Notes

returns empty json object on success.

Raises
  • BadRequest – Some part of the required parameters is missing.

  • UidNotFound – Could not find the user in the database.

backend.profile.get()[source]

POST get attributes of a user profile.

Parameters

uid (str) – uid of requested profile

Returns

  • firstName (str)

  • lastName (str)

  • major (str)

  • year (int)

  • classes (list(str))

  • uid (str)

  • notifications (list(Notifications))

  • Messages (list(Messages))

  • isTutor (bool)

Raises
  • BadRequest – Some part of the required parameters is missing.

  • UidNotFound – Could not find the user in the database.

See also

backend.message

messages module

backend.notification

notifications modle

backend.profile.pictureDownload()[source]

POST download the profile picture for the given user.

Parameters

uid (str) – uid of requested profile

Returns

profilePicUrl – base64 encoded data string or None

Return type

str

Raises
  • BadRequest – Some part of the required parameters is missing.

  • UidNotFound – Could not find the user in the database.

backend.profile.pictureUpload()[source]

POST upload a picture for the given user.

Parameters
  • uid (str) – uid of requested profile

  • profilePicUrl (str) – base64 encoded data string

Notes

method returns empty json object on success.

Raises
  • BadRequest – Some part of the required parameters is missing.

  • UidNotFound – Could not find the user in the database.

backend.rdscli module

rdscli.py helper module to connect to redis database.

backend.rdscli.connect(host='localhost', port=6379)[source]

Connect to database. Each subsequent call connects to the database again.

Parameters
  • host (str) – server location of redis

  • port (int) – default 6379 port of redis

Returns

rdscli.r – module-global Redis connection object

Return type

Redis

backend.recovery module

recovery.py

Endpoints for operations related to matching users. All routes start with /api/recovery All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.recovery.forgot()[source]

POST submit a password reset request. Emails the user a recovery link.

Parameters

email (str) – email to reset to

Notes

returns an empty response body on success.

Raises
  • BadRequest – Some part of the required parameters is missing.

  • EmailNotFound – no user associated with email.

  • ServerBad – Mailserver is not functioning.

backend.recovery.reset()[source]

POST complete a password reset request.

Parameters
  • secret (str) – secret sent in email

  • password (str) – new password

Notes

returns an empty response body on success.

Raises
  • BadRequest – Some part of the required parameters is missing.

  • NoRecovery – No recovery has been requested.

backend.schedule module

schedule.py

Endpoints for operations related to matching users. All routes start with /api/schedule All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

Scheduling blocks are from 9am - 9pm in two hour incrememts for 6 blocks a day, 7 days a week. We index into a scheduling array by 6*day + block.

backend.schedule.get()[source]

POST get schedule for user.

Parameters

uid (str) –

Returns

bytes – see module description for magic 42.

Return type

int[42]

Raises

BadRequest – Some part of the required parameters is missing.

backend.schedule.set()[source]

POST set schedule for user.

Parameters
  • uid (str) –

  • bytes (int[42]) – see module description for magic 42.

Notes

returns an empty response body on success.

Raises

BadRequest – Some part of the required parameters is missing.

backend.search module

search.py

Endpoints for operations related to matching users. All routes start with /api/search All incoming request parameters are wrapped in a JSON body. All outgoing response returns are wrapped in a JSON entry with key ‘payload’, like this:

{
  "error": "false",
  "error-msg": None,
    "payload": {
    "return-1": "true"
  }
}

Note that method documentation assumes you are using jsonResponse/errorResponse to generate the response, and only shows the actual returns within payload. Ditto for request parameters.

backend.search.construct_name(user)[source]

Helper function for search. Not used in requests.

backend.search.schedule_overlaps(schedule, user_sched)[source]

Helper function for search. Not used in requests.

backend.search.search_results()[source]

POST /get get search results

Parameters
  • name (str) – case-insensitive name search

  • classes (list(str)) – name of classes to search for

  • major (str) – major to search for

  • bytes (int[42]) – availibility to search for

Returns

tutors – list of UIDs of tutors which match search criteria

Return type

list(str)

Raises

BadRequest – Some part of the required parameters is missing.

See also

backend.schedule

magic 42

Module contents