diff --git a/Dockerfile b/Dockerfile index 62f19d118..cdff362d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ RUN node --version RUN rm -rvf /app/node_modules RUN git clone https://github.com/2anki/web /app/web -RUN git -C /app/web checkout 2c195d254bef9398db2a32888f570b8bf1e765d8 RUN git clone https://github.com/2anki/create_deck /app/create_deck RUN npm --prefix /app/web install diff --git a/migrations/20221029071325_remove-verify-user.js b/migrations/20221029071325_remove-verify-user.js new file mode 100644 index 000000000..00d625e7a --- /dev/null +++ b/migrations/20221029071325_remove-verify-user.js @@ -0,0 +1,13 @@ +exports.up = function (knex) { + return knex.schema.table('users', (table) => { + table.dropColumn('verification_token'); + table.dropColumn('verified'); + }); +}; + +module.exports.down = (knex) => { + return knex.schema.table('users', (table) => { + table.boolean('verified').defaultTo(true); + table.string('verification_token'); + }); +}; diff --git a/package-lock.json b/package-lock.json index ea46a76a3..50ddfaa93 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "notion2anki-server", - "version": "1.0.0-alpha.32", + "version": "1.0.0-alpha.35", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "notion2anki-server", - "version": "1.0.0-alpha.32", + "version": "1.0.0-alpha.35", "license": "MIT", "dependencies": { "@notionhq/client": "^0.4.12", diff --git a/package.json b/package.json index eefa0a5c5..e52658b67 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "notion2anki" ], "author": "Alexander Alemayhu", - "version": "1.0.0-alpha.32", + "version": "1.0.0-alpha.35", "engines": { "node": ">=12.0.0" }, diff --git a/src/lib/email/EmailHandler.ts b/src/lib/email/EmailHandler.ts index 01d1cb9ab..c51941562 100644 --- a/src/lib/email/EmailHandler.ts +++ b/src/lib/email/EmailHandler.ts @@ -3,10 +3,6 @@ import fs from 'fs'; const EMAIL_TEMPLATES_DIRECTORY = path.join(__dirname, 'templates'); -const VERIFICATION_TEMPLATE = fs.readFileSync( - path.join(EMAIL_TEMPLATES_DIRECTORY, 'verification.html'), - 'utf8' -); const PASSWORD_RESET_TEMPLATE = fs.readFileSync( path.join(EMAIL_TEMPLATES_DIRECTORY, 'reset.html'), 'utf8' @@ -40,21 +36,6 @@ class EmailHandler { return sgMail.send(msg); } - static async SendVerificationEmail(email: string, token: string) { - const link = `${process.env.DOMAIN}/api/users/v/${token}`; - const markup = VERIFICATION_TEMPLATE.replace('{{link}}', link); - const msg = { - to: email, - from: DEFAULT_SENDER, - subject: 'Verify your 2anki.net account', - text: `Please verify your account by visiting the following link ${link}`, - html: markup, - replyTo: 'alexander@alemayhu.com', - }; - - return sgMail.send(msg); - } - static async SendConversionEmail( email: string, filename: string, diff --git a/src/lib/email/templates/verification.html b/src/lib/email/templates/verification.html deleted file mode 100644 index eac9e2d3e..000000000 --- a/src/lib/email/templates/verification.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - 2anki.net - Account Verification - - - - -
-
-

Account verification

-

- Please verify your account by visiting the link below -

- verify -

- If you are having any issues, don't hesitate to ask for help! Reply to - this email or join Discord https://alemayhu.com/discord -

-

Thank you!

-

Alexander Alemayhu Developer of 2anki.net

-
-

- If you did not create an account, please contact me - alexander@alemayhu.com. -

-
-
- - diff --git a/src/lib/misc/TokenHandler.ts b/src/lib/misc/TokenHandler.ts index 902d17a02..eafc3e445 100644 --- a/src/lib/misc/TokenHandler.ts +++ b/src/lib/misc/TokenHandler.ts @@ -84,10 +84,6 @@ class TokenHandler { return crypto.randomBytes(64).toString('hex'); } - static NewVerificationToken(): string { - return crypto.randomBytes(64).toString('hex'); - } - static async IsValidResetToken(token: string): Promise { if (!token || token.length < 128) { return false; @@ -97,24 +93,6 @@ class TokenHandler { return user && user.reset_token; } - static async IsValidVerificationToken(token: string): Promise { - if (!token || token.length < 128) { - return false; - } - const user = await DB('users') - .where({ - verification_token: token, - }) - .first(); - if (user) { - console.debug('found user with verification token'); - } else { - console.debug('no user with verification token'); - } - /* @ts-ignore */ - return user && user.verification_token; - } - static async IsValidJWTToken(token: string): Promise { if (!token) { return false; diff --git a/src/routes/users/index.ts b/src/routes/users/index.ts index ef0b131e2..8cf9cd33f 100644 --- a/src/routes/users/index.ts +++ b/src/routes/users/index.ts @@ -79,21 +79,6 @@ router.post('/forgot-password', async (req, res, next) => { } }); -router.get('/v/:id', async (req, res, next) => { - console.debug(`verify user ${req.params.id}`); - const valid = await TokenHandler.IsValidVerificationToken(req.params.id); - if (!valid) { - console.debug('invalid verification token'); - return res.redirect('/login#login'); - } - const token = req.params.id; - DB('users') - .where({ verification_token: token }) - .update({ verified: true }) - .then(() => res.redirect('/search')) - .catch((err) => next(err)); -}); - router.get('/logout', RequireAuthentication, async (req, res, next) => { const { token } = req.cookies; res.clearCookie('token'); @@ -171,17 +156,14 @@ router.post('/register', async (req, res, next) => { const password = hashPassword(req.body.password); const { name } = req.body; const email = req.body.email.toLowerCase(); - const token = TokenHandler.NewVerificationToken(); try { await DB('users') .insert({ name, password, email, - verification_token: token, }) .returning(['id']); - await EmailHandler.SendVerificationEmail(email, token); res.status(200).json({ message: 'ok' }); } catch (error) { captureException(error);