forked from LycheeOrg/Lychee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create admin during installation, allow multiple admins (LycheeOrg#1602)
- Loading branch information
Showing
73 changed files
with
1,017 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Actions\User\Create; | ||
use App\Contracts\Exceptions\ExternalLycheeException; | ||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
|
||
class CreateUser extends Command | ||
{ | ||
private Create $create; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = | ||
'lychee:create_user' . | ||
'{username : username of the new user} ' . | ||
'{password : password of the new user} ' . | ||
'{--may-edit-own-settings : user can edit own settings} ' . | ||
'{--may-upload : user may upload} ' . | ||
'{--may-administrate : user is an admin} '; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new user with the given username and password. If no user exists yet, this user will be an admin.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct(Create $create) | ||
{ | ||
parent::__construct(); | ||
$this->create = $create; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
* | ||
* @throws ExternalLycheeException | ||
*/ | ||
public function handle(): int | ||
{ | ||
$username = strval($this->argument('username')); | ||
$password = strval($this->argument('password')); | ||
|
||
$count = User::query()->count(); | ||
|
||
$mayAdministrate = $count < 1 || $this->option('may-administrate') === true; | ||
$mayEditOwnSettings = $mayAdministrate || $this->option('may-edit-own-settings') === true; | ||
$mayUpload = $mayAdministrate || $this->option('may-upload') === true; | ||
|
||
$user = $this->create->do($username, $password, $mayUpload, $mayEditOwnSettings); | ||
$user->may_administrate = $mayAdministrate; | ||
$user->save(); | ||
|
||
$this->line(sprintf('Successfully created%s user %s ', $mayAdministrate ? ' admin' : '', $username)); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Contracts\Exceptions\ExternalLycheeException; | ||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UpdateUser extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = | ||
'lychee:update_user' . | ||
'{username : username of the user} ' . | ||
'{password : password of the user} '; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update the user with the given username.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
* | ||
* @throws ExternalLycheeException | ||
*/ | ||
public function handle(): int | ||
{ | ||
$username = strval($this->argument('username')); | ||
|
||
/** @var User|null $user */ | ||
$user = User::query()->where('username', '=', $username)->first(); | ||
|
||
if ($user === null) { | ||
$this->error('user not found'); | ||
|
||
return 1; | ||
} | ||
|
||
$password = strval($this->argument('password')); | ||
|
||
if ($password !== '') { | ||
$user->password = Hash::make($password); | ||
$user->save(); | ||
|
||
$this->line('Successfully updated user ' . $username); | ||
|
||
return 0; | ||
} | ||
|
||
$this->error('wrong password'); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.