Skip to content

Commit

Permalink
Merge branch 'main' into leeoocca/feat/autoresize-textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoocca committed Nov 21, 2024
2 parents 1e94866 + 8c3ff16 commit ce09edc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
7 changes: 3 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ CLIENT_ID=""
CLIENT_SECRET=""
RATE_LIMIT=2

DISCORD_WEBHOOK_ID="example"
DISCORD_WEBHOOK_TOKEN="example"
COUNCIL_SERVER_ISSUE_WEBHOOK_URL="example.com"
STUDENT_SERVER_ISSUE_WEBHOOK_URL="example.com"
CONTACT_WEBHOOK_URL=""
COUNCIL_SERVER_ISSUE_WEBHOOK_URL=""
STUDENT_SERVER_ISSUE_WEBHOOK_URL=""

# Production only
HOST=
Expand Down
38 changes: 22 additions & 16 deletions .github/docs/DOTENV.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# .env File
# .env file

In order to build the website yourself, you will need to create a .env file.

## What is a .env File?
## What is a .env file?

A .env file is a text file containing environment variables. These are used to configure your app's settings, such as credentials, which should _never_ be hard-coded in your source code.

## What Variables Do I Need?
## What variables do I need?

We got you! Check the [.env.example](../../.env.example).

## Set Up 42-OAuth
## Set up 42 OAuth

Here is how OAuth Authentification works:

1. **User Initiates Authentication**: When a user tries to log in, they are redirected to the 42 Network's authentication page.
2. **User Authorizes Application**: The user logs in and authorizes the application to access their information.
3. **Provider Redirects Back**: Upon successful authentication, the 42 Network redirects the user back to your application's callback URL with an authorization code.
Expand All @@ -26,32 +27,37 @@ You will be asked for a **Redirect URI**. This is the URI the user will be redir
This should be as follows: `http://<IP>:5173/oauth/callback`

Once you are done, you will get a UID and a secret, which you can use for authenticating your app. You can then add these to your .env file as follows:

```.env
CLIENT_ID=<UID>
CLIENT_SECRET=<SECRET>
```

## Set Up Discord Webhook
## Set up Discord Webhooks

1. Create a Discord Server:
* If you do not already have a server, create a new one. This can be your personal development server.
- If you do not already have a server, create a new one. This can be your personal development server.
2. Create a Webhook:
* Navigate to the channel where you want to receive the messages.
* Click on the settings icon next to the channel name.
* In the channel settings, go to the 'Integrations' tab.
* Click on 'Create Webhook'.
- Navigate to the channel where you want to receive the messages. The webhook integration has been specifically designed for forum channels.
- Click on the settings icon next to the channel name.
- In the channel settings, go to the 'Integrations' tab.
- Click on 'Create Webhook'.
3. Copy the Webhook URL:
* It should look something like this:
- It should look something like this:

```
https://discord.com/api/webhooks/<WEBHOOK_ID>/<WEBHOOK_TOKEN>
```

