purged wiki module

This commit is contained in:
2021-02-12 13:52:14 +09:00
parent 17239b3a35
commit 1cbd2e7c87
5 changed files with 1 additions and 511 deletions

View File

@@ -9,7 +9,6 @@ use Log;
//Libraries
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Esi\Esi;
use App\Library\Wiki\WikiHelper;
//Models
use App\Models\User\User;
@@ -19,9 +18,6 @@ use App\Models\Esi\EsiToken;
use App\Models\User\UserPermission;
use App\Models\User\UserRole;
use App\Models\Admin\AllowedLogin;
use App\Models\Doku\DokuMember;
use App\Models\Doku\DokuUser;
/**
* The PurgeUsers command takes care of updating any user changes in terms of login role, as well as purging any users without at least
@@ -186,14 +182,7 @@ class PurgeUsers extends Command
EsiToken::where([
'character_id' => $user->character_id,
])->delete();
//Delete the user from the wiki
$wikiHelper = new WikiHelper;
//Get the uid from the wiki tables utilizing the character's name
$uid = DokuUser::where(['name' => $user->name])->first();
$wikiHelper->DeleteWikiUser($uid);
])->delete();
}
}
}

View File

@@ -9,7 +9,6 @@ use Carbon\Carbon;
//Libraries
use App\Library\Taxes\TaxesHelper;
use App\Library\Wiki\WikiHelper;
use App\Library\Lookups\LookupHelper;
use App\Library\SRP\SRPHelper;
@@ -336,187 +335,4 @@ class AdminController extends Controller
return redirect('/admin/dashboard')->with('success', 'Entity removed from allowed login list.');
}
/**
* Display the wiki dashboard for wiki functions
*/
public function displayWikiDashboard() {
//Declare some variables
$wikiUsers = array();
$wikiGroups = array();
$tempUsers = DokuUser::all();
$tempGroups = DokuGroupNames::all();
$wikiMembership = DokuMember::all();
//Create a list of users based on id and name for the select form
foreach($tempUsers as $temp) {
$wikiUsers[$temp->id] = $temp->name;
}
asort($wikiUsers);
foreach($tempGroups as $temp) {
$wikiGroups[$temp->id] = $temp->gname;
}
asort($wikiGroups);
return view('admin.dashboards.wiki')->with('wikiUsers', $wikiUsers)
->with('wikiGroups', $wikiGroups)
->with('wikiMembership', $wikiMembership);
}
/**
* Delete a wiki user
*/
public function deleteWikiUser(Request $request) {
$this->validate($request, [
'user' => 'required',
]);
//Declare helper variable
$wikiHelper = new WikiHelper;
$wikiHelper->DeleteWikiUser($request->user);
redirect('/admin/dashboard/wiki')->with('success', 'User: ' . $request->user . ' has been deleted.');
}
/**
* Add a group to a wiki user
*/
public function addWikiUserGroup(Request $request) {
$this->validate($request, [
'user' => 'required', //User Id number
'groupname' => 'required', //Group Id number
]);
//Declare some helper variables
$wikiHelper = new WikiHelper;
//Check to see if the user has the group we are going to add first
if($wikiHelper->UserHasGroup($request->user, $request->groupname)) {
return redirect('/admin/dashboard/wiki')->with('error', 'User already has the group.');
}
//Add the user to the wiki group
$results = $wikiHelper->AddUserToGroup($request->user, $request->groupname);
//Redirect based on the results of the add user to group function
if($results) {
return redirect('/admin/dashboard/wiki')->with('success', 'User added to group for the wiki.');
} else {
return redirect('/admin/dashboard/wiki')->with('error', 'Failed at add user to group, or user was already part of the group.');
}
}
/**
* Remove a group from a wiki user
*/
public function removeWikiUserGroup(Request $request) {
$this->validate($request, [
'user' => 'required',
'groupname' => 'required',
]);
//Declare some helper variables
$wikiHelper = new WikiHelper;
//Check to see if the user has the group we are going to remove them from
if(!$wikiHelper->UserHasGroup($request->user, $request->groupname)) {
return redirect('/admin/dashboard/wiki')->with('error', 'User does not have the group to remove.');
}
//Remove the user from the wiki group
$wikiHelper->RemoveUserFromGroup($request->user, $request->groupname);
return redirect('/admin/dashboard/wiki')->with('success', 'Removed user from group ' . $request->grouopname);
}
/**
* Remove a user from all wiki groups
*/
public function removeWikiUserAllGroups(Request $request) {
$this->validate($request, [
'user' => 'required',
]);
//Declare variable
$wikiHelper = new WikiHelper;
$wikiHelper->RemoveUserFromAllGroups($request->user);
return redirect('/admin/dashboard/wiki')->with('success', 'User successfully removed from all groups.');
}
/**
* Insert a new group for wiki user's to be added to
*/
public function insertNewWikiUserGroup(Request $request) {
$this->validate($request, [
'group' => 'required',
'description' => 'required',
]);
//Declare variable
$wikiHelper = new WikiHelper;
$wikiHelper->AddNewUserGroup($request->group, $request->description);
return redirect('/admin/dashboard/wiki')->with('success', 'Added new user group.');
}
public function purgeWikiUsers(Request $request) {
$this->validate($request, [
'admin' => 'required',
]);
//Declare helper classes
$lookup = new LookupHelper;
$wikiHelper = new WikiHelper;
//Get all of the users from the database
$users = User::all();
//Search the names and verify against the lookup table
//to find the corporation and / or alliance they belong to.
foreach($users as $user) {
//Let's look up the character in the user table by their name.
//If no name is found, then delete the user and have them start over with the wiki permissions
$count = DokuUser::where(['name' => $user->name])->count();
//If the user is found, then check if they are allowed on the wiki.
//If the the count == 0, then the user wasn't found on the wiki, so do nothing.
if($count > 0) {
//If the user is not allowed, then delete the user, otherwise, leave the user untouched
if(!$wikiHelper->AllowedUser($user->name)) {
$uid = $wikiHelper->GetUID($user->name);
$wikiHelper->DeleteWikiUser($uid);
}
}
}
//Get all of the DokuUsers and verify against the Users on the services page
$users = DokuUser::all();
//Search the names and verify against the lookup table to find the corporation / alliance the user belongs to.
foreach($users as $user) {
//Lookup the character in the user table on the services page
$count = User::where(['name' => $user->name])->count();
//If the user is found, then check if they are allowed on the wiki.
//If the count == 0, then delete the user anyways
if($count > 0 ) {
//If the user is not allowed, then delete the user, otherwise, leave them alone.
if(!$wikiHelper->AllowedUser($user->name)) {
$uid = $wikiHelper->GetUID($user->name);
$wikiHelper->DeleteWikiUser($uid);
} else {
$wikiHelper->DeleteWikiUser($user->id);
}
}
}
return redirect('/admin/dashboard/wiki')->with('success', 'Wiki has been purged.');
}
}

