Changeset 247988e in Klonkt for src/routes/account.js
- Timestamp:
- 06/19/2026 09:55:26 AM (3 months ago)
- Branches:
- main
- Children:
- f33b24a
- Parents:
- 535f955
- File:
-
- 1 edited
-
src/routes/account.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/account.js
r535f955 r247988e 24 24 import { renderPage } from '../middleware/render.js'; 25 25 import { requireAuth } from '../middleware/auth.js'; 26 import { googleConfigured } from '../config/google.js'; 26 27 27 28 const __dirname = path.dirname(fileURLToPath(import.meta.url)); … … 58 59 router.get('/', requireAuth, (req, res) => { 59 60 const account = db.prepare(` 60 SELECT id, username, email, role, bio, avatar_url, created_at, password_hash 61 SELECT id, username, email, role, bio, avatar_url, created_at, password_hash, google_sub 61 62 FROM users WHERE id = ? 62 63 `).get(req.session.user.id); 63 64 const hasPassword = !!(account && account.password_hash && account.password_hash !== '!google-oauth'); 64 if (account) delete account.password_hash; // niet naar de view lekken 65 const googleLinked = !!(account && account.google_sub); 66 if (account) { delete account.password_hash; delete account.google_sub; } // niet naar de view lekken 65 67 66 68 renderPage(req, res, 'pages/account', { … … 69 71 account, 70 72 hasPassword, 73 googleLinked, 74 googleAvailable: googleConfigured(), 71 75 editableSite: ownedSite(req.session.user), 72 76 success: req.query.success || null, … … 144 148 }); 145 149 150 // Google-account ontkoppelen. Alleen toegestaan als er nog een wachtwoord is, 151 // anders zou je jezelf buitensluiten (geen login-methode meer over). 152 router.post('/google/unlink', requireAuth, (req, res) => { 153 const row = db.prepare('SELECT password_hash, google_sub FROM users WHERE id = ?').get(req.session.user.id); 154 if (!row || !row.google_sub) { 155 return res.redirect('/account?error=' + encodeURIComponent('Er is geen Google-account gekoppeld')); 156 } 157 if (!row.password_hash || row.password_hash === '!google-oauth') { 158 return res.redirect('/account?error=' + encodeURIComponent('Stel eerst een wachtwoord in — anders kun je niet meer inloggen.')); 159 } 160 db.prepare('UPDATE users SET google_sub = NULL, updated_at = CURRENT_TIMESTAMP WHERE id = ?').run(req.session.user.id); 161 res.redirect('/account?success=' + encodeURIComponent('Google-account ontkoppeld')); 162 }); 163 146 164 // ==================== UPLOAD AVATAR ==================== 147 165 router.post('/avatar', requireAuth, (req, res) => {
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)