Skip to content

Commit

Permalink
admin Gate added
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Mar 30, 2017
1 parent 52cfcf6 commit 184b918
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Auth/VpnAuthGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function user()
}

$this->user = new User($decoded);

// Admin checking
$this->user->setIsAdmin(env('APP_ADMIN') == $this->user->getEmail());

return $this->user;

} catch (AuthServerFailException $e){
Expand Down
6 changes: 6 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function boot()
{
$this->registerPolicies();

// Vpn auth Guard
Auth::extend('vpnauth', function ($app, $name, array $config) {
$api = $this->app->make('App\Auth\VpnAuthGuard');
$api->setName('vpnauth');
Expand All @@ -36,5 +37,10 @@ public function boot()

//return new JwtGuard(Auth::createUserProvider($config['provider']));
});

// Is admin Gate
Gate::define('is-admin', function ($user) {
return $user->getIsAdmin();
});
}
}
27 changes: 27 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class User implements Authenticatable
protected $local_ip;
protected $remote_ip;
protected $remote_port;
protected $is_admin;

/**
* User constructor - from the decoded json vpn auth response
Expand Down Expand Up @@ -92,4 +93,30 @@ public function getRememberTokenName()
{
return null;
}

/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}

/**
* @return mixed
*/
public function getIsAdmin()
{
return $this->is_admin;
}

/**
* @param mixed $is_admin
*/
public function setIsAdmin($is_admin)
{
$this->is_admin = $is_admin;
}


}

0 comments on commit 184b918

Please sign in to comment.