From bbc72aa1200e8327e17942ac86221a585e4cb6bd Mon Sep 17 00:00:00 2001 From: andrewstech Date: Fri, 15 Mar 2024 22:16:46 +0000 Subject: [PATCH] Main UI --- .github/workflows/main.yml | 42 ++++++++ Dockerfile | 22 ++++ routes/domains.js | 1 + routes/login.js | 26 ++++- util/jwt.js | 4 +- util/router.js | 6 +- views/domain.ejs | 206 ++++++++++++++++++++++++++++--------- views/login.ejs | 8 +- 8 files changed, 261 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 Dockerfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3b7e0e5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,42 @@ +name: Docker + +on: + push: {} + workflow_dispatch: {} + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + name: Build and Push + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + + - name: Registry Login + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Metadata + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and Push Image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..acf9dac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:latest + +# Create the directory! +RUN mkdir -p /usr/src/bot +WORKDIR /usr/src/bot + +# Copy and Install our bot +COPY package.json /usr/src/bot +RUN npm install + +# For Debugging +#RUN apt-get update && apt-get install -y \ +# nano \ +# curl \ +# git \ +# && rm -rf /var/lib/apt/lists/* + +# Our precious bot +COPY . /usr/src/bot + +# Start me! +CMD ["node", "."] \ No newline at end of file diff --git a/routes/domains.js b/routes/domains.js index a4e0676..aba48c7 100644 --- a/routes/domains.js +++ b/routes/domains.js @@ -10,6 +10,7 @@ module.exports = async (req, res) => { }, }); data = await data.json(); + console.log(user) res.render("domain", {user: user, domains: data}) } \ No newline at end of file diff --git a/routes/login.js b/routes/login.js index 6b8fea5..73c254f 100644 --- a/routes/login.js +++ b/routes/login.js @@ -1,3 +1,25 @@ -module.exports = (req, res) => { - res.render("login"); +module.exports = async (req, res) => { + const username = req.body.username; + const password = req.body.password; + + if (!username || !password) { + return res.render("login", { message: "Missing username or password." }); + } + const data = { + "username": username, + "password": password, + }; + const response = await fetch("https://api.open-domains.net/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + const authd = await response.json(); + if (authd.message) { + return res.render("login", { message: authd.message }); + } + res.cookie("token", authd.accessToken, { httpsOnly: true }); + return res.redirect("/domains"); } \ No newline at end of file diff --git a/util/jwt.js b/util/jwt.js index aea2f1d..bfb3550 100644 --- a/util/jwt.js +++ b/util/jwt.js @@ -19,7 +19,9 @@ async function authenticateToken(req, res, next) { if (response.status !== 200) { return res.sendStatus(403); // Forbidden if token is invalid } else { - const user = await response.json(); + let user = await response.json(); + // make the first letter of the username uppercase + user.username = user.username.charAt(0).toUpperCase() + user.username.slice(1); req.user = user; next(); } diff --git a/util/router.js b/util/router.js index b17fd73..c2ded40 100644 --- a/util/router.js +++ b/util/router.js @@ -20,7 +20,11 @@ router.get("/profile", authenticateToken, (req, res) => { router.get("/login", (req, res) => { - res.render("login"); + res.render("login", { message: '' }); +}); + +router.post("/login", upload.any(), (req, res) => { + routes.login(req, res); }); router.get("/register", (req, res) => { diff --git a/views/domain.ejs b/views/domain.ejs index a23b8fc..cfff82d 100644 --- a/views/domain.ejs +++ b/views/domain.ejs @@ -1,54 +1,164 @@ - - + - - - User Profile - - - -
- Profile Picture - -
-
-

Hello <%= user.username %>

- - -
-

Domain List

- <% if (domains.length === 0) { %> -

You have no domains.

- <% } else { %> - - - - - - - - - - <% domains.forEach(domain => { %> - - - - - - <% }) %> - -
Domain NameStatus
<%= domain._id %><%= domain.status %> - Edit -
+ +
+
- - - +
+ + +
+
+ + My domains + <% if (user.staffMember) { %> + Staff + <% } %> + Donate +
+
+
+
+ +
+
+
<%= user.username %>
+
<%= user.email %>
+
+ +
+ +
+
+ + +
+
+

Hello <%= user.username %>

+
+
+
+
+ +
+

Domain List

+ <% if (domains.length === 0) { %> +

You have no domains.

+ <% } else { %> + + + + + + + + + + <% domains.forEach(domain => { %> + + + + + + <% }) %> + +
Domain NameStatus
<%= domain._id %><%= domain.status %> + Edit +
+ <% } %> +
+
+
+
+ \ No newline at end of file diff --git a/views/login.ejs b/views/login.ejs index ff77b3d..4d604ce 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -33,9 +33,13 @@

Login

- <% if (message.length > 0) { %> -
<%= message %>
+ <% if (message && message.length > 0) { %> + <% } %> +