roles functions in login controller'

This commit is contained in:
2018-11-05 21:22:07 -06:00
parent 627af443e5
commit 19b26cb54f
3 changed files with 23 additions and 0 deletions

View File

@@ -101,7 +101,11 @@ class LoginController extends Controller
if($eve_user->refreshToken !== null) {
//Check if the owner hash has changed to call the user type if it needs to be updated
if($this->OwnerHasChanged($authUser->owner_hash, $eve_user->owner_hash)) {
//Get the right role for the user
$role = $this->GetRole(null, $eve_user->id);
//Set the role for the user
$this->SetRole($role, $eve_user->id);
//Update the user information never the less.
DB::table('users')->where('character_id', $eve_user->id)->update([
'name' => $eve_user->getName(),
@@ -162,6 +166,8 @@ class LoginController extends Controller
} else {
//Get the role for the character to be stored in the database
$role = $this->GetRole();
//Set the role for the user
$this->SetRole($role, $eve_user->id);
//Create a user account
return User::create([
@@ -178,6 +184,20 @@ class LoginController extends Controller
}
}
/**
* Set the user role in the database
*
* @param role
* @param charId
*/
private function SetRole($role, $charId) {
//Insert the role into the database
$roles = new App\Models\UserRole;
$roles->character_id = $charId;
$roles->role = $role;
$roles->save();
}
/**
* Set the user scopes in the database
*

View File

@@ -18,6 +18,7 @@ class FinancesController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('role:Admin');
}
public function redirectToProvider() {

View File

@@ -43,8 +43,10 @@ class User extends Authenticatable
protected $guarded = [];
//Used in middleware to make sure a user is able to access many of the pages
public function hasRole($role)
{
//return User::where('role', $role)->get();
}