Login & User Role - 1
This commit is contained in:
33
scripts/list-users.ts
Normal file
33
scripts/list-users.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function listUsers() {
|
||||
try {
|
||||
const users = await prisma.user.findMany({
|
||||
include: {
|
||||
role: true
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Daftar Pengguna:');
|
||||
console.log('================');
|
||||
|
||||
users.forEach((user, index) => {
|
||||
console.log(`\n[${index + 1}] ${user.nama} (${user.email})`);
|
||||
console.log(` Role: ${user.role.name} (${user.role.id})`);
|
||||
console.log(` Status: ${user.isActive ? 'Aktif' : 'Tidak Aktif'}`);
|
||||
console.log(` Terakhir Login: ${user.lastLogin || 'Belum pernah login'}`);
|
||||
console.log(` Dibuat pada: ${user.createdAt}`);
|
||||
});
|
||||
|
||||
console.log('\nTotal pengguna:', users.length);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
listUsers();
|
||||
39
scripts/reset-passwords.ts
Normal file
39
scripts/reset-passwords.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function resetPasswords() {
|
||||
try {
|
||||
// Password to set for all users
|
||||
const newPassword = 'password123';
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
|
||||
// Get all users
|
||||
const users = await prisma.user.findMany();
|
||||
|
||||
console.log('Resetting passwords for all users...');
|
||||
|
||||
// Update each user's password
|
||||
for (const user of users) {
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
password: hashedPassword,
|
||||
isActive: true // Ensure all users are active
|
||||
}
|
||||
});
|
||||
console.log(`✅ Reset password for ${user.email}`);
|
||||
}
|
||||
|
||||
console.log('\nSemua password telah direset ke: password123');
|
||||
console.log('Silakan login dengan email yang ada dan password: password123');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
resetPasswords();
|
||||
Reference in New Issue
Block a user