Skip to content

Commit

Permalink
/dash/profile added
Browse files Browse the repository at this point in the history
  • Loading branch information
daneedev committed Oct 30, 2024
1 parent df92058 commit 158dd1f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
16 changes: 15 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const Server = require("../models/Server");
const Plan = require("../models/Plan");
const Egg = require("../models/Egg");


// /DASH

router.get("/", checkSetup, checkAuth, async function (req, res) {
const serverCount = await Server.count({where: {ownerId: req.user.id}})
res.render("dash/home.html", {hostname: (await SettingsModel.findOne({where: {name: "hostname"}})).value, username: req.user.username, gravatarhash: sha256(req.user.email), credits: req.user.credits, pterourl: (await SettingsModel.findOne({where: {name: "pterourl"}})).value, isAdmin: req.user.admin, page: "Home", serverCount: serverCount})
Expand All @@ -20,17 +23,28 @@ router.get("/", checkSetup, checkAuth, async function (req, res) {
router.get("/servers", checkSetup, checkAuth, async function (req, res) {
const servers = await Server.findAll({where: {ownerId: req.user.id}})
const serversArray = await Promise.all(servers.map(async server => {
const plan = await Plan.findOne({where: {id: server.planId}})
let serverObject = {
id: server.id,
name: server.name,
plan: (await Plan.findOne({where: {id: server.planId}})).name,
plan: plan.name,
egg: (await Egg.findOne({where: {id: server.eggId}})).name,
price: plan.price,
hourPrice: (plan.price / 720).toFixed(2)
}
return serverObject;
}))
res.render("dash/servers.html", {hostname: (await SettingsModel.findOne({where: {name: "hostname"}})).value, servers: serversArray, username: req.user.username, gravatarhash: sha256(req.user.email), credits: req.user.credits, pterourl: (await SettingsModel.findOne({where: {name: "pterourl"}})).value, isAdmin: req.user.admin, page: "Your servers"})
})


router.get("/profile", checkSetup, checkAuth, async function (req, res) {
const user = await User.findOne({where: {id: req.user.id}})
res.render("dash/profile.html", {hostname: (await SettingsModel.findOne({where: {name: "hostname"}})).value, username: req.user.username, gravatarhash: sha256(req.user.email), credits: req.user.credits, pterourl: (await SettingsModel.findOne({where: {name: "pterourl"}})).value, isAdmin: req.user.admin, page: "Profile", user: user})
})

// /SETUP

router2.get("/", checkNotSetup, function (req, res) {
res.render("setup.html", {})
})
Expand Down
40 changes: 40 additions & 0 deletions views/dash/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "dash/dash.html" %}

{% block head %}
{% endblock %}

{% block content %}
<div class="flex flex-col items-center">
<div class="w-1/4 flex flex-col bg-slate-700 rounded-lg p-10">
<div class="flex flex-row items-center gap-3 justify-center">
<img src={{ "https://gravatar.com/avatar/" + gravatarhash }} class="w-16 rounded-full">
<h1 class="text-2xl text-white font-bold">{{ user.username }}</h2>
</div>
<div class="flex flex-col items-center mt-5">
<p class="text-lg text-slate-400"><i class="fa-solid fa-envelope"></i>&nbsp;Email: <span class="text-white font-bold">{{ user.email }}</span></p>
<p class="text-lg text-slate-400"><i class="fa-solid fa-coins"></i>&nbsp;Credits: <span class="text-white font-bold">{{ user.credits }}</span></p>
{% if user.verifiedEmail %}
<p class="text-lg text-green-400"><i class="fa-solid fa-check"></i>&nbsp;Email verified</p>
{% else %}
<p class="text-lg text-red-400"><i class="fa-solid fa-times"></i>&nbsp;Email not verified</p>
{% endif %}
{% if user.admin %}
<p class="text-lg text-yellow-400"><i class="fa-solid fa-hammer"></i>&nbsp;Admin rights</p>
{% endif %}
</div>
<div class="flex flex-row justify-between">
<form action="/user/edit">
<button class="bg-slate-800 hover:bg-slate-600 hover:text-blue-500 duration-300 text-white font-bold rounded-md h-10 w-40 mt-5" type="submit"><i class="fa-solid fa-pen"></i>&nbsp;Edit profile</button>
</form>
{% if user.verifiedEmail == false %}
<form action="/user/verify">
<button class="bg-slate-800 hover:bg-slate-600 hover:text-green-500 duration-300 text-white font-bold rounded-md h-10 w-40 mt-5" type="submit"><i class="fa-solid fa-envelope"></i>&nbsp;Verify email</button>
</form>
{% endif %}
<form action="/user/delete">
<button class="bg-slate-800 hover:bg-slate-600 hover:text-red-500 duration-300 text-white font-bold rounded-md h-10 w-40 mt-5" type="submit"><i class="fa-solid fa-trash"></i>&nbsp;Delete profile</button>
</form>
</div>
</div>
</div>
{% endblock %}

0 comments on commit 158dd1f

Please sign in to comment.