Skip to content

Commit

Permalink
Move ChangePassword::getHtml to Server\Privileges class
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jul 29, 2020
1 parent 904d8f9 commit c92663a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 185 deletions.
3 changes: 1 addition & 2 deletions libraries/classes/Controllers/UserPasswordController.php
Expand Up @@ -5,7 +5,6 @@
namespace PhpMyAdmin\Controllers;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\ChangePassword;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
Expand Down Expand Up @@ -101,6 +100,6 @@ public function index(): void
$this->response->addHTML($msg->getDisplay());
}

$this->response->addHTML(ChangePassword::getHtml('change_pw', $username, $hostname));
$this->response->addHTML($this->userPassword->getFormForChangePassword($username, $hostname));
}
}
76 changes: 0 additions & 76 deletions libraries/classes/Display/ChangePassword.php

This file was deleted.

46 changes: 40 additions & 6 deletions libraries/classes/Server/Privileges.php
Expand Up @@ -9,7 +9,6 @@

use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\ChangePassword;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Message;
Expand Down Expand Up @@ -3313,11 +3312,7 @@ public function getHtmlForUserProperties(
$changeLoginInfoFields = '';
if (! is_array($dbname) && strlen($dbname) === 0 && ! $user_does_not_exists) {
//change login information
$changePassword = ChangePassword::getHtml(
'edit_other',
$username,
$hostname
);
$changePassword = $this->getFormForChangePassword($username, $hostname, true);
$userGroup = $this->getUserGroupForUser($username);
$changeLoginInfoFields = $this->getHtmlForLoginInformationFields('change', $username, $hostname);
}
Expand Down Expand Up @@ -3940,4 +3935,43 @@ private function getRoutinePrivileges(

return $this->parseProcPriv($privileges);
}

public function getFormForChangePassword(string $username, string $hostname, bool $editOthers): string
{
global $route;

$isPrivileges = $route === '/server/privileges';

$serverType = Util::getServerType();
$serverVersion = $this->dbi->getVersion();
$origAuthPlugin = $this->getCurrentAuthenticationPlugin(
'change',
$username,
$hostname
);

$isNew = ($serverType === 'MySQL' && $serverVersion >= 50507)
|| ($serverType === 'MariaDB' && $serverVersion >= 50200);
$hasMoreAuthPlugins = ($serverType === 'MySQL' && $serverVersion >= 50706)
|| ($this->dbi->isSuperuser() && $editOthers);

$activeAuthPlugins = ['mysql_native_password' => __('Native MySQL authentication')];

if ($isNew && $hasMoreAuthPlugins) {
$activeAuthPlugins = $this->getActiveAuthPlugins();
if (isset($activeAuthPlugins['mysql_old_password'])) {
unset($activeAuthPlugins['mysql_old_password']);
}
}

return $this->template->render('server/privileges/change_password', [
'username' => $username,
'hostname' => $hostname,
'is_privileges' => $isPrivileges,
'is_new' => $isNew,
'has_more_auth_plugins' => $hasMoreAuthPlugins,
'active_auth_plugins' => $activeAuthPlugins,
'orig_auth_plugin' => $origAuthPlugin,
]);
}
}
5 changes: 5 additions & 0 deletions libraries/classes/UserPassword.php
Expand Up @@ -220,4 +220,9 @@ private function changePassUrlParamsAndSubmitQuery(
// Flush privileges after successful password change
$GLOBALS['dbi']->tryQuery('FLUSH PRIVILEGES;');
}

public function getFormForChangePassword(?string $username, ?string $hostname): string
{
return $this->serverPrivileges->getFormForChangePassword($username ?? '', $hostname ?? '', false);
}
}
File renamed without changes.
101 changes: 0 additions & 101 deletions test/classes/Display/ChangePasswordTest.php

This file was deleted.

50 changes: 50 additions & 0 deletions test/classes/Server/PrivilegesTest.php
Expand Up @@ -2082,4 +2082,54 @@ public function testDeleteUser(): void
$actual[1]->getMessage()
);
}

public function testGetFormForChangePassword(): void
{
global $route;

$username = 'pma_username';
$hostname = 'pma_hostname';
$route = '/server/privileges';

$html = $this->serverPrivileges->getFormForChangePassword($username, $hostname, false);

$this->assertStringContainsString(
Url::getFromRoute('/server/privileges'),
$html
);

//Url::getHiddenInputs
$this->assertStringContainsString(
Url::getHiddenInputs(),
$html
);

//$username & $hostname
$this->assertStringContainsString(
htmlspecialchars($username),
$html
);
$this->assertStringContainsString(
htmlspecialchars($hostname),
$html
);

//labels
$this->assertStringContainsString(
__('Change password'),
$html
);
$this->assertStringContainsString(
__('No Password'),
$html
);
$this->assertStringContainsString(
__('Password:'),
$html
);
$this->assertStringContainsString(
__('Password:'),
$html
);
}
}

0 comments on commit c92663a

Please sign in to comment.