mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
Implement more validation in installer
This commit is contained in:
parent
b05f83d25a
commit
3b5a01e603
|
@ -11,12 +11,14 @@
|
||||||
namespace Flarum\Install\Console;
|
namespace Flarum\Install\Console;
|
||||||
|
|
||||||
use Flarum\Console\Command;
|
use Flarum\Console\Command;
|
||||||
|
use Flarum\Core\Exceptions\ValidationException;
|
||||||
use Flarum\Core\Model;
|
use Flarum\Core\Model;
|
||||||
use Flarum\Core\Users\User;
|
use Flarum\Core\Users\User;
|
||||||
use Flarum\Core\Groups\Group;
|
use Flarum\Core\Groups\Group;
|
||||||
use Flarum\Core\Groups\Permission;
|
use Flarum\Core\Groups\Permission;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Validation\Factory;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -128,6 +130,23 @@ class InstallCommand extends Command
|
||||||
protected function storeConfiguration()
|
protected function storeConfiguration()
|
||||||
{
|
{
|
||||||
$dbConfig = $this->dataSource->getDatabaseConfiguration();
|
$dbConfig = $this->dataSource->getDatabaseConfiguration();
|
||||||
|
$baseUrl = $this->dataSource->getBaseUrl();
|
||||||
|
|
||||||
|
$validation = $this->getValidator()->make(
|
||||||
|
$dbConfig,
|
||||||
|
[
|
||||||
|
'driver' => 'required|in:mysql',
|
||||||
|
'host' => 'required',
|
||||||
|
'database' => 'required|alpha_dash',
|
||||||
|
'username' => 'required|alpha_dash',
|
||||||
|
'password' => 'required',
|
||||||
|
'prefix' => 'alpha_dash|max:10'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($validation->fails()) {
|
||||||
|
throw new ValidationException($validation->getMessageBag()->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
$config = [
|
$config = [
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
|
@ -142,7 +161,7 @@ class InstallCommand extends Command
|
||||||
'prefix' => $dbConfig['prefix'],
|
'prefix' => $dbConfig['prefix'],
|
||||||
'strict' => false
|
'strict' => false
|
||||||
],
|
],
|
||||||
'url' => $this->dataSource->getBaseUrl(),
|
'url' => $baseUrl,
|
||||||
'paths' => [
|
'paths' => [
|
||||||
'api' => 'api',
|
'api' => 'api',
|
||||||
'admin' => 'admin',
|
'admin' => 'admin',
|
||||||
|
@ -254,11 +273,13 @@ class InstallCommand extends Command
|
||||||
|
|
||||||
$this->info('Creating admin user '.$admin['username']);
|
$this->info('Creating admin user '.$admin['username']);
|
||||||
|
|
||||||
User::unguard();
|
$user = User::register(
|
||||||
|
$admin['username'],
|
||||||
|
$admin['email'],
|
||||||
|
$admin['password']
|
||||||
|
);
|
||||||
|
|
||||||
$user = new User(Arr::except($admin, 'password_confirmation'));
|
|
||||||
$user->is_activated = 1;
|
$user->is_activated = 1;
|
||||||
$user->join_time = time();
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$user->groups()->sync([1]);
|
$user->groups()->sync([1]);
|
||||||
|
@ -300,6 +321,14 @@ class InstallCommand extends Command
|
||||||
return $this->application->make('Flarum\Install\Prerequisites\Prerequisite');
|
return $this->application->make('Flarum\Install\Prerequisites\Prerequisite');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Contracts\Validation\Factory
|
||||||
|
*/
|
||||||
|
protected function getValidator()
|
||||||
|
{
|
||||||
|
return new Factory($this->application->make('Symfony\Component\Translation\TranslatorInterface'));
|
||||||
|
}
|
||||||
|
|
||||||
protected function showErrors($errors)
|
protected function showErrors($errors)
|
||||||
{
|
{
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user