-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release and updated version
- Loading branch information
Showing
160 changed files
with
4,051 additions
and
754 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace BookStack\Console\Commands; | ||
|
||
use BookStack\Repos\UserRepo; | ||
use Illuminate\Console\Command; | ||
|
||
class CreateAdmin extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'bookstack:create-admin | ||
{--email= : The email address for the new admin user} | ||
{--name= : The name of the new admin user} | ||
{--password= : The password to assign to the new admin user}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Add a new admin user to the system'; | ||
|
||
protected $userRepo; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @param UserRepo $userRepo | ||
*/ | ||
public function __construct(UserRepo $userRepo) | ||
{ | ||
$this->userRepo = $userRepo; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
* @throws \BookStack\Exceptions\NotFoundException | ||
*/ | ||
public function handle() | ||
{ | ||
$email = trim($this->option('email')); | ||
if (empty($email)) { | ||
$email = $this->ask('Please specify an email address for the new admin user'); | ||
} | ||
if (strlen($email) < 5 || !filter_var($email, FILTER_VALIDATE_EMAIL)) { | ||
return $this->error('Invalid email address provided'); | ||
} | ||
|
||
if ($this->userRepo->getByEmail($email) !== null) { | ||
return $this->error('A user with the provided email already exists!'); | ||
} | ||
|
||
$name = trim($this->option('name')); | ||
if (empty($name)) { | ||
$name = $this->ask('Please specify an name for the new admin user'); | ||
} | ||
if (strlen($name) < 2) { | ||
return $this->error('Invalid name provided'); | ||
} | ||
|
||
$password = trim($this->option('password')); | ||
if (empty($password)) { | ||
$password = $this->secret('Please specify a password for the new admin user'); | ||
} | ||
if (strlen($password) < 5) { | ||
return $this->error('Invalid password provided, Must be at least 5 characters'); | ||
} | ||
|
||
|
||
$user = $this->userRepo->create(['email' => $email, 'name' => $name, 'password' => $password]); | ||
$this->userRepo->attachSystemRole($user, 'admin'); | ||
$this->userRepo->downloadGravatarToUserAvatar($user); | ||
$user->email_confirmed = true; | ||
$user->save(); | ||
|
||
$this->info("Admin account with email \"{$user->email}\" successfully created!"); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
namespace BookStack\Console\Commands; | ||
|
||
use BookStack\User; | ||
use BookStack\Repos\UserRepo; | ||
use Illuminate\Console\Command; | ||
|
||
class DeleteUsers extends Command | ||
{ | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'bookstack:delete-users'; | ||
|
||
protected $user; | ||
|
||
protected $userRepo; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete users that are not "admin" or system users.'; | ||
|
||
public function __construct(User $user, UserRepo $userRepo) | ||
{ | ||
$this->user = $user; | ||
$this->userRepo = $userRepo; | ||
parent::__construct(); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$confirm = $this->ask('This will delete all users from the system that are not "admin" or system users. Are you sure you want to continue? (Type "yes" to continue)'); | ||
$numDeleted = 0; | ||
if (strtolower(trim($confirm)) === 'yes') { | ||
$totalUsers = $this->user->count(); | ||
$users = $this->user->where('system_name', '=', null)->with('roles')->get(); | ||
foreach ($users as $user) { | ||
if ($user->hasSystemRole('admin')) { | ||
// don't delete users with "admin" role | ||
continue; | ||
} | ||
$this->userRepo->destroy($user); | ||
++$numDeleted; | ||
} | ||
$this->info("Deleted $numDeleted of $totalUsers total users."); | ||
} else { | ||
$this->info('Exiting...'); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<?php namespace BookStack; | ||
|
||
|
||
class EntityPermission extends Model | ||
{ | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php namespace BookStack\Exceptions; | ||
|
||
class AuthException extends PrettyException | ||
{ | ||
|
||
class AuthException extends PrettyException {} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php namespace BookStack\Exceptions; | ||
|
||
class ConfirmationEmailException extends NotifyException | ||
{ | ||
|
||
class ConfirmationEmailException extends NotifyException {} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php namespace BookStack\Exceptions; | ||
|
||
class FileUploadException extends PrettyException | ||
{ | ||
|
||
class FileUploadException extends PrettyException {} | ||
} |
Oops, something went wrong.