Commit 39218031 authored by ZeMKI's avatar ZeMKI
Browse files

install mesort command

* you can now run mesort:install to install it into your server.
parent 3114e166
......@@ -8,6 +8,7 @@ use App\User;
use App\Permission;
use App\Mail\VerificationEmail;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Mail;
class CreateUserCommand extends Command
......@@ -69,6 +70,7 @@ class CreateUserCommand extends Command
$user->email = $email;
$user->password = bcrypt($password);
//$user->password_token = Helper::random_str(30);
$user->email_verified_at = Date::now();
$user->save();
$user->attachRole($role);
$createStudyPermission = Permission::where('name', 'create-studies')
......
<?php
namespace App\Console\Commands;
use App\Permission;
use App\User;
use Illuminate\Console\Command;
use Helper;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Date;
use File;
class InstallMesortCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'mesort:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install Mesort application';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->warn('---Migrating the database---');
Artisan::call('migrate');
$this->info(Artisan::output());
$this->warn('--Cleaning the cache---');
Artisan::call('optimize:clear');
$this->info(Artisan::output());
$this->warn('---Creating the required folders---');
$this->error('---If this fails, check your folder permissions!---');
$path = public_path().'/images/preset_tokens';
File::makeDirectory($path, $mode = 0775, true, true);
$path = public_path().'/images/classifiers';
File::makeDirectory($path, $mode = 0775, true, true);
$path = storage_path('app/preset_tokens');
File::makeDirectory($path, $mode = 0775, true, true);
$path = storage_path('app/classifiers');
File::makeDirectory($path, $mode = 0775, true, true);
$this->warn('Folders created successfully!');
$this->warn('You will now create your personal user with all access rights.');
$stored = false;
while(!$stored){
$email = $this->ask('Enter your email');
$password = $this->ask('Enter your password - minimum 6 chars.');
$stored = $this->storeUser(1, $email,$password, $user);
}
$this->info('You can now enter with the following data:');
$this->info('Email: '.$email);
$this->info('Password: '.$password);
}
public function storeUser($roleId, $email, $password, &$user)
{
$role = Role::where('id', $roleId)->first();
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->warn('Please enter a valid email.');
return false;
}
if(strlen($password) < 6){
$this->warn('Please enter a valid password.');
return false;
}
$user = new User();
$user->email = $email;
$user->password = bcrypt($password);
$createStudyPermission = Permission::where('name', 'create-studies')
->first();
$user->supervised_by = $user->id;
$user->email_verified_at = Date::now();
$user->save();
$user->roles()->sync($role);
$user->attachPermissions([$createStudyPermission]);
return true;
}
}
Supports Markdown
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