tududi/backend/scripts/user-create.js
Chris 03f38f05dc
Setup intelligence (#84)
* Add next suggestions and remove console logs

* Add pomodoro timer

* Add pomodoro switch in settings

* Fix pomodoro setting

* Add timezones to settings

* Fix an issue with password reset

* Cleanup

* Sort tags alphabetically

* Clean up today's view

* Add an indicator for repeatedly added to today

* Refactor tags

* Add due date today item

* Move recurrence to the subtitle area

* Fix today layout

* Add a badge to Inbox items

* Move inbox badge to sidebar

* Add quotes and progress bar

* Add translations for quotes

* Fix test issues

* Add helper script for docker local

* Set up overdue tasks

* Add  linux/arm/v7 build to deploy script

* Add  linux/arm/v7 build to deploy script pt2

* Fix an issue with helmet and SSL

* Add volume db persistence

* Fix cog icon issues
2025-06-27 14:02:18 +03:00

77 lines
No EOL
2.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
/**
* User Creation Script
* Creates a new user with email and password
* Usage: node user-create.js <email> <password>
*/
require('dotenv').config();
const { User } = require('../models');
const bcrypt = require('bcrypt');
async function createUser() {
const [email, password] = process.argv.slice(2);
if (!email || password === undefined) {
console.error('❌ Usage: npm run user:create <email> <password>');
console.error('Example: npm run user:create admin@example.com mypassword123');
process.exit(1);
}
// Basic password validation (check for empty or short passwords)
if (!password || password.length < 6) {
console.error('❌ Password must be at least 6 characters long');
process.exit(1);
}
// Enhanced email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
// Check for common invalid patterns
if (!email.includes('@') ||
!email.includes('.') ||
email.includes('@@') ||
email.includes(' ') ||
email.startsWith('@') ||
email.endsWith('@') ||
email.endsWith('.') ||
email.includes('@.') ||
email.includes('.@') ||
!emailRegex.test(email)) {
console.error('❌ Invalid email format');
process.exit(1);
}
try {
console.log(`Creating user with email: ${email}`);
// Check if user already exists
const existingUser = await User.findOne({ where: { email } });
if (existingUser) {
console.error(`❌ User with email ${email} already exists`);
process.exit(1);
}
// Hash the password manually since the hook might not be working in this context
const hashedPassword = await bcrypt.hash(password, 10);
// Create the user
const user = await User.create({
email,
password_digest: hashedPassword
});
console.log('✅ User created successfully');
console.log(`📧 Email: ${user.email}`);
console.log(`🆔 User ID: ${user.id}`);
console.log(`📅 Created: ${user.created_at}`);
process.exit(0);
} catch (error) {
console.error('❌ Error creating user:', error.message);
process.exit(1);
}
}
createUser();