mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
update: address comments, remove name field and auto-derive.
This commit is contained in:
@@ -330,7 +330,6 @@
|
||||
const normalizedHttpsPort = (formState?.httpsPort || '').trim() || '443';
|
||||
const normalizedEmail = (formState?.emailCertificates || '').trim();
|
||||
const normalizedAssistantKey = (formState?.assistantOpenAIKey || '').trim();
|
||||
const normalizedAccountName = (formState?.accountName || '').trim();
|
||||
const normalizedAccountEmail = (formState?.accountEmail || '').trim();
|
||||
const normalizedAccountPassword = (formState?.accountPassword || '').trim();
|
||||
|
||||
@@ -343,7 +342,6 @@
|
||||
emailCertificates: normalizedEmail,
|
||||
opensslKey: (formState?.opensslKey || '').trim(),
|
||||
assistantOpenAIKey: normalizedAssistantKey,
|
||||
accountName: normalizedAccountName,
|
||||
accountEmail: normalizedAccountEmail,
|
||||
accountPassword: normalizedAccountPassword
|
||||
};
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
emailCertificates: null,
|
||||
opensslKey: null,
|
||||
assistantOpenAIKey: null,
|
||||
accountName: null,
|
||||
accountEmail: null,
|
||||
accountPassword: null
|
||||
};
|
||||
@@ -115,7 +114,6 @@
|
||||
setStateIfEmpty('emailCertificates', payload.emailCertificates);
|
||||
setStateIfEmpty('opensslKey', payload.opensslKey);
|
||||
setStateIfEmpty('assistantOpenAIKey', payload.assistantOpenAIKey);
|
||||
setStateIfEmpty('accountName', payload.accountName);
|
||||
setStateIfEmpty('accountEmail', payload.accountEmail);
|
||||
setStateIfEmpty('accountPassword', payload.accountPassword);
|
||||
};
|
||||
|
||||
@@ -262,15 +262,11 @@
|
||||
};
|
||||
|
||||
const hydrateStep3State = (root) => {
|
||||
State.setStateIfEmpty?.('accountName', root.querySelector('#account-name')?.value);
|
||||
State.setStateIfEmpty?.('accountEmail', root.querySelector('#account-email')?.value);
|
||||
State.setStateIfEmpty?.('accountPassword', root.querySelector('#account-password')?.value);
|
||||
};
|
||||
|
||||
const applyStep3State = (root) => {
|
||||
const name = root.querySelector('#account-name');
|
||||
if (name && formState.accountName) name.value = formState.accountName;
|
||||
|
||||
const email = root.querySelector('#account-email');
|
||||
if (email && formState.accountEmail) email.value = formState.accountEmail;
|
||||
|
||||
@@ -290,16 +286,13 @@
|
||||
hydrateStep3State(root);
|
||||
applyStep3State(root);
|
||||
|
||||
const name = root.querySelector('#account-name');
|
||||
const email = root.querySelector('#account-email');
|
||||
const password = root.querySelector('#account-password');
|
||||
const passwordToggle = root.querySelector('[data-password-toggle="account-password"]');
|
||||
|
||||
bindInputToState(name, 'accountName');
|
||||
bindInputToState(email, 'accountEmail');
|
||||
bindInputToState(password, 'accountPassword');
|
||||
|
||||
bindErrorClear?.(name);
|
||||
bindErrorClear?.(email);
|
||||
bindErrorClear?.(password);
|
||||
|
||||
@@ -429,15 +422,9 @@
|
||||
if (normalized === 3) {
|
||||
clearFieldErrors?.(root);
|
||||
let valid = true;
|
||||
const name = root?.querySelector('#account-name');
|
||||
const email = root?.querySelector('#account-email');
|
||||
const password = root?.querySelector('#account-password');
|
||||
|
||||
if (!name || !name.value.trim()) {
|
||||
setFieldError?.(name, 'This field is required');
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!email || !email.value.trim()) {
|
||||
setFieldError?.(email, 'This field is required');
|
||||
valid = false;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
$defaultAccountEmail = $defaultAccountEmail ?? '';
|
||||
$defaultAccountName = $defaultAccountName ?? '';
|
||||
$accountEmailValue = htmlspecialchars($defaultAccountEmail, ENT_QUOTES, 'UTF-8');
|
||||
$accountNameValue = htmlspecialchars($defaultAccountName, ENT_QUOTES, 'UTF-8');
|
||||
?>
|
||||
<div class="step-layout" data-step="3">
|
||||
<div class="stack-xl">
|
||||
@@ -15,18 +13,6 @@ $accountNameValue = htmlspecialchars($defaultAccountName, ENT_QUOTES, 'UTF-8');
|
||||
</div>
|
||||
|
||||
<div class="stack-l">
|
||||
<div class="input-group stack-xs">
|
||||
<label for="account-name" class="label-text typography-text-m-500 text-neutral-secondary">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="account-name"
|
||||
name="accountName"
|
||||
class="input-field typography-text-m-400 text-neutral-primary"
|
||||
placeholder="John Doe"
|
||||
value="<?php echo $accountNameValue; ?>"
|
||||
autocomplete="name"
|
||||
>
|
||||
</div>
|
||||
<div class="input-group stack-xs">
|
||||
<label for="account-email" class="label-text typography-text-m-500 text-neutral-secondary">Email</label>
|
||||
<input
|
||||
|
||||
@@ -314,12 +314,8 @@ class HttpHandler
|
||||
$assistantOpenAIKey = trim((string) ($input['assistantOpenAIKey'] ?? ''));
|
||||
$input['assistantOpenAIKey'] = $assistantOpenAIKey;
|
||||
|
||||
$account = [];
|
||||
if (!$this->config->isUpgrade()) {
|
||||
$accountName = trim((string) ($input['accountName'] ?? ''));
|
||||
if (!$this->state->isValidAccountName($accountName)) {
|
||||
$this->respondBadRequest('Please enter a name', $wantsStream, Server::STEP_ACCOUNT_SETUP);
|
||||
}
|
||||
|
||||
$accountEmail = trim((string) ($input['accountEmail'] ?? ''));
|
||||
if ($accountEmail === '' || !$this->state->isValidEmailAddress($accountEmail)) {
|
||||
$this->respondBadRequest('Please enter a valid email address', $wantsStream, Server::STEP_ACCOUNT_SETUP);
|
||||
@@ -330,9 +326,17 @@ class HttpHandler
|
||||
$this->respondBadRequest('Password must be at least 8 characters', $wantsStream, Server::STEP_ACCOUNT_SETUP);
|
||||
}
|
||||
|
||||
$input['accountName'] = $accountName;
|
||||
// Derive name from email
|
||||
$accountName = $this->deriveNameFromEmail($accountEmail);
|
||||
|
||||
$input['accountEmail'] = $accountEmail;
|
||||
$input['accountPassword'] = $accountPassword;
|
||||
|
||||
$account = [
|
||||
'name' => $accountName,
|
||||
'email' => $accountEmail,
|
||||
'password' => $accountPassword,
|
||||
];
|
||||
}
|
||||
|
||||
$lockedDatabase = $this->config->getLockedDatabase();
|
||||
@@ -474,11 +478,6 @@ class HttpHandler
|
||||
$vars = $this->config->getVars();
|
||||
$shouldGenerateSecrets = !$installer->hasExistingConfig() && !$this->config->isUpgrade();
|
||||
$envVars = $installer->prepareEnvironmentVariables($payloadInput, $vars, $shouldGenerateSecrets);
|
||||
$account = [
|
||||
'name' => $input['accountName'] ?? '',
|
||||
'email' => $input['accountEmail'] ?? '',
|
||||
'password' => $input['accountPassword'] ?? '',
|
||||
];
|
||||
|
||||
$this->state->writeProgressFile($installId, [
|
||||
'payload' => [
|
||||
@@ -487,8 +486,8 @@ class HttpHandler
|
||||
'database' => $lockedDatabase ?? ($input['database'] ?? 'mongodb'),
|
||||
'appDomain' => $input['appDomain'] ?? 'localhost',
|
||||
'emailCertificates' => $input['emailCertificates'] ?? '',
|
||||
'opensslKeyHash' => $this->state->hashSensitiveValue((string) ($input['opensslKey'] ?? '')),
|
||||
'assistantOpenAIKeyHash' => $this->state->hashSensitiveValue((string) ($input['assistantOpenAIKey'] ?? '')),
|
||||
'opensslKeyHash' => $this->state->hashSensitiveValue($input['opensslKey'] ?? ''),
|
||||
'assistantOpenAIKeyHash' => $this->state->hashSensitiveValue($input['assistantOpenAIKey'] ?? ''),
|
||||
],
|
||||
'step' => 'start',
|
||||
'status' => Server::STATUS_IN_PROGRESS,
|
||||
@@ -667,4 +666,23 @@ class HttpHandler
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives a name from an email address
|
||||
* Examples:
|
||||
* admin@example.com -> Admin
|
||||
* admin.123@example.com -> Admin123
|
||||
*/
|
||||
private function deriveNameFromEmail(string $email): string
|
||||
{
|
||||
// extract before @ symbol
|
||||
$parts = explode('@', $email);
|
||||
$username = $parts[0] ?? '';
|
||||
|
||||
// remove all non-alphanumeric characters
|
||||
$cleaned = preg_replace('/[^a-zA-Z0-9]/', '', $username);
|
||||
|
||||
// capitalize
|
||||
return ucfirst($cleaned);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user