View File

@@ -11,7 +11,6 @@ use Illuminate\Support\Facades\Auth;
//Libraries
use App\Library\Taxes\TaxesHelper;
use App\Library\Wiki\WikiHelper;
use App\Library\Lookups\LookupHelper;
use App\Library\SRP\SRPHelper;

View File

@@ -1,152 +0,0 @@
<?php
namespace App\Http\Controllers\Wiki;
//Laravel libraries
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
//User Libraries
use App\Library\Lookups\LookupHelper;
use App\Library\Wiki\WikiHelper;
//Models
use App\Models\Doku\DokuGroupNames;
use App\Models\Doku\DokuMember;
use App\Models\Doku\DokuUser;
use App\Models\Admin\AllowedLogin;
use App\Models\User\User;
class WikiController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('role:Renter');
}
public function displayRegister() {
//make user name syntax like we want it.
$name = Auth::user()->name;
$name = strtolower($name);
$name = str_replace(' ', '_', $name);
//Check to see if the user is already registered in the database
$count = DokuUser::where([
'login' => $name,
])->count();
//If the count is greater than zero, also check the login name as a reference
if($count > 0) {
$check = DokuUser::where([
'login' => $name,
])->first();
if($check->login === $name) {
return redirect('/dashboard')->with('error', 'Already registered for the wiki!');
}
}
return view('wiki.user.register')->with('name', $name);
}
public function storeRegister(Request $request) {
$this->validate($request, [
'password' => 'required',
'password2' => 'required',
]);
$password = '';
//Check to make sure the password matches
if($request->password !== $request->password2) {
return view('/dashboard')->with('error');
} else {
$password = md5($request->password);
}
if(Auth::user()->hasRole('User')) {
$role = 1; //User role id from wiki_groupname table
$roleDescription = 'user';
} else if(Auth::user()->hasRole('Renter')) {
$role = 8; //Renter role id from wiki_groupname table
$roleDescription = 'renter';
}
//Load the model
$user = new DokuUser;
$member = new DokuMember;
//make user name syntax like we want it.
$name = Auth::user()->name;
$name = strtolower($name);
$name = str_replace(' ', '_', $name);
//Add the new user to the wiki
$user->login = $name;
$user->pass = $password;
$user->name = Auth::user()->name;
$user->save();
//Get the user from the table to get the uid
$uid = DokuUser::where([
'login' => $name,
])->first();
//Save information in the model
$member->uid = $uid->id;
$member->gid = $role;
$member->groupname = $roleDescription;
$member->save();
//Return to the dashboard view
return redirect('/dashboard')->with('success', 'Registration successful. Your username is: ' . $name);
}
public function displayChangePassword() {
$name = Auth::user()->name;
$name = strtolower($name);
$name = str_replace(' ', '_', $name);
//Get the password
$check = DokuUser::where([
'login' => $name
])->count();
if($check == 0) {
return redirect('/dashboard')->with('error', 'Login Not Found');
}
return view('wiki.user.changepassword')->with('name', $name);
}
public function changePassword(Request $request) {
$this->validate($request, [
'password' => 'required',
'password2' => 'required',
]);
//Check for a valid password
$password = '';
if($request->password !== $request->password2) {
return redirect('/wiki/changepassword')->with('error', 'Passwords did not match');
} else {
$password = md5($request->password);
}
//Get a model ready for the database
$user = new DokuUser;
//Find the username for the database through the character name in auth
$name = Auth::user()->name;
$name = strtolower($name);
$name = str_replace(' ', '_', $name);
//Update the password for the login name
DokuUser::where([
'login' => $name,
])->update([
'pass' => $password,
]);
return redirect('/dashboard')->with('success', 'Password changed successfully. Your username is: ' . $name);
}
}

