diff --git a/app/Http/Controllers/RegisterStructureController.php b/app/Http/Controllers/RegisterStructureController.php index c08b20489..eaa303056 100644 --- a/app/Http/Controllers/RegisterStructureController.php +++ b/app/Http/Controllers/RegisterStructureController.php @@ -8,6 +8,7 @@ use Auth; use DB; use App\Models\Corporation\CorpStructure; +use App\Library\Esi; class RegisterStructureController extends Controller { @@ -17,7 +18,12 @@ class RegisterStructureController extends Controller } public function displayRegisterStructure() { - return view('structures.register'); + //Check to see if the user has the read corp journal esi scope before allowing to register a structure + if(Auth()->user()->hasEsiScope('esi-wallet.read_corporation_wallets.v1')) { + return view('structures.register'); + } else { + return view('dashboard')->with('error', 'You need to setup your esi scope for read corporation wallets'); + } } public function storeStructure(Request $request) { diff --git a/app/User.php b/app/User.php index c55e3575d..51b2836fa 100644 --- a/app/User.php +++ b/app/User.php @@ -51,15 +51,19 @@ class User extends Authenticatable } public function role() { - return $this->hasOne('App\Models\UserRole', 'character_id'); + return $this->hasOne('App\Models\User\UserRole', 'character_id'); } public function permissions() { - return $this->hasMany('App\Models\UserPermission', 'character_id'); + return $this->hasMany('App\Models\User\UserPermission', 'character_id'); } public function esitoken() { - return $this->hasOne('App\Models\EsiToken', 'character_id', 'character_id'); + return $this->hasOne('App\Models\Esi\EsiToken', 'character_id', 'character_id'); + } + + public function esiScopes() { + return $this->hasMany('App\Models\Esi\EsiScope', 'character_id'); } public function hasPermission($permission) { @@ -72,13 +76,22 @@ class User extends Authenticatable } + public function hasEsiScope($scope) { + $found = EsiScope::where(['character_id' => $this->character_id, 'scope' => $scope])->get(['scope']); + if(isset($found[0]->scope) && $found[0]->scope == $scope) { + return true; + } else { + return false; + } + } + public function hasRole($role) { //If the user is a super user then he has all roles if($this->hasSuperUser()) { return true; } - $found = UserRole::where(['character_id' => $this->character_id, 'role' => $role])->get(); + $found = UserRole::where(['character_id' => $this->character_id, 'role' => $role])->get(['role']); if(isset($found[0]) && $found[0]->role == $role) { return true;