4. Add the Webhook ID and Token to Your .env File:
* Split the webhook URL to extract the <WEBHOOK_ID> and <WEBHOOK_TOKEN>.
* Add these to your .env file:
```.env
DISCORD_WEBHOOK_ID=<WEBHOOK_ID>
DISCORD_WEBHOOK_TOKEN=<WEBHOOK_TOKEN>
- Add these to your .env file:

```sh
CONTACT_WEBHOOK_URL=<WEBHOOK_URL>
COUNCIL_SERVER_ISSUE_WEBHOOK_URL=<WEBHOOK_URL>
STUDENT_SERVER_ISSUE_WEBHOOK_URL=<WEBHOOK_URL>
```

# REMINDER

Pushing private credentials on an open source project poses a **huge** security issue. We _will_ deny any pull request containing them and we _might_ prank you using your credentials 😉.
8 changes: 4 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
profiles:
- dev
- prod
restart: always

app_prod:
build:
Expand All @@ -31,13 +32,13 @@ services:
CLIENT_ID: ${CLIENT_ID}
CLIENT_SECRET: ${CLIENT_SECRET}
RATE_LIMIT: ${RATE_LIMIT}
DISCORD_WEBHOOK_ID: ${DISCORD_WEBHOOK_ID}
DISCORD_WEBHOOK_TOKEN: ${DISCORD_WEBHOOK_TOKEN}
CONTACT_WEBHOOK_URL: ${CONTACT_WEBHOOK_URL}
COUNCIL_SERVER_ISSUE_WEBHOOK_URL: ${COUNCIL_SERVER_ISSUE_WEBHOOK_URL}
STUDENT_SERVER_ISSUE_WEBHOOK_URL: ${STUDENT_SERVER_ISSUE_WEBHOOK_URL}
SUPER_ADMIN: ${SUPER_ADMIN}
profiles:
- prod
restart: always

app_dev:
build:
Expand All @@ -58,8 +59,7 @@ services:
CLIENT_SECRET: ${CLIENT_SECRET}
RATE_LIMIT: ${RATE_LIMIT}
BASE_URL: ${BASE_URL}
DISCORD_WEBHOOK_ID: ${DISCORD_WEBHOOK_ID}
DISCORD_WEBHOOK_TOKEN: ${DISCORD_WEBHOOK_TOKEN}
CONTACT_WEBHOOK_URL: ${CONTACT_WEBHOOK_URL}
COUNCIL_SERVER_ISSUE_WEBHOOK_URL: ${COUNCIL_SERVER_ISSUE_WEBHOOK_URL}
STUDENT_SERVER_ISSUE_WEBHOOK_URL: ${STUDENT_SERVER_ISSUE_WEBHOOK_URL}
SUPER_ADMIN: ${SUPER_ADMIN}
Expand Down
5 changes: 3 additions & 2 deletions src/app/routes/_app.contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { Button } from '~/components/ui/button';
import { Input } from '~/components/ui/input';
import { Label } from '~/components/ui/label';
import { RadioGroup, RadioGroupItem } from '~/components/ui/radio-group';
import { sendDiscordWebhook } from '~/utils/discord.server';
import { config } from '~/utils/config.server';
import { sendDiscordWebhookWithUrl } from '~/utils/discord.server';
import { SessionData, requireSessionData } from '~/utils/session.server';
import { validateForm } from '~/utils/validation';

Expand Down Expand Up @@ -79,7 +80,7 @@ export async function action({ request }: ActionFunctionArgs) {
}

try {
await sendDiscordWebhook({
await sendDiscordWebhookWithUrl(config.discord.contactWebhookUrl, {
embeds: [embed],
username: 'Webportal',
wait: true,
Expand Down
3 changes: 1 addition & 2 deletions src/app/utils/config.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export const config = {
baseUrl: requireEnv('BASE_URL'),
discord: {
webhookId: requireEnv('DISCORD_WEBHOOK_ID'),
webhookToken: requireEnv('DISCORD_WEBHOOK_TOKEN'),
contactWebhookUrl: requireEnv('CONTACT_WEBHOOK_URL'),
councilServerIssueWebhookUrl: requireEnv('COUNCIL_SERVER_ISSUE_WEBHOOK_URL'),
studentServerIssueWebhookUrl: requireEnv('STUDENT_SERVER_ISSUE_WEBHOOK_URL'),
},
Expand Down
8 changes: 2 additions & 6 deletions src/app/utils/discord.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { REST, RawFile } from '@discordjs/rest';
import { API, RESTPostAPIWebhookWithTokenJSONBody, RESTPostAPIWebhookWithTokenQuery } from '@discordjs/core';
import { config } from './config.server';
import { REST, RawFile } from '@discordjs/rest';

const rest = new REST({ version: '10' });
const api = new API(rest);
Expand All @@ -11,11 +10,8 @@ export type ExecuteWebhookData = RESTPostAPIWebhookWithTokenJSONBody &
wait: true;
};

export async function sendDiscordWebhook(data: ExecuteWebhookData) {
await api.webhooks.execute(config.discord.webhookId, config.discord.webhookToken, data);
}

export async function sendDiscordWebhookWithUrl(url: string, data: ExecuteWebhookData) {
if (!url.length) return;
const [id, token] = url.split('/').slice(-2);
return await api.webhooks.execute(id, token, data);
}

0 comments on commit ce09edc

Please sign in to comment.