View File

@@ -1,162 +0,0 @@
<?php
namespace App\Library\Wiki;
//Internal Library
use Carbon\Carbon;
//Library
use App\Library\Lookups\LookupHelper;
//Models
use App\Models\User\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
use App\Models\Doku\DokuGroupNames;
use App\Models\Doku\DokuMember;
use App\Models\Doku\DokuUser;
use App\Models\Admin\AllowedLogin;
class WikiHelper {
/**
* Check whether the user is allwoed or not allowed
*/
public function AllowedUser($user) {
//Declare some variables
$purge = true;
//Declare helper class
$lookup = new LookupHelper;
//Get the allowed logins list from the database
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
$charIdTemp = User::where(['name' => $user])->get(['character_id']);
//Set the character id
$charId = $charIdTemp[0]->character_id;
//Set the corp id
$char = $lookup->GetCharacterInfo($charId);
$corpId = $char->corporation_id;
//Set the alliance id
$corp = $lookup->GetCorporationInfo($corpId);
if(isset($corp->alliance_id)) {
$allianceId = $corp->alliance_id;
} else {
$allianceId = 0;
}
if(in_array($allianceId, $legacy) || in_array($allianceId, $renter) || $allianceId == 99004116) {
$purge = false;
} else {
$purge = true;
}
return $purge;
}
/**
* Add a user to a particular group
*/
public function AddUserToGroup($userId, $groupId) {
//Get the group information
$groups = DokuGroupNames::all();
//Check if the user already belongs to the group
if(DokuMember::where(['gid' => $groupId, 'uid' => $userId])->count() > 0) {
//If the count is greater than zero then we don't need to do anything,
//just return false to indicate nothing was changed
return false;
} else {
//Get the group the person needs to be added to.
$newGroup = DokuGroupNames::where(['id' => $groupId])->first();
//Add the user to the group
DokuMember::insert([
'uid' => $userId,
'gid' => $groupId,
'groupname' => $newGroup->gname,
]);
//Return true saying we have inserted the user into the group
return true;
}
}
/**
* Remove a user from a particular group
*/
public function RemoveUserFromGroup($userId, $groupId) {
//Remove the user from any groups he is associated with
DokuMember::where([
'uid' => $userId,
'gid' => $groupId,
])->delete();
}
/**
* Remove a user from all groups
*/
public function RemoveUserFromAllGroups($userId) {
//Remove the user from all groups
DokuMember::where([
'uid' => $userId,
])->delete();
}
/**
* Check to see if a user is already in a group
*/
public function UserHasGroup($userId, $groupId) {
//Get the user information
$user = DokuUser::where(['id' => $userId])->first();
//Get all of the groups
$allGroups = DokuGroupNames::all();
//cycle through all of the groups, and all of the user's groups to see if the user
//is part of the group we are seeking
foreach($allGroups as $all) {
if($groupId === $all->id) {
return true;
}
}
//If we have made it here, then the user does not have the group, therefore,
//return the user doesn't have the group
return false;
}
/**
* Add a new user group
*/
public function AddNewUserGroup($groupName, $description) {
//Insert or ignore the group if it's already there.
DokuGroupNames::insertOrIgnore([
'gname' => $groupName,
'description' => $description,
]);
}
/**
* Delete all traces of a wiki user
*/
public function DeleteWikiUser($userId) {
//Delete the permissions of the user first.
DokuMember::where([
'uid' => $userId,
])->delete();
//Delete the user from the user table
DokuUser::where(['id' => $userId])->delete();
}
/**
* Get uid from name
*/
public function GetUID($name) {
return DokuUser::where(['name' => $name])->first();
}
}