remove user function added to admin controller
This commit is contained in:
@@ -9,6 +9,9 @@ use App\User;
|
|||||||
use App\Models\User\UserRole;
|
use App\Models\User\UserRole;
|
||||||
use App\Models\User\UserPermission;
|
use App\Models\User\UserPermission;
|
||||||
use App\Models\User\AvailableUserPermission;
|
use App\Models\User\AvailableUserPermission;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Corporation\CorpStructure;
|
||||||
|
|
||||||
class AdminController extends Controller
|
class AdminController extends Controller
|
||||||
{
|
{
|
||||||
@@ -65,57 +68,30 @@ class AdminController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removePermission(Request $request) {
|
public function removeUser(Request $request) {
|
||||||
//Get the user and permission to be removed from the form
|
//Get the user from the form to delete
|
||||||
$user = $request->user;
|
$user = $request->user;
|
||||||
$permission = $request->permission;
|
|
||||||
//Get the character id from the username using the user table
|
|
||||||
$character = DB::table('users')->where('name', $user)->first();
|
|
||||||
//Check if the permission exists in the table
|
|
||||||
$check = DB::table('user_permissions')->where(['character_id' => $character->character_id, 'permission' => $permission])->get();
|
|
||||||
if($check !== null) {
|
|
||||||
DB::table('user_permissions')->where(['character_id' => $character->character_id,
|
|
||||||
'permission' => $permission])
|
|
||||||
->delete();
|
|
||||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
|
||||||
} else {
|
|
||||||
return view('admin.dashboard')->with('error', 'User did not have the permission.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRole(Request $request) {
|
//Get the user data from the table
|
||||||
//Get the user and role from the form
|
$data = User::where(['name' => $user])->get();
|
||||||
$user = $request->user;
|
|
||||||
$role = $request->role;
|
|
||||||
//Get the character id from the username using the user table
|
|
||||||
$character = DB::table('users')->where('name', $user)->first();
|
|
||||||
//Delete the current roles from the database to start with a clean state
|
|
||||||
DB::table('user_roles')->where(['character_id' => $character->character_id])->delete();
|
|
||||||
|
|
||||||
$userRoles = new UserRole;
|
//Delete the user's ESI Scopes
|
||||||
$userRoles->character_id = $character->character_id;
|
EsiScope::where(['character_id' => $data->character_id])->delete();
|
||||||
$userRoles->role = $role;
|
|
||||||
$userRoles->save();
|
|
||||||
|
|
||||||
//Return the view and the message of user updated
|
//Delete the user's ESI Token
|
||||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
EsiToken::where(['character_id' => $data->character_id])->delete();
|
||||||
}
|
|
||||||
|
|
||||||
public function removeRole(Request $request) {
|
//Delete the user's roles from the roles table
|
||||||
//Get the user and role from the form
|
UserRole::where(['character_id' => $data->character_id])->delete();
|
||||||
$user = $request->user;
|
|
||||||
$role = $request->role;
|
|
||||||
//Get the character id from teh username using the user table
|
|
||||||
$character = DB::table('users')->where('name', $user)->first();
|
|
||||||
$check = DB::table('user_roles')->where(['character_id' => $character->character_id, 'role' => $role])->get();
|
|
||||||
if($check !== null) {
|
|
||||||
DB::table('user_roles')->where(['character_id' => $character->character_id,
|
|
||||||
'role' => $role])
|
|
||||||
->delete();
|
|
||||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.dashboard')->with('error', 'User did not have the role.');
|
//Delete the user from the user table
|
||||||
|
User::where(['character_id' => $data->character_id])->delete();
|
||||||
|
|
||||||
|
//Delete the user's structures
|
||||||
|
CorpStructure::where(['character_id' => $data->character_id])->delete();
|
||||||
|
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard')->with('success', 'User deleted from the site.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayAllowedLogins() {
|
public function displayAllowedLogins() {
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Corporation;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Structure extends Model
|
|
||||||
{
|
|
||||||
// Table Name
|
|
||||||
protected $table = 'Structures';
|
|
||||||
|
|
||||||
// Timestamps
|
|
||||||
public $timestamps = true;
|
|
||||||
|
|
||||||
//Primary Key
|
|
||||||
public $primaryKey = 'structure_id';
|
|
||||||
}
|
|
||||||
@@ -24,4 +24,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 card">
|
||||||
|
<div class="card-header">
|
||||||
|
Remove User
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{!! Form::open(['action' => 'AdminController@removeUser', 'method' => 'POST']) !!}
|
||||||
|
<div class="form-group">
|
||||||
|
{{ Form::label('user', 'User') }}
|
||||||
|
{{ Form::select('user', $date['users'], null, ['class' => 'form-control']) }}
|
||||||
|
</div>
|
||||||
|
{{ Form::submit('Submit', ['class' => 'btn btn-primary']) }}
|
||||||
|
{!! Form::close() !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
Reference in New Issue
Block a user