diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index 566504e..559cb95 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -6,7 +6,7 @@ import { getLingdocsUser, updateLingdocsUser, } from "../lib/couch-db"; -import { createNewUser, canRemoveOneOutsideProvider } from "../lib/user-utils"; +import { createNewUser, canRemoveOneOutsideProvider, downgradeUser } from "../lib/user-utils"; import { getHash, getURLToken, @@ -191,6 +191,18 @@ const authRouter = (passport: PassportStatic) => { } }); + router.post("/downgradeToBasic", async (req, res, next) => { + try { + if (!req.user) { + return res.redirect("/"); + } + await downgradeUser(req.user.userId); + res.redirect("/"); + } catch (e) { + next(e); + } + }); + router.delete("/admin/:userId", async (req, res, next) => { try { // TODO: MAKE PROPER MIDDLEWARE WITH TYPING diff --git a/account/src/routers/payment-router.ts b/account/src/routers/payment-router.ts index 3aed866..e0f27da 100644 --- a/account/src/routers/payment-router.ts +++ b/account/src/routers/payment-router.ts @@ -53,7 +53,6 @@ paymentRouter.post( case 'customer.subscription.created': subscription = event.data.object; status = subscription.status; - console.log({ subscription }); console.log(`Upgrading user ${userId}.`); await upgradeUser(userId); // TODO: save subscription to db @@ -97,7 +96,8 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => { subscription_data: { metadata: { userId: req.user.userId, - } + startTime: Date.now(), + }, }, mode: 'subscription', success_url: `https://account.lingdocs.com/user?upgrade=success`, diff --git a/account/views/user.ejs b/account/views/user.ejs index 6f34995..28839e0 100644 --- a/account/views/user.ejs +++ b/account/views/user.ejs @@ -67,6 +67,11 @@ <% } %> <% } %> + <% if (user.tester && user.level === "student") { %> +
+ +
+ <% } %> <% if (user.email) { %>

Password

<% if (!user.password) { %>