allowed login models and update of login controller
This commit is contained in:
@@ -12,7 +12,7 @@ use DB;
|
||||
use App\User;
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\User\UserRole;
|
||||
use App\Models\user\Permission;
|
||||
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
@@ -111,6 +111,12 @@ class LoginController extends Controller
|
||||
'owner_hash' => $eve_user->owner_hash,
|
||||
'role' => $role,
|
||||
]);
|
||||
//Update the user's roles and permission
|
||||
UserPermission::where(['character_id' => $eve_user->id])->delete();
|
||||
$perm = new UserPermission();
|
||||
$perm->character_id = $eve_user->id;
|
||||
$perm->permission = $role;
|
||||
$perm->save();
|
||||
} else {
|
||||
//Update the user information never the less.
|
||||
DB::table('users')->where('character_id', $eve_user->id)->update([
|
||||
@@ -178,11 +184,10 @@ class LoginController extends Controller
|
||||
* @param charId
|
||||
*/
|
||||
private function SetRole($role, $charId) {
|
||||
//Insert the role into the database
|
||||
$roles = new UserRole;
|
||||
$roles->character_id = $charId;
|
||||
$roles->role = $role;
|
||||
$roles->save();
|
||||
$permission = new UserPermission;
|
||||
$permission->character_id = $charId;
|
||||
$permission->permission = $role;
|
||||
$permission->save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,13 +231,13 @@ class LoginController extends Controller
|
||||
private function GetRole($refreshToken, $charId) {
|
||||
$accountType = $this->GetAccountType($refreshToken, $charId);
|
||||
if($accountType == 'Guest') {
|
||||
$role = 'Guest';
|
||||
$role = 'role.guest';
|
||||
} else if($accountType == 'Legacy'){
|
||||
$role = 'User';
|
||||
$role = 'role.user';
|
||||
} else if($accountType == 'W4RP') {
|
||||
$role = 'User';
|
||||
$role = 'role.user';
|
||||
} else {
|
||||
$role = 'None';
|
||||
$role = 'role.none';
|
||||
}
|
||||
|
||||
return $role;
|
||||
|
||||
@@ -62,13 +62,8 @@ class RegisterController extends Controller
|
||||
* @param array $data
|
||||
* @return \App\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
protected function create()
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
'character_id' => $data['characterid'],
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Admin;
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AllowedLogin extends Model
|
||||
{
|
||||
//Table Name
|
||||
public $table = 'allowed_login';
|
||||
public $table = 'allowed_logins';
|
||||
|
||||
//Timestamps
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
use DB;
|
||||
use App\Models\User\UserRole;
|
||||
use App\Models\User\UserPermission;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -32,54 +32,53 @@ class AuthServiceProvider extends ServiceProvider
|
||||
$this->registerPolicies($gate);
|
||||
|
||||
$gate->define('isAdmin', function($user) {
|
||||
//Get the roles the user has from the user_roles table and check against the gate we are creating
|
||||
$check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]->role === 'Admin') {
|
||||
//User has the Admin role
|
||||
|
||||
$check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]-> role === 'role.admin') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$gate->define('isDirector', function($user) {
|
||||
//Get the roles the user has from the user_roles table and check against the gate we are creating
|
||||
$check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]->role === 'Director') {
|
||||
//User has the Director role
|
||||
|
||||
$check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]-> role === 'role.director') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$gate->define('isUser', function($user) {
|
||||
//Get the roles the user has from the user_roles table and check against the gate we are creating
|
||||
$check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]->role === 'User') {
|
||||
//User has the User role
|
||||
|
||||
$check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]-> role === 'role.user') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$gate->define('isGuest', function($user) {
|
||||
//Get the roles the user has from the user_roles table and check against the gate we are creating
|
||||
$check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]->role === 'Guest') {
|
||||
//User has the Guest role
|
||||
|
||||
$check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]-> role === 'role.guest') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$gate->define('isNone', function($user) {
|
||||
//Get the roles the user has from the user_roles table and check against the gate we are creating
|
||||
$check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]->role === 'None') {
|
||||
//User has no role
|
||||
|
||||
$check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
if($check[0]-> role === 'role.none') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DropUsersRoleColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(Schema::hasColumn('users', 'role')) {
|
||||
Schema::table('users', function($table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateAllowedLoginsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!Schema::hasTable('allowed_logins')) {
|
||||
Schema::create('allowed_logins', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('entity_id');
|
||||
$table->string('entity_type');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('allowed_logins');
|
||||
}
|
||||
}
|
||||
5
vendor/composer/autoload_classmap.php
vendored
5
vendor/composer/autoload_classmap.php
vendored
@@ -9,8 +9,8 @@ return array(
|
||||
'App\\Console\\Commands\\CalculateMarketTax' => $baseDir . '/app/Console/Commands/calculatemarkettax.php',
|
||||
'App\\Console\\Commands\\CorpJournal' => $baseDir . '/app/Console/Commands/corpJournal.php',
|
||||
'App\\Console\\Commands\\DumpFleets' => $baseDir . '/app/Console/Commands/dumpFleets.php',
|
||||
'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/getCorps.php',
|
||||
'App\\Console\\Commands\\GetLogisticsContracts' => $baseDir . '/app/Console/Commands/getLogisticContracts.php',
|
||||
'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/GetCorps.php',
|
||||
'App\\Console\\Commands\\GetLogisticsContracts' => $baseDir . '/app/Console/Commands/GetLogisticContracts.php',
|
||||
'App\\Console\\Commands\\SendMail' => $baseDir . '/app/Console/Commands/sendmail.php',
|
||||
'App\\Console\\Commands\\UpdateMoonPricing' => $baseDir . '/app/Console/Commands/UpdateMoonPricing.php',
|
||||
'App\\Console\\Commands\\holdingfinances' => $baseDir . '/app/Console/Commands/holdingfinances.php',
|
||||
@@ -67,6 +67,7 @@ return array(
|
||||
'App\\Library\\SeatHelper' => $baseDir . '/app/Library/SeatHelper.php',
|
||||
'App\\Library\\Structures\\JumpBridgeFuel' => $baseDir . '/app/Library/Structures/JumpBridgeFuel.php',
|
||||
'App\\Library\\Structures\\StructureTaxHelper' => $baseDir . '/app/Library/Structures/StructureTaxHelper.php',
|
||||
'App\\Models\\Admin\\AllowedLogin' => $baseDir . '/app/Models/Admin/AllowedLogin.php',
|
||||
'App\\Models\\Character\\CharacterToCorporation' => $baseDir . '/app/Models/Charcter/CharacterToCorporation.php',
|
||||
'App\\Models\\Config' => $baseDir . '/app/Models/Config.php',
|
||||
'App\\Models\\Corporation\\AllianceCorp' => $baseDir . '/app/Models/Corporation/AllianceCorp.php',
|
||||
|
||||
5
vendor/composer/autoload_static.php
vendored
5
vendor/composer/autoload_static.php
vendored
@@ -463,8 +463,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
|
||||
'App\\Console\\Commands\\CalculateMarketTax' => __DIR__ . '/../..' . '/app/Console/Commands/calculatemarkettax.php',
|
||||
'App\\Console\\Commands\\CorpJournal' => __DIR__ . '/../..' . '/app/Console/Commands/corpJournal.php',
|
||||
'App\\Console\\Commands\\DumpFleets' => __DIR__ . '/../..' . '/app/Console/Commands/dumpFleets.php',
|
||||
'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php',
|
||||
'App\\Console\\Commands\\GetLogisticsContracts' => __DIR__ . '/../..' . '/app/Console/Commands/getLogisticContracts.php',
|
||||
'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/GetCorps.php',
|
||||
'App\\Console\\Commands\\GetLogisticsContracts' => __DIR__ . '/../..' . '/app/Console/Commands/GetLogisticContracts.php',
|
||||
'App\\Console\\Commands\\SendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php',
|
||||
'App\\Console\\Commands\\UpdateMoonPricing' => __DIR__ . '/../..' . '/app/Console/Commands/UpdateMoonPricing.php',
|
||||
'App\\Console\\Commands\\holdingfinances' => __DIR__ . '/../..' . '/app/Console/Commands/holdingfinances.php',
|
||||
@@ -521,6 +521,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
|
||||
'App\\Library\\SeatHelper' => __DIR__ . '/../..' . '/app/Library/SeatHelper.php',
|
||||
'App\\Library\\Structures\\JumpBridgeFuel' => __DIR__ . '/../..' . '/app/Library/Structures/JumpBridgeFuel.php',
|
||||
'App\\Library\\Structures\\StructureTaxHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureTaxHelper.php',
|
||||
'App\\Models\\Admin\\AllowedLogin' => __DIR__ . '/../..' . '/app/Models/Admin/AllowedLogin.php',
|
||||
'App\\Models\\Character\\CharacterToCorporation' => __DIR__ . '/../..' . '/app/Models/Charcter/CharacterToCorporation.php',
|
||||
'App\\Models\\Config' => __DIR__ . '/../..' . '/app/Models/Config.php',
|
||||
'App\\Models\\Corporation\\AllianceCorp' => __DIR__ . '/../..' . '/app/Models/Corporation/AllianceCorp.php',
|
||||
|
||||
Reference in New Issue
Block a user