| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- const query = require("../queries");
- const utils = require("../utils");
- const env = require("../env");
- async function homepage(req, res) {
- res.render("homepage", {
- title: "Modern open source URL shortener",
- });
- }
- function login(req, res) {
- if (req.user) {
- res.redirect("/");
- return;
- }
- res.render("login", {
- title: "Log in or sign up"
- });
- }
- function logout(req, res) {
- utils.deleteCurrentToken(res);
- res.render("logout", {
- title: "Logging out.."
- });
- }
- function notFound(req, res) {
- res.render("404", {
- title: "404 - Not found"
- });
- }
- function settings(req, res) {
- res.render("settings", {
- title: "Settings"
- });
- }
- function stats(req, res) {
- res.render("stats", {
- title: "Stats"
- });
- }
- async function banned(req, res) {
- res.render("banned", {
- title: "Banned link",
- });
- }
- async function report(req, res) {
- res.render("report", {
- title: "Report abuse",
- });
- }
- async function resetPassword(req, res) {
- res.render("reset_password", {
- title: "Reset password",
- });
- }
- async function resetPasswordResult(req, res) {
- res.render("reset_password_result", {
- title: "Reset password",
- });
- }
- async function verifyChangeEmail(req, res) {
- res.render("verify_change_email", {
- title: "Verifying email",
- });
- }
- async function verify(req, res) {
- res.render("verify", {
- title: "Verify",
- });
- }
- async function terms(req, res) {
- res.render("terms", {
- title: "Terms of Service",
- });
- }
- async function confirmLinkDelete(req, res) {
- const link = await query.link.find({
- uuid: req.query.id,
- ...(!req.user.admin && { user_id: req.user.id })
- });
- if (!link) {
- return res.render("partials/links/dialog/message", {
- layout: false,
- message: "Could not find the link."
- });
- }
- res.render("partials/links/dialog/delete", {
- layout: false,
- link: utils.getShortURL(link.address, link.domain).link,
- id: link.uuid
- });
- }
- async function confirmLinkBan(req, res) {
- const link = await query.link.find({
- uuid: req.query.id,
- ...(!req.user.admin && { user_id: req.user.id })
- });
- if (!link) {
- return res.render("partials/links/dialog/message", {
- message: "Could not find the link."
- });
- }
- res.render("partials/links/dialog/ban", {
- link: utils.getShortURL(link.address, link.domain).link,
- id: link.uuid
- });
- }
- async function addDomainForm(req, res) {
- res.render("partials/settings/domain/add_form");
- }
- async function confirmDomainDelete(req, res) {
- const domain = await query.domain.find({
- uuid: req.query.id,
- user_id: req.user.id
- });
- if (!domain) {
- throw new utils.CustomError("Could not find the link", 400);
- }
- res.render("partials/settings/domain/delete", {
- ...utils.sanitize.domain(domain)
- });
- }
- async function getReportEmail(req, res) {
- if (!env.REPORT_EMAIL) {
- throw new utils.CustomError("No report email is available.", 400);
- }
- res.render("partials/report/email", {
- report_email: env.REPORT_EMAIL.replace("@", "[at]")
- });
- }
- async function getSupportEmail(req, res) {
- if (!env.CONTACT_EMAIL) {
- throw new utils.CustomError("No support email is available.", 400);
- }
- await utils.sleep(500);
- res.render("partials/support_email", {
- email: env.CONTACT_EMAIL,
- });
- }
- async function linkEdit(req, res) {
- const link = await query.link.find({
- uuid: req.params.id,
- ...(!req.user.admin && { user_id: req.user.id })
- });
- res.render("partials/links/edit", {
- ...(link && utils.sanitize.link(link)),
- });
- }
- module.exports = {
- addDomainForm,
- banned,
- confirmDomainDelete,
- confirmLinkBan,
- confirmLinkDelete,
- getReportEmail,
- getSupportEmail,
- homepage,
- linkEdit,
- login,
- logout,
- notFound,
- report,
- resetPassword,
- resetPasswordResult,
- settings,
- stats,
- terms,
- verifyChangeEmail,
- verify,
- }
|