Add password change routes to backend and frontend; update routing and UI components for password management
This commit is contained in:
71
backend/set-password.js
Normal file
71
backend/set-password.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Script zum Setzen eines neuen Passworts für einen User
|
||||
* Verwendung: node set-password.js <user_id> <neues_passwort>
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const bcrypt = require('bcrypt');
|
||||
const database = require('./src/config/database');
|
||||
|
||||
async function setPassword(userId, newPassword) {
|
||||
try {
|
||||
// Datenbank initialisieren
|
||||
await database.initialize();
|
||||
|
||||
const { User, AuthInfo } = database.getModels();
|
||||
|
||||
// Hole User
|
||||
const user = await User.findByPk(userId, {
|
||||
include: [
|
||||
{
|
||||
model: AuthInfo,
|
||||
as: 'authInfo',
|
||||
required: true
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if (!user || !user.authInfo) {
|
||||
console.error(`❌ User ${userId} oder AuthInfo nicht gefunden`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Hash Passwort
|
||||
console.log('🔐 Hashe Passwort...');
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
|
||||
// Aktualisiere Passwort
|
||||
user.authInfo.password_hash = hashedPassword;
|
||||
await user.authInfo.save();
|
||||
|
||||
console.log(`✅ Passwort für User ${userId} (${user.full_name}) erfolgreich gesetzt!`);
|
||||
console.log(` Email: ${user.authInfo.email}`);
|
||||
|
||||
// Schließe Datenbankverbindung
|
||||
await database.close();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('❌ Fehler beim Setzen des Passworts:', error.message);
|
||||
await database.close();
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Argumente prüfen
|
||||
const userId = parseInt(process.argv[2]);
|
||||
const newPassword = process.argv[3];
|
||||
|
||||
if (!userId || !newPassword) {
|
||||
console.log('Verwendung: node set-password.js <user_id> <neues_passwort>');
|
||||
console.log('Beispiel: node set-password.js 1 MeinNeuesPasswort123');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (newPassword.length < 6) {
|
||||
console.error('❌ Passwort muss mindestens 6 Zeichen lang sein');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Passwort setzen
|
||||
setPassword(userId, newPassword);
|
||||
|
||||
Reference in New Issue
Block a user