Commit 43a56a34 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/Core/' changes from 0a5e9bc..8d6a3d5

8d6a3d5 rename composer file
ba484e8 Change theme name in config
edf4dd1 Add mpedrera/themify configuration
a5e2dee Remove profile link
691549d Add view website link
671d718 Remove unused class import
a21fb88 Remove commented code
1804be7 Merge pull request #12 from AsgardCms/modify-install-cmd
a7c6c98 Only hash the password for sentinel
2c69c34 Using the schema to check installation
5aede0f Merge pull request #11 from AsgardCms/sentry-installation
fc586fc Add some docblocks
fd914db Add a check if the platform has already been installed
8805317 Removing unused class property
25604c9 set the correct default choice. Add a first pass at the Sentry installation
36f224d Publish required package configurations
cea9fda Finish the Sentinel installation implementation
69f0c5f Add remove method. add output handler
f60d05d Inject the new composer class
39ec942 Prepare first pass at file search and replaces
0d76121 Inject $app instance to console command
b5dbb80 add a composer helper to install
2ed8d61 Merge pull request #10 from AsgardCms/correct-user-role
fc38935 Attach the correct role to the user
8a92489 Change role name

git-subtree-dir: Modules/Core
git-subtree-split: 8d6a3d5ef012fd193605d5c902c19bd205bbe0ad
parent 337ca737
<?php namespace Modules\Core\Services;
use Symfony\Component\Process\Process;
class Composer extends \Illuminate\Foundation\Composer
{
protected $outputHandler = null;
private $output;
/**
* Enable real time output of all commands.
*
* @param $command
* @return void
*/
public function enableOutput($command)
{
$this->output = function ($type, $buffer) use ($command) {
if (Process::ERR === $type) {
$command->info(trim('[ERR] > '.$buffer));
} else {
$command->info(trim('> '.$buffer));
}
};
}
/**
* Disable real time output of all commands.
*
* @return void
*/
public function disableOutput()
{
$this->output = null;
}
/**
* Update all composer packages.
*
* @param string $package
* @return void
*/
public function update($package = null)
{
if (!is_null($package)) {
$package = '"' . $package . '"';
}
$process = $this->getProcess();
$process->setCommandLine(trim($this->findComposer() . ' update ' . $package));
$process->run($this->output);
}
/**
* Require a new composer package.
*
* @param string $package
* @return void
*/
public function install($package)
{
if (!is_null($package)) {
$package = '"' . $package . '"';
}
$process = $this->getProcess();
$process->setCommandLine(trim($this->findComposer() . ' require ' . $package));
$process->run($this->output);
}
public function remove($package)
{
if (!is_null($package)) {
$package = '"' . $package . '"';
}
$process = $this->getProcess();
$process->setCommandLine(trim($this->findComposer() . ' remove ' . $package));
$process->run($this->output);
}
}
...@@ -19,7 +19,7 @@ return [ ...@@ -19,7 +19,7 @@ return [
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
'front-themes' => [ 'front-themes' => [
'bootstrap', 'demo',
'default' 'default'
] ]
]; ];
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
use Dotenv; use Dotenv;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Modules\User\Repositories\UserRepository; use Illuminate\Support\Facades\Schema;
use Modules\Core\Services\Composer;
class InstallCommand extends Command class InstallCommand extends Command
{ {
...@@ -22,28 +24,32 @@ class InstallCommand extends Command ...@@ -22,28 +24,32 @@ class InstallCommand extends Command
*/ */
protected $description = 'Install Asgard CMS'; protected $description = 'Install Asgard CMS';
/**
* @var UserRepository
*/
private $user;
/** /**
* @var Filesystem * @var Filesystem
*/ */
private $finder; private $finder;
/**
* @var Application
*/
private $app;
/**
* @var Composer
*/
private $composer;
/** /**
* Create a new command instance. * Create a new command instance.
* *
* @param UserRepository $user
* @param Filesystem $finder * @param Filesystem $finder
* @return \Modules\Core\Console\InstallCommand * @param Application $app
* @param Composer $composer
*/ */
public function __construct($user, Filesystem $finder) public function __construct(Filesystem $finder, Application $app, Composer $composer)
{ {
parent::__construct(); parent::__construct();
$this->user = $user;
$this->finder = $finder; $this->finder = $finder;
$this->app = $app;
$this->composer = $composer;
} }
/** /**
...@@ -55,16 +61,23 @@ class InstallCommand extends Command ...@@ -55,16 +61,23 @@ class InstallCommand extends Command
{ {
$this->info('Starting the installation process...'); $this->info('Starting the installation process...');
if ($this->checkIfInstalled()) {
$this->error('Asgard has already been installed. You can already log into your administration.');
return;
}
$this->configureDatabase(); $this->configureDatabase();
if ($this->confirm('Do you wish to init sentinel and create its first user? [yes|no]')) { $userDriver = $this->choice('Which user driver do you wish to use?', ['Sentinel', 'Sentry'], 1);
$this->runUserCommands(); $userDriver = "run{$userDriver}UserCommands";
} $this->$userDriver();
$this->runMigrations(); $this->runMigrations();
$this->publishAssets(); $this->publishAssets();
$this->publishConfigurations();
$this->blockMessage( $this->blockMessage(
'Success!', 'Success!',
'Platform ready! You can now login with your username and password at /backend' 'Platform ready! You can now login with your username and password at /backend'
...@@ -72,21 +85,53 @@ class InstallCommand extends Command ...@@ -72,21 +85,53 @@ class InstallCommand extends Command
} }
/** /**
* * Run the required commands to use Sentinel
*/ */
private function runUserCommands() private function runSentinelUserCommands()
{ {
$this->info('Requiring Sentinel package, this may take some time...');
$this->handleComposerForSentinel();
$this->info('Running Sentinel migrations...');
$this->runSentinelMigrations(); $this->runSentinelMigrations();
$this->runUserSeeds();
$this->createFirstUser(); $this->info('Running Sentinel seed...');
$this->call('db:seed', ['--class' => 'Modules\User\Database\Seeders\SentinelGroupSeedTableSeeder']);
$this->replaceUserRepositoryBindings('Sentinel');
$this->bindUserRepositoryOnTheFly('Sentinel');
$this->call('publish:config', ['package' => 'cartalyst/sentinel']);
$this->replaceCartalystUserModelConfiguration('Cartalyst\Sentinel\Users\EloquentUser', 'Sentinel');
$this->createFirstUser('sentinel');
$this->info('User commands done.'); $this->info('User commands done.');
} }
/**
* Run the required commands to use Sentry
*/
private function runSentryUserCommands()
{
$this->info('Running Sentry migrations...');
$this->call('migrate', ['--package' => 'cartalyst/sentry']);
$this->info('Running Sentry seed...');
$this->call('db:seed', ['--class' => 'Modules\User\Database\Seeders\SentryGroupSeedTableSeeder']);
$this->call('publish:config', ['package' => 'cartalyst/sentry']);
$this->replaceCartalystUserModelConfiguration('Cartalyst\Sentry\Users\Eloquent\User', 'Sentry');
$this->createFirstUser('sentry');
$this->info('User commands done.');
}
/** /**
* Create the first user that'll have admin access * Create the first user that'll have admin access
*/ */
private function createFirstUser() private function createFirstUser($driver)
{ {
$this->line('Creating an Admin user account...'); $this->line('Creating an Admin user account...');
...@@ -99,9 +144,16 @@ class InstallCommand extends Command ...@@ -99,9 +144,16 @@ class InstallCommand extends Command
'first_name' => $firstname, 'first_name' => $firstname,
'last_name' => $lastname, 'last_name' => $lastname,
'email' => $email, 'email' => $email,
'password' => Hash::make($password),
]; ];
$this->user->createWithRoles($userInfo, ['admin']);
if ($driver == 'sentinel') {
$userInfo = array_merge($userInfo, ['password' => Hash::make($password)]);
} else {
$userInfo = array_merge($userInfo, ['password' => $password]);
}
$user = app('Modules\User\Repositories\UserRepository');
$user->createWithRoles($userInfo, [1], true);
$this->info('Admin account created!'); $this->info('Admin account created!');
} }
...@@ -126,10 +178,28 @@ class InstallCommand extends Command ...@@ -126,10 +178,28 @@ class InstallCommand extends Command
$this->info('Application migrated!'); $this->info('Application migrated!');
} }
private function runUserSeeds() /**
{ *
$this->call('module:seed', ['module' => 'User']); */
} private function publishConfigurations()
{
$this->call('publish:config', ['package' => 'dimsav/laravel-translatable']);
$this->call('publish:config', ['package' => 'mcamara/laravel-localization']);
$this->call('publish:config', ['package' => 'pingpong/modules']);
$this->call('publish:config', ['package' => 'mpedrera/themify']);
$this->adaptThemifyConfiguration();
}
/**
* Configure the mpedrera/themify configuration
* @throws \Illuminate\Filesystem\FileNotFoundException
*/
private function adaptThemifyConfiguration()
{
$themifyConfig = $this->finder->get('config/packages/mpedrera/themify/config.php');
$themifyConfig = str_replace('app_path()', 'base_path()', $themifyConfig);
$this->finder->put('config/packages/mpedrera/themify/config.php', $themifyConfig);
}
/** /**
* Symfony style block messages * Symfony style block messages
...@@ -216,4 +286,97 @@ class InstallCommand extends Command ...@@ -216,4 +286,97 @@ class InstallCommand extends Command
$this->laravel['config']['database.connections.mysql.password'] = $databasePassword; $this->laravel['config']['database.connections.mysql.password'] = $databasePassword;
} }
/**
* Find and replace the correct repository bindings with the given driver
* @param string $driver
* @throws \Illuminate\Filesystem\FileNotFoundException
*/
private function replaceUserRepositoryBindings($driver)
{
$path = 'Modules/User/Providers/UserServiceProvider.php';
$userServiceProvider = $this->finder->get($path);
$userServiceProvider = str_replace('Sentry', $driver, $userServiceProvider);
$this->finder->put($path, $userServiceProvider);
}
/**
* Set the correct repository binding on the fly for the current request
* @param $driver
*/
private function bindUserRepositoryOnTheFly($driver)
{
$this->app->bind(
'Modules\User\Repositories\UserRepository',
"Modules\\User\\Repositories\\$driver\\{$driver}UserRepository"
);
$this->app->bind(
'Modules\User\Repositories\RoleRepository',
"Modules\\User\\Repositories\\$driver\\{$driver}RoleRepository"
);
$this->app->bind(
'Modules\Core\Contracts\Authentication',
"Modules\\User\\Repositories\\$driver\\{$driver}Authentication"
);
}
/**
* Replaced the model in the cartalyst configuration file
* @param string $search
* @param string $Driver
* @throws \Illuminate\Filesystem\FileNotFoundException
*/
private function replaceCartalystUserModelConfiguration($search, $Driver)
{
$driver = strtolower($Driver);
$path = "config/packages/cartalyst/{$driver}/config.php";
$config = $this->finder->get($path);
$config = str_replace($search, "Modules\\User\\Entities\\{$Driver}User", $config);
$this->finder->put($path, $config);
}
/**
* Install sentinel and remove sentry
* Set the required Service Providers and Aliases in config/app.php
* @throws \Illuminate\Filesystem\FileNotFoundException
*/
private function handleComposerForSentinel()
{
$this->composer->enableOutput($this);
$this->composer->install('cartalyst/sentinel:~1.0');
// Search and replace SP and Alias in config/app.php
$appConfig = $this->finder->get('config/app.php');
$appConfig = str_replace(
[
"#'Cartalyst\\Sentinel\\Laravel\\SentinelServiceProvider',",
"'Cartalyst\\Sentry\\SentryServiceProvider',",
"#'Activation' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Activation',",
"#'Reminder' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Reminder',",
"#'Sentinel' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Sentinel',",
"'Sentry' => 'Cartalyst\\Sentry\\Facades\\Laravel\\Sentry',"
],
[
"'Cartalyst\\Sentinel\\Laravel\\SentinelServiceProvider',",
"#'Cartalyst\\Sentry\\SentryServiceProvider',",
"'Activation' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Activation',",
"'Reminder' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Reminder',",
"'Sentinel' => 'Cartalyst\\Sentinel\\Laravel\\Facades\\Sentinel',",
"#'Sentry' => 'Cartalyst\\Sentry\\Facades\\Laravel\\Sentry',"
],
$appConfig
);
$this->finder->put('config/app.php', $appConfig);
$this->composer->remove('cartalyst/sentry');
}
/**
* Check if Asgard CMS already has been installed
*/
private function checkIfInstalled()
{
return Schema::hasTable('users');
}
} }
...@@ -4,6 +4,7 @@ use Illuminate\Contracts\Foundation\Application; ...@@ -4,6 +4,7 @@ use Illuminate\Contracts\Foundation\Application;
use Illuminate\Routing\Router; use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Modules\Core\Console\InstallCommand; use Modules\Core\Console\InstallCommand;
use Modules\Core\Services\Composer;
use Modules\Menu\Entities\Menuitem; use Modules\Menu\Entities\Menuitem;
use Modules\Menu\Repositories\Eloquent\EloquentMenuItemRepository; use Modules\Menu\Repositories\Eloquent\EloquentMenuItemRepository;
...@@ -87,8 +88,9 @@ class CoreServiceProvider extends ServiceProvider ...@@ -87,8 +88,9 @@ class CoreServiceProvider extends ServiceProvider
{ {
$this->app->bindShared('command.asgard.install', function($app) { $this->app->bindShared('command.asgard.install', function($app) {
return new InstallCommand( return new InstallCommand(
$app['Modules\User\Repositories\UserRepository'], $app['files'],
$app['files'] $app,
new Composer($app['files'])
); );
}); });
......
...@@ -2,51 +2,11 @@ ...@@ -2,51 +2,11 @@
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router; use Illuminate\Routing\Router;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class RoutingServiceProvider extends ServiceProvider class RoutingServiceProvider extends ServiceProvider
{ {
public function before(Router $router) public function before(Router $router)
{ {
// $modules = app('modules');
// $routes = app('Asgard.routes');
// foreach ($modules->enabled() as $module) {
// $router->group(
// ['namespace' => "Modules\\$module\\Http\\Controllers"],
// function (Router $router) use ($module, $routes) {
// foreach (LaravelLocalization::getSupportedLocales() as $locale => $language) {
// if ($this->moduleHasRoute($routes, $module, $locale)) {
// $uri = $routes[strtolower($module)][$locale];
// $router->get(
// $uri,
// [
// 'as' => "{$locale}.{$module}",
// 'uses' => 'PublicController@index'
// ]
// );
// $router->get(
// $uri . '/{slug}',
// [
// 'as' => "{$locale}.{$module}.slug",
// 'uses' => 'PublicController@show'
// ]
// );
// }
// }
// }
// );
// }
}
/**
* @param $routes
* @param $module
* @param $locale
* @return bool
*/
private function moduleHasRoute($routes, $module, $locale)
{
return isset($routes[strtolower($module)][$locale]);
} }
public function map(Router $router) public function map(Router $router)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<div class="navbar-right"> <div class="navbar-right">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="{{ URL::to('/') }}" target="_blank"><i class="fa fa-eye"></i> View Website</a></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-flag"></i> <i class="fa fa-flag"></i>
...@@ -55,12 +56,7 @@ ...@@ -55,12 +56,7 @@
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->
<li class="user-footer"> <li class="user-footer">
<div class="pull-left"> <a href="{{ URL::route('logout') }}" class="btn btn-default btn-flat">Sign out</a>
<a href="{{ URL::route('dashboard.user.edit', [$user->id]) }}" class="btn btn-default btn-flat">Profile</a>
</div>
<div class="pull-right">
<a href="{{ URL::route('logout') }}" class="btn btn-default btn-flat">Sign out</a>
</div>
</li> </li>
</ul> </ul>
</li> </li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment