diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php
index bd9a87ede5..c5301127d9 100644
--- a/libraries/classes/Server/Privileges.php
+++ b/libraries/classes/Server/Privileges.php
@@ -1613,233 +1613,60 @@ class Privileges
* Displays the fields used by the "new user" form as well as the
* "change login information / copy user" form.
*
- * @param string $mode are we creating a new user or are we just
- * changing one? (allowed values: 'new', 'change')
- * @param string $username User name
- * @param string $hostname Host name
- *
- * @global array $cfg the phpMyAdmin configuration
- * @global resource $user_link the database connection
+ * @param string $mode are we creating a new user or are we just
+ * changing one? (allowed values: 'new', 'change')
+ * @param string $user User name
+ * @param string $host Host name
*
* @return string a HTML snippet
*/
public function getHtmlForLoginInformationFields(
$mode = 'new',
- $username = null,
- $hostname = null
+ $user = null,
+ $host = null
) {
- list($username_length, $hostname_length) = $this->getUsernameAndHostnameLength();
+ global $pred_username, $pred_hostname, $username, $hostname, $new_username;
- if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
- $GLOBALS['pred_username'] = 'any';
+ list($usernameLength, $hostnameLength) = $this->getUsernameAndHostnameLength();
+
+ if (isset($username) && strlen($username) === 0) {
+ $pred_username = 'any';
}
- $html_output = '
' . "\n"
- . '' . __('Login Information') . ' ' . "\n"
- . '' . "\n"
- . '
' . "\n"
- . ' ' . __('User name:') . "\n"
- . ' ' . "\n"
- . '
' . "\n";
- $html_output .= '' . "\n";
-
- $html_output .= ''
- . __('Any user')
- . ' ' . "\n";
-
- $html_output .= ''
- . __('Use text field')
- . ': ' . "\n";
-
- $html_output .= ' ' . "\n"
- . ' ' . "\n";
-
- $html_output .= '
' . "\n";
-
- $html_output .= '
'
- . Message::notice(
- __(
- 'An account already exists with the same username '
- . 'but possibly a different hostname.'
- )
- )->getDisplay()
- . '
';
- $html_output .= '
';
-
- $html_output .= '' . "\n"
- . '' . "\n"
- . ' ' . __('Host name:') . "\n"
- . ' ' . "\n";
-
- $html_output .= '' . "\n"
- . ' dbi->fetchValue('SELECT USER();');
- if (! empty($_current_user)) {
- $thishost = str_replace(
- "'",
+ $currentUser = $this->dbi->fetchValue('SELECT USER();');
+ $thisHost = null;
+ if (! empty($currentUser)) {
+ $thisHost = str_replace(
+ '\'',
'',
mb_substr(
- $_current_user,
- mb_strrpos($_current_user, '@') + 1
+ $currentUser,
+ mb_strrpos($currentUser, '@') + 1
)
);
- if ($thishost != 'localhost' && $thishost != '127.0.0.1') {
- $html_output .= ' data-thishost="' . htmlspecialchars($thishost) . '" ';
- } else {
- unset($thishost);
- }
}
- $html_output .= '>' . "\n";
- unset($_current_user);
- // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
- if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
- switch (mb_strtolower($GLOBALS['hostname'])) {
+ if (! isset($pred_hostname) && isset($hostname)) {
+ switch (mb_strtolower($hostname)) {
case 'localhost':
case '127.0.0.1':
- $GLOBALS['pred_hostname'] = 'localhost';
+ $pred_hostname = 'localhost';
break;
case '%':
- $GLOBALS['pred_hostname'] = 'any';
+ $pred_hostname = 'any';
break;
default:
- $GLOBALS['pred_hostname'] = 'userdefined';
+ $pred_hostname = 'userdefined';
break;
}
}
- $html_output .= ''
- . __('Any host')
- . ' ' . "\n"
- . ''
- . __('Local')
- . ' ' . "\n";
- if (! empty($thishost)) {
- $html_output .= ''
- . __('This Host')
- . ' ' . "\n";
- }
- unset($thishost);
- $html_output .= ''
- . __('Use Host Table')
- . ' ' . "\n";
-
- $html_output .= ''
- . __('Use text field:') . ' ' . "\n"
- . ' ' . "\n"
- . ' ' . "\n";
-
- $html_output .= ' ' . "\n"
- . Util::showHint(
- __(
- 'When Host table is used, this field is ignored '
- . 'and values stored in Host table are used instead.'
- )
- )
- . '
' . "\n";
-
- $html_output .= '' . "\n"
- . '' . "\n"
- . ' ' . __('Password:') . "\n"
- . ' ' . "\n"
- . '' . "\n"
- . '' . "\n"
- . ($mode == 'change' ? ''
- . __('Do not change the password')
- . ' ' . "\n" : '')
- . '' . "\n"
- . ' '
- . __('Use text field')
- . ': ' . "\n"
- . ' ' . "\n"
- . ' ' . "\n"
- . ' ' . "\n"
- . 'Strength: '
- . ' '
- . ' ' . "\n"
- . '
' . "\n";
-
- $html_output .= '' . "\n"
- . '' . "\n"
- . ' ' . __('Re-type:') . "\n"
- . ' ' . "\n"
- . ' ' . "\n"
- . ' ' . "\n"
- . '
' . "\n"
- . ''
- . '
';
$serverType = Util::getServerType();
$serverVersion = $this->dbi->getVersion();
- $orig_auth_plugin = $this->getCurrentAuthenticationPlugin(
+ $authPlugin = $this->getCurrentAuthenticationPlugin(
$mode,
- $username,
- $hostname
+ $user,
+ $host
);
if (($serverType == 'MySQL'
@@ -1847,44 +1674,35 @@ class Privileges
|| ($serverType == 'MariaDB'
&& $serverVersion >= 50200)
) {
- $html_output .= __('Authentication Plugin')
- . ' ' . "\n";
-
- $auth_plugin_dropdown = $this->getHtmlForAuthPluginsDropdown(
- $orig_auth_plugin,
+ $isNew = true;
+ $authPluginDropdown = $this->getHtmlForAuthPluginsDropdown(
+ $authPlugin,
$mode,
'new'
);
} else {
- $html_output .= __('Password Hashing Method')
- . '
' . "\n";
- $auth_plugin_dropdown = $this->getHtmlForAuthPluginsDropdown(
- $orig_auth_plugin,
+ $isNew = false;
+ $authPluginDropdown = $this->getHtmlForAuthPluginsDropdown(
+ $authPlugin,
$mode,
'old'
);
}
- $html_output .= $auth_plugin_dropdown;
- $html_output .= '
'
- . Message::notice(
- __(
- 'This method requires using an \'SSL connection \' '
- . 'or an \'unencrypted connection that encrypts the password '
- . 'using RSA \'; while connecting to the server.'
- )
- . Util::showMySQLDocu('sha256-authentication-plugin')
- )
- ->getDisplay()
- . '
';
-
- $html_output .= '
' . "\n"
- // Generate password added here via jQuery
- . ' ' . "\n";
-
- return $html_output;
+ return $this->template->render('server/privileges/login_information_fields', [
+ 'pred_username' => $pred_username ?? null,
+ 'pred_hostname' => $pred_hostname ?? null,
+ 'username_length' => $usernameLength,
+ 'hostname_length' => $hostnameLength,
+ 'username' => $username ?? null,
+ 'new_username' => $new_username ?? null,
+ 'hostname' => $hostname ?? null,
+ 'this_host' => $thisHost,
+ 'is_change' => $mode === 'change',
+ 'auth_plugin' => $authPlugin,
+ 'auth_plugin_dropdown' => $authPluginDropdown,
+ 'is_new' => $isNew,
+ ]);
}
/**
diff --git a/templates/server/privileges/login_information_fields.twig b/templates/server/privileges/login_information_fields.twig
new file mode 100644
index 0000000000..d2af70eaa0
--- /dev/null
+++ b/templates/server/privileges/login_information_fields.twig
@@ -0,0 +1,87 @@
+
+ {% trans 'Login Information' %}
+
+
{% trans 'User name:' %}
+
+
+ {% trans 'Any user' %}
+ {% trans 'Use text field' %}
+
+
+
+
+
+ {{ 'An account already exists with the same username but possibly a different hostname.'|trans|notice }}
+
+
+
+
+
+ {% trans 'Host name:' %}
+
+
+
+ {% trans 'Any host' %}
+ {% trans 'Local' %}
+ {% if this_host is not empty %}
+ {% trans 'This host' %}
+ {% endif %}
+ {% trans 'Use host table' %}
+ {% trans 'Use text field' %}
+
+
+
+
+ {{ show_hint('When Host table is used, this field is ignored and values stored in Host table are used instead.'|trans) }}
+
+
+
+ {% trans 'Password:' %}
+
+
+ {% if is_change %}
+ {% trans 'Do not change the password' %}
+ {% endif %}
+ {% trans 'No password' %}
+ {% trans 'Use text field' %}
+
+
+
+ {% trans %}Strength:{% context %}Password strength{% endtrans %}
+
+
+
+
+
+ {% trans 'Re-type:' %}
+
+
+
+
+
+
+ {% if is_new %}
+ {% trans 'Authentication plugin' %}
+ {% else %}
+ {% trans 'Password hashing method' %}
+ {% endif %}
+
+
+
+ {{ auth_plugin_dropdown|raw }}
+
+
+ {% filter notice %}
+ {% trans %}
+ This method requires using an 'SSL connection ' or an 'unencrypted connection that encrypts the password using RSA '; while connecting to the server.
+ {% endtrans %}
+ {{ show_mysql_docu('sha256-authentication-plugin') }}
+ {% endfilter %}
+
+
+ {# Generate password added here via jQuery #}
+