2021-07-17 15:46:23 +00:00
|
|
|
# Chat Registration System
|
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
A simple chat system for built for maya's livestream.
|
|
|
|
Provides a simple API for user authentication, and chat functions.
|
|
|
|
Frontend & backend code stored here.
|
2021-07-17 15:46:23 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
## Auth API Documentation
|
2021-07-17 15:46:23 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
Most API functions will return JSON in the following format:
|
2021-07-16 14:55:07 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`status`: either `ok` if action succeeded, or `fail` otherwise.
|
2021-07-18 16:06:05 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`reason`: More info about why the action failed.
|
2021-07-18 16:06:05 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
### Register & Login:
|
2021-07-18 16:06:05 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`POST /api/register` with JSON body values of: `name`, `pin`, `pronouns`.
|
|
|
|
|
|
|
|
Will return JSON with `status` and `reason`.
|
|
|
|
|
|
|
|
`POST /api/login` with JSON body values of: `name`, `pin`.
|
|
|
|
|
|
|
|
Will return JSON with `status` and `reason`.
|
|
|
|
|
|
|
|
Will set a private cookie named `token` which is used for authentication.
|
|
|
|
|
|
|
|
### Change User Information
|
|
|
|
|
|
|
|
User information such as name, pin, and pronouns, can be changed currently one at a time.
|
|
|
|
|
|
|
|
`POST /api/change` with JSON body values of: `name`, `changed_event`, `new_event`.
|
|
|
|
|
|
|
|
`name` the user's current username. used for authentication.
|
|
|
|
|
|
|
|
`changed_event` which event to change. value can be one of: `Name`, `Pin`, `Pronouns`.
|
|
|
|
|
|
|
|
`new_event` the new value for the changed event.
|
|
|
|
|
|
|
|
User is authenticated via token.
|
2021-07-16 14:55:07 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
### Check if User is Still Logged in
|
2021-07-22 17:01:30 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
Instead of having to save the pin and re-login every time to check wether they're logged in, you can just check via the token.
|
2021-07-16 14:55:07 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`GET /api/token/<name>` where `<name>` is the current username.
|
2021-07-18 20:36:23 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
Will return JSON with `status` and `reason`.
|
2021-07-18 20:36:23 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
### Logout
|
2021-07-18 16:06:05 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
This API will remove the cookie from the client, as well as invalidating the token serverside.
|
|
|
|
|
|
|
|
`POST /api/logout` with JSON body values of: `name`.
|
|
|
|
|
|
|
|
Will use the current token as authentication.
|
|
|
|
|
|
|
|
Will return JSON with `status` and `reason`.
|
|
|
|
|
|
|
|
### Get Info About A User
|
|
|
|
|
|
|
|
This API will return info about a user on success.
|
|
|
|
|
|
|
|
`GET /api/users/<name>`
|
|
|
|
|
|
|
|
On success returns JSON in format:
|
2021-07-23 15:29:42 +00:00
|
|
|
```
|
|
|
|
status: ok
|
|
|
|
user:
|
|
|
|
name: user's name
|
|
|
|
pronouns: user's pronouns
|
|
|
|
role: the users role, one of either 'Normal', 'Moderator', or 'Admin'
|
|
|
|
```
|
2021-07-23 14:35:14 +00:00
|
|
|
|
|
|
|
eg:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
2021-07-23 15:29:42 +00:00
|
|
|
status: "ok",
|
|
|
|
user: {
|
|
|
|
name: "example",
|
|
|
|
pronouns: "they/them",
|
|
|
|
role: "Normal",
|
|
|
|
},
|
2021-07-23 14:35:14 +00:00
|
|
|
}
|
|
|
|
```
|
2021-07-22 18:23:59 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
## Chat API Documentation
|
2021-07-18 16:06:05 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`POST /api/message/send {"name":"username","body":"message body"}` Post a message with JSON body values of: `name` & `body`
|
2021-07-17 19:52:52 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
Will return JSON with `status` and `reason`.
|
2021-07-17 19:59:58 +00:00
|
|
|
|
2021-07-23 14:35:14 +00:00
|
|
|
`GET /api/message/messages.json` Returns a json file of all the messages
|
2021-07-17 19:59:58 +00:00
|
|
|
|
2021-07-17 19:52:52 +00:00
|
|
|
## Chat Planning
|
|
|
|
|
|
|
|
Clientside js will register & check login of users, if login is correct will ask for a random token.
|
|
|
|
Backend will generate token, store it, and then send it to the client to set as a cookie.
|
|
|
|
Whenever user sends a message, client will send message & token and backend will check if token matches.
|
|
|
|
|
|
|
|
## To-Do:
|
|
|
|
|
2021-07-18 16:06:05 +00:00
|
|
|
- [x] Basic auth API
|
2021-07-18 17:26:26 +00:00
|
|
|
- [x] Return json instead of string
|
2021-07-18 16:06:05 +00:00
|
|
|
- "status" shows wether request was succesful or not, either "ok" or "fail"
|
|
|
|
- "reason" is for more details, mainly just for debugging?
|
|
|
|
- [x] Basic messaging system
|
2021-07-18 15:37:11 +00:00
|
|
|
- [x] Finish up `chat::create_message()`
|
|
|
|
- [x] Create `chat::fetch_messages()`
|
2021-07-23 11:55:24 +00:00
|
|
|
- [x] Use unix timestamp for date
|
2021-07-18 02:27:05 +00:00
|
|
|
- [ ] Create `chat::delete_message()`
|
2021-07-22 15:44:31 +00:00
|
|
|
- [x] Switch to using sled database to store users
|
2021-07-23 14:35:14 +00:00
|
|
|
- [x] Error handling
|
2021-07-18 17:26:26 +00:00
|
|
|
- [x] Token generation & storage
|
|
|
|
- [x] Sets cookie
|
|
|
|
- [x] Store token in json
|
2021-07-22 15:44:31 +00:00
|
|
|
- [x] Have cookie expire
|
|
|
|
- [x] Remove old cookie
|
2021-07-22 17:01:30 +00:00
|
|
|
- [x] Use token for most stuff
|
2021-07-22 18:23:59 +00:00
|
|
|
- [x] Logout API
|
2021-07-22 17:01:30 +00:00
|
|
|
- [x] Fail on NULL token
|
2021-07-17 19:52:52 +00:00
|
|
|
- [x] Pronouns
|
2021-07-18 16:06:05 +00:00
|
|
|
- [x] Set pronouns
|
2021-07-22 21:17:55 +00:00
|
|
|
- [x] Change pronouns
|
2021-07-23 14:35:14 +00:00
|
|
|
- [x] make changed_event Enum, use token instead of pin
|
2021-07-18 02:27:05 +00:00
|
|
|
- [ ] Some form of plural support?
|
2021-07-17 23:41:41 +00:00
|
|
|
- [ ] User management (banning, etc.)
|
2021-07-22 21:30:06 +00:00
|
|
|
- [x] User roles (admin, mod, etc.)
|
|
|
|
- [ ] Commands to affect users
|
2021-07-17 23:41:41 +00:00
|
|
|
- [ ] Blacklist words from chat/names
|
2021-07-18 16:06:05 +00:00
|
|
|
- [ ] More advanced chat features
|
2021-07-22 20:20:49 +00:00
|
|
|
- [x] Different types of message events? eg. default, announcement, command
|
2021-07-22 21:30:06 +00:00
|
|
|
- [ ] Types will display differently? eg. announcements pinned to top?
|
|
|
|
- [ ] Have different commands?
|
2021-07-18 16:06:05 +00:00
|
|
|
- [ ] Emote support?
|