Skip to content

Commit

Permalink
Remove some Legacy functions that always return the same result
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Jul 3, 2022
1 parent a9accdb commit f732f5d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 50 deletions.
5 changes: 0 additions & 5 deletions app/Actions/Settings/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Exceptions\UnauthenticatedException;
use App\Exceptions\UnauthorizedException;
use App\Facades\AccessControl;
use App\Legacy\Legacy;
use App\Models\Logs;
use App\Models\User;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -53,10 +52,6 @@ public function do(string $username, string $password, ?string $oldUsername, ?st
throw new InvalidPropertyException('Could not hash username or password', $e);
}

if (Legacy::SetPassword($hashedUsername, $hashedPassword)) {
return;
}

// > 4.0.8
/** @var User $adminUser */
$adminUser = User::query()->find(0);
Expand Down
46 changes: 2 additions & 44 deletions app/Legacy/Legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace App\Legacy;

use App\Exceptions\ConfigurationException;
use App\Exceptions\Internal\InvalidConfigOption;
use App\Exceptions\Internal\QueryBuilderException;
use App\Facades\AccessControl;
use App\Models\Configs;
use App\Models\Logs;
use App\Rules\IntegerIDRule;
use App\Rules\RandomIDRule;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;

/**
* Stuff we need to delete in the future.
Expand All @@ -30,53 +29,12 @@ public static function resetAdmin(): void
->update(['value' => '']);
}

/**
* @throws InvalidConfigOption
*/
public static function SetPassword(string $hashedUsername, string $hashedPassword): bool
{
$configs = Configs::get();

if (Configs::getValueAsString('version') < '040008') {
if ($configs['password'] === '' && $configs['username'] === '') {
Configs::set('username', $hashedUsername);
Configs::set('password', $hashedPassword);

return true;
}
}

return false;
}

public static function noLogin(): bool
{
// LEGACY STUFF
$configs = Configs::get();

if (Configs::getValueAsString('version') <= '040008') {
// Check if login credentials exist and login if they don't
if (
isset($configs['username']) && $configs['username'] === '' &&
isset($configs['password']) && $configs['password'] === ''
) {
Session::put('login', true);
Session::put('UserID', 0);

return true;
}
}

return false;
}

public static function log_as_admin(string $username, string $password, string $ip): bool
{
$configs = Configs::get();

if (Hash::check($username, $configs['username']) && Hash::check($password, $configs['password'])) {
Session::put('login', true);
Session::put('UserID', 0);
AccessControl::log_as_id(0);
Logs::notice(__METHOD__, __LINE__, 'User (' . $username . ') has logged in from ' . $ip . ' (legacy)');

return true;
Expand Down
2 changes: 1 addition & 1 deletion app/ModelFunctions/SessionFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function noLogin(): bool
return true;
}

return Legacy::noLogin();
return false;
}

/**
Expand Down

0 comments on commit f732f5d

Please sign in to comment.