final touchups

This commit is contained in:
lingdocs 2021-08-26 16:54:15 +04:00
parent 18bd140614
commit 6d2a264295
3 changed files with 49 additions and 12 deletions

View File

@ -144,7 +144,7 @@ apiRouter.post("/user/upgradeToStudentRequest", async (req, res, next) => {
if (!req.user) throw new Error("user not found");
try {
if (req.user.level === "student" || req.user.level === "editor") {
res.send({ ok: true, message: "user already upgraded "});
res.send({ ok: true, message: "user already upgraded" });
return;
}
sendUpgradeRequestToAdmin(req.user).catch(console.error);

View File

@ -7,6 +7,9 @@
<title>Account · LingDocs</title>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
<script>
</script>
</head>
<body>
<div class="container" style="max-width: 400px;">
@ -14,7 +17,7 @@
<% if (user.admin) { %>
<a href="/admin"><h5 class="mb-2">Admin Console</h5></a>
<% } %>
<h4>Profile:</h4>
<h4>Profile <i class="fas fa-user ml-2"></i></h4>
<form method="POST" class="mb-4">
<div>
<label for="email" class="form-label">Email:</label>
@ -48,9 +51,16 @@
<button type="submit" class="btn btn-primary">Update Profile</button>
</div>
</form>
<h5>Account Level: <%= user.level %></h5>
<h5>Account Level: <%= user.level.charAt(0).toUpperCase() + user.level.slice(1) %></h5>
<% if (user.level === "basic") { %>
<% if (user.upgradeToStudentRequest === "waiting") { %>
<p>Wating for upgrade approval</p>
<% } else { %>
<button class="btn btn-sm btn-secondary" id="upgrade-request-button" onclick="handleRequestUpgrade()">Request Upgrade</button>
<% } %>
<% } %>
<% if (user.email) { %>
<h4 class="mt-3">Password:</h4>
<h4 class="mt-3 mb-3">Password <i class="fas fa-key ml-2"></i></h4>
<% if (!user.password) { %>
<p class="small">Add a password to be able to log in with just your e-mail address.</p>
<% } %>
@ -81,7 +91,7 @@
<div id="password-change-result" style="display: none;" class="alert alert-info mt-3 mb-4" role="alert">
</div>
<% if (user.email) { %>
<div class="d-flex flex-row justify-content-between mt-4 mb-3">
<div class="d-flex flex-row justify-content-between mt-2 mb-1">
<button type="button" id="password-change-button" class="btn btn-secondary">
<% if (user.password) { %>
Change
@ -93,14 +103,14 @@
<button type="button" style="display: none;" id="cancel-password-change-button" class="btn btn-light">Cancel</button>
</div>
<% } %>
<h4 class="mb-2">Linked Accounts:</h4>
<h4 class="mt-3 mb-1">Linked Accounts <i class="fas fa-link ml-2"></i></h4>
<div class="mb-4">
<% if (user.google) { %>
<!-- TODO: MAKE THIS EMAIL THING SAFER! -->
<div class="my-2 w-100 btn btn-secondary"><i class="fab fa-google mr-2"></i> Linked to Google · <%= user.google.emails[0].value %></div>
<form action="/google/remove" method="POST">
<% if (removeProviderOption) { %>
<button type="submit" class="btn btn-sm">Unlink from Google</button>
<button type="submit" class="btn btn-sm btn-outline">Unlink from Google</button>
<% } %>
</form>
<% } %>
@ -108,7 +118,7 @@
<div class="my-2 w-100 btn btn-secondary"><i class="fab fa-twitter mr-2"></i> Linked to Twitter · @<%= user.twitter.username %></div>
<form action="/twitter/remove" method="POST">
<% if (removeProviderOption) { %>
<button type="submit" class="btn btn-sm">Unlink from twitter</button>
<button type="submit" class="btn btn-sm btn-outline">Unlink from Twitter</button>
<% } %>
</form>
<% } %>
@ -116,7 +126,7 @@
<div class="my-2 w-100 btn btn-secondary"><i class="fab fa-github mr-2"></i> Linked to GitHub · <%= user.github.username %></div>
<form action="/github/remove" method="POST">
<% if (removeProviderOption) { %>
<button type="submit" class="btn btn-sm">Unlink from GitHub</button>
<button type="submit" class="btn btn-sm btn-outline">Unlink from GitHub</button>
<% } %>
</form>
<% } %>
@ -147,8 +157,34 @@
<script>
if (window.opener) {
const w = window.opener
w.postMessage("signed in", "https://dev.dictionary.lingdocs.com");
// window.opener.postMessage("signed in", "https://dictionary.lingdocs.com");
try {
w.postMessage("signed in", "https://dictionary.lingdocs.com");
} catch (e) {
console.error(e);
}
try {
w.postMessage("signed in", "https://dev.dictionary.lingdocs.com");
} catch (e) {
console.error(e);
}
}
function handleRequestUpgrade() {
console.log("got here");
const btn = document.getElementById("upgrade-request-button");
btn.innerHTML = "Sending...";
fetch("/api/user/upgradeToStudentRequest", {
method: "POST",
}).then((res) => res.json()).then((res) => {
console.log(res);
if (res.ok) {
btn.innerHTML = "Upgrade request sent";
} else {
btn.innerHTML = "Error requesting upgrade";
}
}).catch((e) => {
console.error(e);
btn.innerHTML = "Error requesting upgrade";
});
}
function clearPasswordForm() {
document.getElementById("oldPassword").value = "";

View File

@ -160,7 +160,7 @@ const Account = ({ user, loadUser }: { user: AT.LingdocsUser | undefined, loadUs
: ""}</li>
<li className="list-group-item">Signs in with:
{(user.password && user.email) && <span>
<i className="fas fa-key ml-2"></i> <span className="small mr-2">Password</span>
<i className="fas fa-key ml-2"></i> <span className="small mr-1">Password</span>
</span>}
{providers.map((provider) => (
user[provider] && <span>
@ -171,6 +171,7 @@ const Account = ({ user, loadUser }: { user: AT.LingdocsUser | undefined, loadUs
</ul>
</div>
</div>
{user.level === "student" && <p><strong>Note:</strong> If you had a student account in the previous system <em>your wordlist will be moved over to this account in a couple of days</em>.</p>}
<h4 className="mb-3">Account Admin</h4>
<div className="row mb-4">
{user.level === "basic" && <div className="col-sm mb-3">