fix: restore branding for recovery emails

This commit is contained in:
Chirag Aggarwal committed 2026-07-14 10:16:12 +05:30
1 parent f80416ad53
commit 8d07da3e4e
3 files changed
+58

No files matched your search

+23
View File
@@ -3827,6 +3827,14 @@ Http::post('/v1/account/recovery')
$customTemplate =
$project->getAttribute('templates', [])['email.recovery-' . $locale->default] ??
$project->getAttribute('templates', [])['email.recovery-' . $locale->fallback] ?? [];
$smtpBaseTemplate = $project->getAttribute('smtpBaseTemplate', 'email-base');
$validator = new FileName();
if (!$validator->isValid($smtpBaseTemplate)) {
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid template path');
}
$bodyTemplate = __DIR__ . '/../../config/locale/templates/' . $smtpBaseTemplate . '.tpl';
$message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl');
$message
@@ -3906,12 +3914,27 @@ Http::post('/v1/account/recovery')
'team' => ''
];
if ($smtpBaseTemplate === APP_BRANDED_EMAIL_BASE_TEMPLATE) {
$emailVariables = [
...$emailVariables,
'accentColor' => $platform['accentColor'],
'logoUrl' => $platform['logoUrl'],
'twitter' => $platform['twitterUrl'],
'discord' => $platform['discordUrl'],
'github' => $platform['githubUrl'],
'terms' => $platform['termsUrl'],
'privacy' => $platform['privacyUrl'],
'platform' => $platform['platformName'],
];
}
$publisherForMails->enqueue(new MailMessage(
project: $project,
recipient: $profile->getAttribute('email', ''),
name: $profile->getAttribute('name', ''),
subject: $subject,
template: MAIL_TEMPLATE_RECOVERY,
bodyTemplate: $bodyTemplate,
body: $body,
preview: $preview,
smtp: $smtpConfig,
@@ -16,6 +16,40 @@ final class AccountConsoleClientTest extends Scope
use ProjectConsole;
use SideClient;
public function testCreateRecoveryEmailBranding(): void
{
$email = ID::unique() . '@appwrite.io';
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'userId' => ID::unique(),
'email' => $email,
'password' => 'password',
'name' => 'Recovery User',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'email' => $email,
'url' => 'http://localhost/recovery',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$lastEmail = $this->getLastEmailByAddress($email);
$this->assertNotEmpty($lastEmail, 'Email not found for address: ' . $email);
$this->assertStringContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']);
}
/**
* Test that account deletion succeeds even with active team memberships.
* When the user is the sole owner and only member of a team, the team
@@ -1804,6 +1804,7 @@ final class AccountCustomClientTest extends Scope
$this->assertEquals($name, $lastEmail['to'][0]['name']);
$this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']);
$this->assertStringContainsStringIgnoringCase('Reset your ' . $this->getProject()['name'] . ' password using the link.', $lastEmail['text']);
$this->assertStringNotContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']);
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);