Changeset c80e78b in Klonkt for src/routes/account.js


Ignore:
Timestamp:
06/14/2026 04:39:57 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
ae924a2
Parents:
89d6536
Message:

auth: replace username/password with Google login

Listeners (and the owner) now log in via Google instead of a local
username/password account. This lowers the barrier to commenting and
removes the home-built password/registration system.

  • src/config/google.js: raw OAuth2 helpers (authorize/token/userinfo) via the built-in fetch, config-driven. Boot keeps working without credentials.
  • src/routes/auth.js: /auth/google + /auth/google/callback (find-or-create user on email, ADMIN_EMAIL -> god, set session). login/register/reset POST handlers removed; /login now shows the Google button.
  • database.js: idempotent column users.google_sub.
  • account.js + account.ejs: change-password removed.
  • auth-login.ejs / welcome.ejs: Google button instead of password form.
  • shared-styles.ejs: .btn-google styling.
  • .env.example: GOOGLE_CLIENT_ID/SECRET/REDIRECT_URI + ADMIN_EMAIL.

Existing users are matched on email (owner retains their site).
DO NOT deploy to roboburr until the Google credentials are in .env, otherwise
the owner locks themselves out.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/account.js

    r89d6536 rc80e78b  
    1717import fs from 'fs';
    1818import { fileURLToPath } from 'url';
    19 import bcrypt from 'bcryptjs';
    2019import multer from 'multer';
    2120import { v4 as uuid } from 'uuid';
     
    8483// longer read or written.
    8584
    86 // ==================== CHANGE PASSWORD ====================
    87 router.post('/password', requireAuth, (req, res) => {
    88   const { current, new_password, confirm } = req.body;
    89   if (!current || !new_password || !confirm) {
    90     return res.redirect('/account?error=' + encodeURIComponent('All password fields required'));
    91   }
    92   if (new_password.length < 8) {
    93     return res.redirect('/account?error=' + encodeURIComponent('New password must be at least 8 characters'));
    94   }
    95   if (new_password !== confirm) {
    96     return res.redirect('/account?error=' + encodeURIComponent('New passwords do not match'));
    97   }
    98 
    99   const row = db.prepare('SELECT password_hash FROM users WHERE id = ?').get(req.session.user.id);
    100   if (!row || !bcrypt.compareSync(current, row.password_hash)) {
    101     return res.redirect('/account?error=' + encodeURIComponent('Current password is incorrect'));
    102   }
    103 
    104   const newHash = bcrypt.hashSync(new_password, 10);
    105   db.prepare('UPDATE users SET password_hash = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?')
    106     .run(newHash, req.session.user.id);
    107 
    108   res.redirect('/account?success=' + encodeURIComponent('Password changed'));
    109 });
     85// Wachtwoord-wijzigen is verwijderd: inloggen gaat sinds de Google-OAuth-migratie
     86// volledig via Google, er is geen wachtwoord meer om te wijzigen.
    11087
    11188// ==================== UPLOAD AVATAR ====================
Note: See TracChangeset for help on using the changeset viewer.