Changeset 9e27d64 in Klonkt for src/routes/account.js
- Timestamp:
- 06/14/2026 07:31:23 AM (3 months ago)
- Branches:
- main
- Children:
- 6351545
- Parents:
- 32cc601
- File:
-
- 1 edited
-
src/routes/account.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/account.js
r32cc601 r9e27d64 17 17 import fs from 'fs'; 18 18 import { fileURLToPath } from 'url'; 19 import bcrypt from 'bcryptjs'; 19 20 import multer from 'multer'; 20 21 import { v4 as uuid } from 'uuid'; … … 56 57 router.get('/', requireAuth, (req, res) => { 57 58 const account = db.prepare(` 58 SELECT id, username, email, role, bio, avatar_url, created_at 59 SELECT id, username, email, role, bio, avatar_url, created_at, password_hash 59 60 FROM users WHERE id = ? 60 61 `).get(req.session.user.id); 62 const hasPassword = !!(account && account.password_hash && account.password_hash !== '!google-oauth'); 63 if (account) delete account.password_hash; // niet naar de view lekken 61 64 62 65 renderPage(req, res, 'pages/account', { … … 64 67 bodyClass: 'on-special', 65 68 account, 69 hasPassword, 66 70 success: req.query.success || null, 67 71 error: req.query.error || null, … … 83 87 // longer read or written. 84 88 85 // Wachtwoord-wijzigen is verwijderd: inloggen gaat sinds de Google-OAuth-migratie 86 // volledig via Google, er is geen wachtwoord meer om te wijzigen. 89 // ==================== CHANGE PASSWORD ==================== 90 router.post('/password', requireAuth, (req, res) => { 91 const { current, new_password, confirm } = req.body; 92 if (!current || !new_password || !confirm) { 93 return res.redirect('/account?error=' + encodeURIComponent('Alle wachtwoordvelden zijn verplicht')); 94 } 95 if (new_password.length < 8) { 96 return res.redirect('/account?error=' + encodeURIComponent('Nieuw wachtwoord moet minstens 8 tekens zijn')); 97 } 98 if (new_password !== confirm) { 99 return res.redirect('/account?error=' + encodeURIComponent('Nieuwe wachtwoorden komen niet overeen')); 100 } 101 102 const row = db.prepare('SELECT password_hash FROM users WHERE id = ?').get(req.session.user.id); 103 // Google-only accounts (luisteraars) hebben geen echt wachtwoord. 104 if (!row || !row.password_hash || row.password_hash === '!google-oauth') { 105 return res.redirect('/account?error=' + encodeURIComponent('Dit account heeft geen wachtwoord (Google-login)')); 106 } 107 if (!bcrypt.compareSync(current, row.password_hash)) { 108 return res.redirect('/account?error=' + encodeURIComponent('Huidig wachtwoord is onjuist')); 109 } 110 111 const newHash = bcrypt.hashSync(new_password, 10); 112 db.prepare('UPDATE users SET password_hash = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?') 113 .run(newHash, req.session.user.id); 114 115 res.redirect('/account?success=' + encodeURIComponent('Wachtwoord gewijzigd')); 116 }); 87 117 88 118 // ==================== UPLOAD AVATAR ====================
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)