Files
2026-09-01 10:46:29 -03:00

79 lines
2.6 KiB
PHP
Executable File

<?php
/**
* SysCMS - Content Management System
*
* Copyright (c) 2025 Marco Costa
* All rights reserved.
*
* Author: Marco Costa
* Email: contato@syspanel.com.br
* Project: SysCMS
*
* This software is licensed, not sold.
* Permission is granted to use this software
* subject to the terms of the SysCMS Commercial License.
*
* Redistribution, sublicensing, resale, or
* disclosure of this software, in whole or in part,
* is strictly prohibited without prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*/
namespace App\Console\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Modules\Auth\Models\User;
use Carbon\Carbon;
class CreateSuperAdminCommand extends Command
{
protected static $defaultName = 'user:create-super-admin';
protected static $defaultDescription = 'Creates the default Super Admin user';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$email = 'superadmin@syscms.com';
$password = 'SuperAdmin123!';
try {
// Remove global scopes to ensure we can find the user regardless of company context
$user = User::withoutGlobalScopes()->where('users_email', $email)->first();
if ($user) {
$user->users_role = 'super_admin';
$user->users_password = password_hash($password, PASSWORD_DEFAULT);
$user->users_status = 'active';
$user->save();
$output->writeln('<info>Usuário Super Admin atualizado com sucesso!</info>');
} else {
$user = new User();
$user->users_name = 'Super Admin';
$user->users_email = $email;
$user->users_password = password_hash($password, PASSWORD_DEFAULT);
$user->users_role = 'super_admin';
$user->users_status = 'active';
$user->save();
$output->writeln('<info>Usuário Super Admin criado com sucesso!</info>');
}
$output->writeln([
'',
'Credenciais:',
"Email: $email",
"Senha: $password",
"Role: super_admin",
''
]);
return Command::SUCCESS;
} catch (\Exception $e) {
$output->writeln("<error>Erro: " . $e->getMessage() . "</error>");
return Command::FAILURE;
}
}
}