Compare commits

...

4 Commits

Author SHA1 Message Date
adueck 5c67fb5179 update year in login page 2023-12-17 00:21:40 +04:00
adueck ef0098d7ee better email validation on signup 2023-12-17 00:17:20 +04:00
adueck 34d7387a44 better email validation on signup 2023-12-16 23:41:13 +04:00
adueck a199019439 update README, not using couchdb_peruser anymore 2023-12-16 23:14:50 +04:00
4 changed files with 24 additions and 15 deletions

View File

@ -217,7 +217,7 @@ server {
When a user upgrades their account level to `student` or `editor`:
1. A doc in the `_users` db is created with their Firebase Authentication info, account level, and a password they can use for syncing their personal wordlistdb
2. A user database is created (automatically by `couchdb_peruser`) which they use to sync their personal wordlist.
2. A user database is created which they use to sync their personal wordlist.
There is also a `review-tasks` database which is used to store all the review tasks for editors and syncs with the review tasks in the app for the editor(s).

View File

@ -7,9 +7,12 @@ import { DocumentInsertResponse } from "nano";
import env from "./src/lib/env-vars";
import * as T from "../website/src/types/account-types";
import {
addCouchDbAuthUser,
generateWordlistDbPassword,
getAllLingdocsUsers,
getLingdocsUser,
insertLingdocsUser,
updateLingdocsUser,
} from "./src/lib/couch-db";
const nano = Nano(env.couchDbURL);
@ -31,7 +34,6 @@ function processAPIResponse(
async function main() {
const users = await getAllLingdocsUsers();
const usersWDbs = users.filter((x) => x.level !== "basic");
const paidUsersEmails: string[] = [];
for (let user of usersWDbs) {
// if (!user.docs.length) return;
// const u = user.docs[0];
@ -39,6 +41,22 @@ async function main() {
if (user.level === "basic") {
throw new Error("");
}
process.stdout.write(
`Checking for _user for ${user.name} - ${user.email}...`
);
const uzrs = nano.db.use("_users");
const r = await uzrs.find({
selector: { _id: `org.couchdb.user:${user.userId}` },
});
console.log(r.docs.length ? "✅" : "❌");
if (!r.docs.length) {
console.log(`Creating wordlist db for ${user.name} - ${user.email}...`);
const { password, userDbName } = await addCouchDbAuthUser(user.userId);
await updateLingdocsUser(user.userId, {
couchDbPassword: password,
wordlistDbName: userDbName,
});
}
process.stdout.write(`Checking for db for ${user.name} - ${user.email}...`);
const userDb = nano.db.use(user.wordlistDbName);
try {
@ -89,16 +107,6 @@ async function main() {
return "done";
}
// function removeRedundant(tests: T.TestResult[]): T.TestResult[] {
// if (tests.length === 0) return tests;
// const first = tests[0];
// const rest = tests.slice(1);
// const redundancies = rest.filter(x => ((x.id === first.id)) && (x.done === first.done));
// return redundancies.length < 2
// ? [first, ...removeRedundant(rest)]
// : removeRedundant(rest);
// }
main().then((res) => {
console.log(res);
});

View File

@ -146,6 +146,7 @@ export async function updateLingdocsUser(
| { upgradeToStudentRequest: "waiting" }
| { upgradeToStudentRequest: "denied" }
| { tests: T.TestResult[] }
| { wordlistDbName: T.WordlistDbName; couchDbPassword: T.UserDbPassword }
): Promise<T.LingdocsUser> {
const user = await getLingdocsUser("userId", uuid);
if (!user) throw new Error("unable to update - user not found " + uuid);
@ -238,7 +239,7 @@ export function getWordlistDbName(uid: T.UUID): T.WordlistDbName {
return `${userDbPrefix}${stringToHex(uid)}` as T.WordlistDbName;
}
function generateWordlistDbPassword(): T.UserDbPassword {
export function generateWordlistDbPassword(): T.UserDbPassword {
function makeChunk(): string {
return Math.random().toString(36).slice(2);
}

View File

@ -29,7 +29,7 @@
<h1 class="h3 mb-4 fw-normal">Sign in to LingDocs</h1>
<!-- <p class="small mb-2">New? Enter an e-mail and password to sign up</p> -->
<div class="form-floating mt-3">
<input type="email" required class="form-control" id="emailInput" placeholder="name@example.com">
<input type="email" pattern='(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])' required class="form-control" id="emailInput" placeholder="name@example.com">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
@ -61,7 +61,7 @@
<a href="/google" class="mt-1 w-100 btn btn-lg btn-secondary" role="button"><i class="fab fa-google mr-2"></i> Sign In With Google</a>
<a href="/twitter" class="mt-3 w-100 btn btn-lg btn-secondary" role="button"><i class="fab fa-twitter mr-2"></i> Sign In With Twitter</a>
<a href="/github" class="mt-3 w-100 btn btn-lg btn-secondary" role="button"><i class="fab fa-github mr-2"></i> Sign In With GitHub</a>
<p class="mt-5 text-muted">&copy; 2021 <a href="https://www.lingdocs.com/">LingDocs.com</a></p>
<p class="mt-5 text-muted">&copy; <script type="text/javascript">document.write(new Date().getFullYear());</script><noscript>2023</noscript> <a href="https://www.lingdocs.com/">LingDocs.com</a></p>
<p class="mt-3 text-muted small"><a href="/privacy">privacy policy</a></p>
</main>
</body>