Compare commits

...

2 commits

3 changed files with 79 additions and 26 deletions

63
conf/CreateUser.php Normal file
View file

@ -0,0 +1,63 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
class CreateUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:create-user
{name : The username of the user}
{email : The email of the user}
{password : Password in plain text (will be encrypted automatically)}
{--unverified : Keep the user unverified. Otherwise, email verified will be set at current time.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a user to access the admin panel';
private array $rules = [
'name' => ['required', 'min:4', 'unique:users,name'],
'email' => ['required', 'email', 'unique:users,email'],
'password' => ['required', 'min:6'],
];
/**
* Execute the console command.
*/
public function handle(): int
{
$validator = Validator::make([
'name' => $this->argument('name'),
'email' => $this->argument('email'),
'password' => $this->argument('password'),
], $this->rules);
try {
$userData = $validator->validated();
$userData['password'] = bcrypt($userData['password']);
$userData['email_verified_at'] = $this->option('unverified') ? NULL : now();
User::factory()->create($userData);
$this->info('User created.');
} catch (\Exception $e) {
$this->error("ERROR: {$e->getMessage()} [Code: {$e->getCode()}]");
return 1;
}
return 0;
}
}

View file

@ -4,7 +4,7 @@ packaging_format = 2
id = "my_idlers"
name = "My Idlers"
description.en = "A self-hosted web app for displaying, organizing and storing information about your servers (VPS/Dedi), shared & reseller hosting, seedboxes, domains, DNS and misc services."
description.en = "A self-hosted web app for displaying, organizing and storing information about your servers (VPS/Dedi), shared & reseller hosting, seedboxes, domains, DNS and misc services. Are you the person in your family, group of friends or at work who keeps an eye on everyones Yunohosts, then this is the app to help you."
description.fr = "Une application Web auto-hébergée pour afficher, organiser et stocker des informations sur vos serveurs (VPS/Dedi), votre hébergement partagé et revendeur, vos seedboxes, vos domaines, vos DNS et divers services."
version = "3.0~ynh1"
@ -46,12 +46,16 @@ ram.runtime = "100M"
default = "all_users"
# for now no credentials configured, make it install first
# [install.admin]
# type = "user"
# [install.password]
# help.en = "Use the help field to add an information for the admin about this question."
# help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
# type = "password"
[install.name]
help.en = "The name of the user"
type = "text"
[install.email]
help.en = "The email address used for logging in to the application"
type = "email"
[install.password]
help.en = "Use the help field to add an information for the admin about this question."
help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
type = "password"
[resources]
# See the packaging documentation for the full set

View file

@ -44,6 +44,9 @@ ynh_config_add --template=.env --destination="$install_dir/.env"
chmod 640 "$install_dir/.env"
chown "$app:www-data" "$install_dir/.env"
# Inject CreateUser.php into app/Console/Commands/ to extend the upstream version with this functionality
# Using this, we can create the user with the credentials provided
ynh_config_add --template=CreateUser.php --destination="$install_dir/app/Console/Commands/CreateUser.php"
#=================================================
# SYSTEM CONFIGURATION
@ -97,7 +100,7 @@ pushd "$install_dir"
"php$php_version" artisan migrate:fresh --seed -n --force
"php$php_version" artisan config:clear -n
"php$php_version" artisan config:cache -n
#"php$php_version" artisan lychee:create_user "$admin" "$password"
"php$php_version" artisan app:create-user "$name" "$email" "$password"
popd
@ -122,24 +125,7 @@ chmod -R 2775 "$install_dir/storage" "$install_dir/app" "$install_dir/public" "$
# Installation with curl
ynh_script_progression "Finalizing installation..."
#ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression "Starting $app's systemd service..."
### `ynh_systemctl` is used to start a systemd service for an app.
### Only needed if you have configure a systemd service
### If you're not using these lines:
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
### - As well as the section "START SYSTEMD SERVICE" in the restore script
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
# Start a systemd service
ynh_systemctl --service="nginx" --action="reload"
ynh_systemctl --service="php$php_version-fpm" --action="reload"
#ynh_local_curl "/INSTALL_PATH" "key1=$name" "key2=$email" "key3=$password" "key4=$password"
#=================================================
# END OF SCRIPT