Merge branch 'master' into feat-team-invite-improvements
This commit is contained in:
commit
3146ec363d
10 changed files with 181 additions and 209 deletions
|
@ -91,6 +91,8 @@ git clone git@github.com:[YOUR_FORK_HERE]/appwrite.git
|
||||||
|
|
||||||
cd appwrite
|
cd appwrite
|
||||||
|
|
||||||
|
git submodule update --init
|
||||||
|
|
||||||
docker compose build
|
docker compose build
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
|
@ -713,11 +713,33 @@ App::post('/v1/account/sessions/magic-url')
|
||||||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $loginSecret, 'expire' => $expire, 'project' => $project->getId()]);
|
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $loginSecret, 'expire' => $expire, 'project' => $project->getId()]);
|
||||||
$url = Template::unParseURL($url);
|
$url = Template::unParseURL($url);
|
||||||
|
|
||||||
|
$from = $project->isEmpty() || $project->getId() === 'console' ? '' : \sprintf($locale->getText('emails.sender'), $project->getAttribute('name'));
|
||||||
|
|
||||||
|
$body = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl');
|
||||||
|
$subject = $locale->getText("emails.magicSession.subject");
|
||||||
|
|
||||||
|
$body
|
||||||
|
->setParam('{{subject}}', $subject)
|
||||||
|
->setParam('{{hello}}', $locale->getText("emails.magicSession.hello"))
|
||||||
|
->setParam('{{name}}', '')
|
||||||
|
->setParam('{{body}}', $locale->getText("emails.magicSession.body"))
|
||||||
|
->setParam('{{redirect}}', $url)
|
||||||
|
->setParam('{{footer}}', $locale->getText("emails.magicSession.footer"))
|
||||||
|
->setParam('{{thanks}}', $locale->getText("emails.magicSession.thanks"))
|
||||||
|
->setParam('{{signature}}', $locale->getText("emails.magicSession.signature"))
|
||||||
|
->setParam('{{project}}', $project->getAttribute('name'))
|
||||||
|
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
||||||
|
->setParam('{{bg-body}}', '#f7f7f7')
|
||||||
|
->setParam('{{bg-content}}', '#ffffff')
|
||||||
|
->setParam('{{text-content}}', '#000000');
|
||||||
|
|
||||||
|
$body = $body->render();
|
||||||
|
|
||||||
$mails
|
$mails
|
||||||
->setType(MAIL_TYPE_MAGIC_SESSION)
|
->setSubject($subject)
|
||||||
|
->setBody($body)
|
||||||
|
->setFrom($from)
|
||||||
->setRecipient($user->getAttribute('email'))
|
->setRecipient($user->getAttribute('email'))
|
||||||
->setUrl($url)
|
|
||||||
->setLocale($locale->default)
|
|
||||||
->trigger()
|
->trigger()
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -1991,12 +2013,35 @@ App::post('/v1/account/recovery')
|
||||||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $profile->getId(), 'secret' => $secret, 'expire' => $expire]);
|
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $profile->getId(), 'secret' => $secret, 'expire' => $expire]);
|
||||||
$url = Template::unParseURL($url);
|
$url = Template::unParseURL($url);
|
||||||
|
|
||||||
|
$projectName = $project->isEmpty() ? 'Console' : $project->getAttribute('name', '[APP-NAME]');
|
||||||
|
$from = $project->isEmpty() || $project->getId() === 'console' ? '' : \sprintf($locale->getText('emails.sender'), $projectName);
|
||||||
|
$body = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl');
|
||||||
|
$subject = $locale->getText("emails.recovery.subject");
|
||||||
|
|
||||||
|
$body
|
||||||
|
->setParam('{{subject}}', $subject)
|
||||||
|
->setParam('{{hello}}', $locale->getText("emails.recovery.hello"))
|
||||||
|
->setParam('{{name}}', $profile->getAttribute('name'))
|
||||||
|
->setParam('{{body}}', $locale->getText("emails.recovery.body"))
|
||||||
|
->setParam('{{redirect}}', $url)
|
||||||
|
->setParam('{{footer}}', $locale->getText("emails.recovery.footer"))
|
||||||
|
->setParam('{{thanks}}', $locale->getText("emails.recovery.thanks"))
|
||||||
|
->setParam('{{signature}}', $locale->getText("emails.recovery.signature"))
|
||||||
|
->setParam('{{project}}', $projectName)
|
||||||
|
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
||||||
|
->setParam('{{bg-body}}', '#f7f7f7')
|
||||||
|
->setParam('{{bg-content}}', '#ffffff')
|
||||||
|
->setParam('{{text-content}}', '#000000');
|
||||||
|
|
||||||
|
$body = $body->render();
|
||||||
|
|
||||||
|
|
||||||
$mails
|
$mails
|
||||||
->setType(MAIL_TYPE_RECOVERY)
|
|
||||||
->setRecipient($profile->getAttribute('email', ''))
|
->setRecipient($profile->getAttribute('email', ''))
|
||||||
->setUrl($url)
|
|
||||||
->setLocale($locale->default)
|
|
||||||
->setName($profile->getAttribute('name'))
|
->setName($profile->getAttribute('name'))
|
||||||
|
->setBody($body)
|
||||||
|
->setFrom($from)
|
||||||
|
->setSubject($subject)
|
||||||
->trigger();
|
->trigger();
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -2151,11 +2196,32 @@ App::post('/v1/account/verification')
|
||||||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $verificationSecret, 'expire' => $expire]);
|
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $verificationSecret, 'expire' => $expire]);
|
||||||
$url = Template::unParseURL($url);
|
$url = Template::unParseURL($url);
|
||||||
|
|
||||||
|
$projectName = $project->isEmpty() ? 'Console' : $project->getAttribute('name', '[APP-NAME]');
|
||||||
|
$from = $project->isEmpty() || $project->getId() === 'console' ? '' : \sprintf($locale->getText('emails.sender'), $projectName);
|
||||||
|
$body = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl');
|
||||||
|
$subject = $locale->getText("emails.verification.subject");
|
||||||
|
$body
|
||||||
|
->setParam('{{subject}}', $subject)
|
||||||
|
->setParam('{{hello}}', $locale->getText("emails.verification.hello"))
|
||||||
|
->setParam('{{name}}', $user->getAttribute('name'))
|
||||||
|
->setParam('{{body}}', $locale->getText("emails.verification.body"))
|
||||||
|
->setParam('{{redirect}}', $url)
|
||||||
|
->setParam('{{footer}}', $locale->getText("emails.verification.footer"))
|
||||||
|
->setParam('{{thanks}}', $locale->getText("emails.verification.thanks"))
|
||||||
|
->setParam('{{signature}}', $locale->getText("emails.verification.signature"))
|
||||||
|
->setParam('{{project}}', $projectName)
|
||||||
|
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
||||||
|
->setParam('{{bg-body}}', '#f7f7f7')
|
||||||
|
->setParam('{{bg-content}}', '#ffffff')
|
||||||
|
->setParam('{{text-content}}', '#000000');
|
||||||
|
|
||||||
|
$body = $body->render();
|
||||||
|
|
||||||
$mails
|
$mails
|
||||||
->setType(MAIL_TYPE_VERIFICATION)
|
->setSubject($subject)
|
||||||
|
->setBody($body)
|
||||||
|
->setFrom($from)
|
||||||
->setRecipient($user->getAttribute('email'))
|
->setRecipient($user->getAttribute('email'))
|
||||||
->setUrl($url)
|
|
||||||
->setLocale($locale->default)
|
|
||||||
->setName($user->getAttribute('name'))
|
->setName($user->getAttribute('name'))
|
||||||
->trigger()
|
->trigger()
|
||||||
;
|
;
|
||||||
|
|
|
@ -459,28 +459,44 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS);
|
throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = Template::parseURL($url);
|
$url = Template::parseURL($url);
|
||||||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['membershipId' => $membership->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]);
|
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['membershipId' => $membership->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]);
|
||||||
$url = Template::unParseURL($url);
|
$url = Template::unParseURL($url);
|
||||||
|
|
||||||
// No need of confirmation when in admin or app mode
|
$projectName = $project->isEmpty() ? 'Console' : $project->getAttribute('name', '[APP-NAME]');
|
||||||
if (!empty($email)) {
|
|
||||||
$mails
|
$from = $project->isEmpty() || $project->getId() === 'console' ? '' : \sprintf($locale->getText('emails.sender'), $projectName);
|
||||||
->setType(MAIL_TYPE_INVITATION)
|
$body = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl');
|
||||||
->setRecipient($email)
|
$subject = \sprintf($locale->getText("emails.invitation.subject"), $team->getAttribute('name'), $projectName);
|
||||||
->setUrl($url)
|
$body->setParam('{{owner}}', $user->getAttribute('name'));
|
||||||
->setName($name)
|
$body->setParam('{{team}}', $team->getAttribute('name'));
|
||||||
->setLocale($locale->default)
|
|
||||||
->setTeam($team)
|
$body
|
||||||
->setUser($user)
|
->setParam('{{subject}}', $subject)
|
||||||
->trigger()
|
->setParam('{{hello}}', $locale->getText("emails.invitation.hello"))
|
||||||
;
|
->setParam('{{name}}', $user->getAttribute('name'))
|
||||||
} elseif (!empty($phone)) {
|
->setParam('{{body}}', $locale->getText("emails.invitation.body"))
|
||||||
$messaging
|
->setParam('{{redirect}}', $url)
|
||||||
->setRecipient($phone)
|
->setParam('{{footer}}', $locale->getText("emails.invitation.footer"))
|
||||||
->setMessage($url)
|
->setParam('{{thanks}}', $locale->getText("emails.invitation.thanks"))
|
||||||
->trigger();
|
->setParam('{{signature}}', $locale->getText("emails.invitation.signature"))
|
||||||
}
|
->setParam('{{project}}', $projectName)
|
||||||
|
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
||||||
|
->setParam('{{bg-body}}', '#f7f7f7')
|
||||||
|
->setParam('{{bg-content}}', '#ffffff')
|
||||||
|
->setParam('{{text-content}}', '#000000');
|
||||||
|
|
||||||
|
$body = $body->render();
|
||||||
|
|
||||||
|
$mails
|
||||||
|
->setSubject($subject)
|
||||||
|
->setBody($body)
|
||||||
|
->setFrom($from)
|
||||||
|
->setRecipient($invitee->getAttribute('email'))
|
||||||
|
->setName($invitee->getAttribute('name'))
|
||||||
|
->trigger()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
$events
|
$events
|
||||||
|
|
|
@ -98,13 +98,12 @@ App::init()
|
||||||
->inject('user')
|
->inject('user')
|
||||||
->inject('events')
|
->inject('events')
|
||||||
->inject('audits')
|
->inject('audits')
|
||||||
->inject('mails')
|
|
||||||
->inject('usage')
|
->inject('usage')
|
||||||
->inject('deletes')
|
->inject('deletes')
|
||||||
->inject('database')
|
->inject('database')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('mode')
|
->inject('mode')
|
||||||
->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $events, Audit $audits, Mail $mails, Stats $usage, Delete $deletes, EventDatabase $database, Database $dbForProject, string $mode) use ($databaseListener) {
|
->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $events, Audit $audits, Stats $usage, Delete $deletes, EventDatabase $database, Database $dbForProject, string $mode) use ($databaseListener) {
|
||||||
|
|
||||||
$route = $utopia->match($request);
|
$route = $utopia->match($request);
|
||||||
|
|
||||||
|
@ -178,10 +177,6 @@ App::init()
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
->setUser($user);
|
->setUser($user);
|
||||||
|
|
||||||
$mails
|
|
||||||
->setProject($project)
|
|
||||||
->setUser($user);
|
|
||||||
|
|
||||||
$audits
|
$audits
|
||||||
->setMode($mode)
|
->setMode($mode)
|
||||||
->setUserAgent($request->getUserAgent(''))
|
->setUserAgent($request->getUserAgent(''))
|
||||||
|
|
|
@ -4,6 +4,7 @@ use Appwrite\Event\Event;
|
||||||
use Appwrite\Event\Mail;
|
use Appwrite\Event\Mail;
|
||||||
use Appwrite\Network\Validator\CNAME;
|
use Appwrite\Network\Validator\CNAME;
|
||||||
use Appwrite\Resque\Worker;
|
use Appwrite\Resque\Worker;
|
||||||
|
use Appwrite\Template\Template;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
|
@ -12,6 +13,7 @@ use Utopia\Database\DateTime;
|
||||||
use Utopia\Database\ID;
|
use Utopia\Database\ID;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Domains\Domain;
|
use Utopia\Domains\Domain;
|
||||||
|
use Utopia\Locale\Locale;
|
||||||
|
|
||||||
require_once __DIR__ . '/../init.php';
|
require_once __DIR__ . '/../init.php';
|
||||||
|
|
||||||
|
@ -375,18 +377,38 @@ class CertificatesV1 extends Worker
|
||||||
Console::warning('Cannot renew domain (' . $domain . ') on attempt no. ' . $attempt . ' certificate: ' . $errorMessage);
|
Console::warning('Cannot renew domain (' . $domain . ') on attempt no. ' . $attempt . ' certificate: ' . $errorMessage);
|
||||||
|
|
||||||
// Send mail to administratore mail
|
// Send mail to administratore mail
|
||||||
|
|
||||||
|
$locale = new Locale(App::getEnv('_APP_LOCALE', 'en'));
|
||||||
|
if (!$locale->getText('emails.sender') || !$locale->getText("emails.certificate.hello") || !$locale->getText("emails.certificate.subject") || !$locale->getText("emails.certificate.body") || !$locale->getText("emails.certificate.footer") || !$locale->getText("emails.certificate.thanks") || !$locale->getText("emails.certificate.signature")) {
|
||||||
|
$locale->setDefault('en');
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl');
|
||||||
|
|
||||||
|
$subject = \sprintf($locale->getText("emails.certificate.subject"), $domain);
|
||||||
|
$body->setParam('{{domain}}', $domain);
|
||||||
|
$body->setParam('{{error}}', $errorMessage);
|
||||||
|
$body->setParam('{{attempt}}', $attempt);
|
||||||
|
|
||||||
|
$body
|
||||||
|
->setParam('{{subject}}', $subject)
|
||||||
|
->setParam('{{hello}}', $locale->getText("emails.certificate.hello"))
|
||||||
|
->setParam('{{body}}', $locale->getText("emails.certificate.body"))
|
||||||
|
->setParam('{{redirect}}', 'https://' . $domain)
|
||||||
|
->setParam('{{footer}}', $locale->getText("emails.certificate.footer"))
|
||||||
|
->setParam('{{thanks}}', $locale->getText("emails.certificate.thanks"))
|
||||||
|
->setParam('{{signature}}', $locale->getText("emails.certificate.signature"))
|
||||||
|
->setParam('{{project}}', 'Console')
|
||||||
|
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
||||||
|
->setParam('{{bg-body}}', '#f7f7f7')
|
||||||
|
->setParam('{{bg-content}}', '#ffffff')
|
||||||
|
->setParam('{{text-content}}', '#000000');
|
||||||
|
|
||||||
|
$body = $body->render();
|
||||||
$mail = new Mail();
|
$mail = new Mail();
|
||||||
$mail
|
$mail
|
||||||
->setType(MAIL_TYPE_CERTIFICATE)
|
|
||||||
->setRecipient(App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS'))
|
->setRecipient(App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS'))
|
||||||
->setUrl('https://' . $domain)
|
|
||||||
->setLocale(App::getEnv('_APP_LOCALE', 'en'))
|
|
||||||
->setName('Appwrite Administrator')
|
->setName('Appwrite Administrator')
|
||||||
->setPayload([
|
|
||||||
'domain' => $domain,
|
|
||||||
'error' => $errorMessage,
|
|
||||||
'attempt' => $attempt
|
|
||||||
])
|
|
||||||
->trigger();
|
->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Appwrite\Resque\Worker;
|
use Appwrite\Resque\Worker;
|
||||||
use Appwrite\Template\Template;
|
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Database\Document;
|
|
||||||
use Utopia\Locale\Locale;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../init.php';
|
require_once __DIR__ . '/../init.php';
|
||||||
|
|
||||||
|
@ -32,67 +29,12 @@ class MailsV1 extends Worker
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$project = new Document($this->args['project'] ?? []);
|
|
||||||
$user = new Document($this->args['user'] ?? []);
|
|
||||||
$team = new Document($this->args['team'] ?? []);
|
|
||||||
$payload = $this->args['payload'] ?? [];
|
|
||||||
|
|
||||||
$recipient = $this->args['recipient'];
|
$recipient = $this->args['recipient'];
|
||||||
$url = $this->args['url'];
|
$subject = $this->args['subject'];
|
||||||
$name = $this->args['name'];
|
$name = $this->args['name'];
|
||||||
$type = $this->args['type'];
|
$body = $this->args['body'];
|
||||||
$prefix = $this->getPrefix($type);
|
$from = $this->args['from'];
|
||||||
$locale = new Locale($this->args['locale']);
|
|
||||||
$projectName = $project->isEmpty() ? 'Console' : $project->getAttribute('name', '[APP-NAME]');
|
|
||||||
|
|
||||||
if (!$this->doesLocaleExist($locale, $prefix)) {
|
|
||||||
$locale->setDefault('en');
|
|
||||||
}
|
|
||||||
|
|
||||||
$from = $project->isEmpty() || $project->getId() === 'console' ? '' : \sprintf($locale->getText('emails.sender'), $projectName);
|
|
||||||
$body = Template::fromFile(__DIR__ . '/../config/locale/templates/email-base.tpl');
|
|
||||||
$subject = '';
|
|
||||||
switch ($type) {
|
|
||||||
case MAIL_TYPE_CERTIFICATE:
|
|
||||||
$domain = $payload['domain'];
|
|
||||||
$error = $payload['error'];
|
|
||||||
$attempt = $payload['attempt'];
|
|
||||||
|
|
||||||
$subject = \sprintf($locale->getText("$prefix.subject"), $domain);
|
|
||||||
$body->setParam('{{domain}}', $domain);
|
|
||||||
$body->setParam('{{error}}', $error);
|
|
||||||
$body->setParam('{{attempt}}', $attempt);
|
|
||||||
break;
|
|
||||||
case MAIL_TYPE_INVITATION:
|
|
||||||
$subject = \sprintf($locale->getText("$prefix.subject"), $team->getAttribute('name'), $projectName);
|
|
||||||
$body->setParam('{{owner}}', $user->getAttribute('name'));
|
|
||||||
$body->setParam('{{team}}', $team->getAttribute('name'));
|
|
||||||
break;
|
|
||||||
case MAIL_TYPE_RECOVERY:
|
|
||||||
case MAIL_TYPE_VERIFICATION:
|
|
||||||
case MAIL_TYPE_MAGIC_SESSION:
|
|
||||||
$subject = $locale->getText("$prefix.subject");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception('Undefined Mail Type : ' . $type, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
$body
|
|
||||||
->setParam('{{subject}}', $subject)
|
|
||||||
->setParam('{{hello}}', $locale->getText("$prefix.hello"))
|
|
||||||
->setParam('{{name}}', $name)
|
|
||||||
->setParam('{{body}}', $locale->getText("$prefix.body"))
|
|
||||||
->setParam('{{redirect}}', $url)
|
|
||||||
->setParam('{{footer}}', $locale->getText("$prefix.footer"))
|
|
||||||
->setParam('{{thanks}}', $locale->getText("$prefix.thanks"))
|
|
||||||
->setParam('{{signature}}', $locale->getText("$prefix.signature"))
|
|
||||||
->setParam('{{project}}', $projectName)
|
|
||||||
->setParam('{{direction}}', $locale->getText('settings.direction'))
|
|
||||||
->setParam('{{bg-body}}', '#f7f7f7')
|
|
||||||
->setParam('{{bg-content}}', '#ffffff')
|
|
||||||
->setParam('{{text-content}}', '#000000');
|
|
||||||
|
|
||||||
$body = $body->render();
|
|
||||||
|
|
||||||
/** @var \PHPMailer\PHPMailer\PHPMailer $mail */
|
/** @var \PHPMailer\PHPMailer\PHPMailer $mail */
|
||||||
$mail = $register->get('smtp');
|
$mail = $register->get('smtp');
|
||||||
|
@ -130,47 +72,4 @@ class MailsV1 extends Worker
|
||||||
public function shutdown(): void
|
public function shutdown(): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a prefix from a mail type
|
|
||||||
*
|
|
||||||
* @param $type
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getPrefix(string $type): string
|
|
||||||
{
|
|
||||||
switch ($type) {
|
|
||||||
case MAIL_TYPE_RECOVERY:
|
|
||||||
return 'emails.recovery';
|
|
||||||
case MAIL_TYPE_CERTIFICATE:
|
|
||||||
return 'emails.certificate';
|
|
||||||
case MAIL_TYPE_INVITATION:
|
|
||||||
return 'emails.invitation';
|
|
||||||
case MAIL_TYPE_VERIFICATION:
|
|
||||||
return 'emails.verification';
|
|
||||||
case MAIL_TYPE_MAGIC_SESSION:
|
|
||||||
return 'emails.magicSession';
|
|
||||||
default:
|
|
||||||
throw new Exception('Undefined Mail Type : ' . $type, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if all the required terms in a locale exist. False otherwise
|
|
||||||
*
|
|
||||||
* @param $locale
|
|
||||||
* @param $prefix
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function doesLocaleExist(Locale $locale, string $prefix): bool
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!$locale->getText('emails.sender') || !$locale->getText("$prefix.hello") || !$locale->getText("$prefix.subject") || !$locale->getText("$prefix.body") || !$locale->getText("$prefix.footer") || !$locale->getText("$prefix.thanks") || !$locale->getText("$prefix.signature")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
"utopia-php/orchestration": "0.6.*",
|
"utopia-php/orchestration": "0.6.*",
|
||||||
"utopia-php/preloader": "0.2.*",
|
"utopia-php/preloader": "0.2.*",
|
||||||
"utopia-php/registry": "0.5.*",
|
"utopia-php/registry": "0.5.*",
|
||||||
"utopia-php/storage": "0.11.*",
|
"utopia-php/storage": "0.13.*",
|
||||||
"utopia-php/swoole": "0.5.*",
|
"utopia-php/swoole": "0.5.*",
|
||||||
"utopia-php/websocket": "0.1.*",
|
"utopia-php/websocket": "0.1.*",
|
||||||
"resque/php-resque": "1.3.6",
|
"resque/php-resque": "1.3.6",
|
||||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "60bbe8610441d8b6e119bd322e0f5a13",
|
"content-hash": "dbc502462e4afa550b1a1bc3898020b3",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adhocore/jwt",
|
"name": "adhocore/jwt",
|
||||||
|
@ -2373,16 +2373,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/storage",
|
"name": "utopia-php/storage",
|
||||||
"version": "0.11.0",
|
"version": "0.13.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/storage.git",
|
"url": "https://github.com/utopia-php/storage.git",
|
||||||
"reference": "59802cf281d1976560cf6e353f250a9b870efddc"
|
"reference": "ad1c00f24ca56e73888acc2af3deee4919b1194b"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/59802cf281d1976560cf6e353f250a9b870efddc",
|
"url": "https://api.github.com/repos/utopia-php/storage/zipball/ad1c00f24ca56e73888acc2af3deee4919b1194b",
|
||||||
"reference": "59802cf281d1976560cf6e353f250a9b870efddc",
|
"reference": "ad1c00f24ca56e73888acc2af3deee4919b1194b",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -2422,9 +2422,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/storage/issues",
|
"issues": "https://github.com/utopia-php/storage/issues",
|
||||||
"source": "https://github.com/utopia-php/storage/tree/0.11.0"
|
"source": "https://github.com/utopia-php/storage/tree/0.13.2"
|
||||||
},
|
},
|
||||||
"time": "2022-08-31T09:17:31+00:00"
|
"time": "2022-12-20T11:11:35+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/swoole",
|
"name": "utopia-php/swoole",
|
||||||
|
|
|
@ -8,11 +8,10 @@ use Utopia\Database\Document;
|
||||||
class Mail extends Event
|
class Mail extends Event
|
||||||
{
|
{
|
||||||
protected string $recipient = '';
|
protected string $recipient = '';
|
||||||
protected string $url = '';
|
protected string $from = '';
|
||||||
protected string $type = '';
|
|
||||||
protected string $name = '';
|
protected string $name = '';
|
||||||
protected string $locale = '';
|
protected string $subject = '';
|
||||||
protected ?Document $team = null;
|
protected string $body = '';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -20,14 +19,14 @@ class Mail extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets team for the mail event.
|
* Sets subject for the mail event.
|
||||||
*
|
*
|
||||||
* @param Document $team
|
* @param string $subject
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setTeam(Document $team): self
|
public function setSubject(string $subject): self
|
||||||
{
|
{
|
||||||
$this->team = $team;
|
$this->subject = $subject;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -35,11 +34,11 @@ class Mail extends Event
|
||||||
/**
|
/**
|
||||||
* Returns set team for the mail event.
|
* Returns set team for the mail event.
|
||||||
*
|
*
|
||||||
* @return null|Document
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTeam(): ?Document
|
public function getSubject(): string
|
||||||
{
|
{
|
||||||
return $this->team;
|
return $this->subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,49 +65,49 @@ class Mail extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets url for the mail event.
|
* Sets from for the mail event.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $from
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setUrl(string $url): self
|
public function setFrom(string $from): self
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->from = $from;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns set url for the mail event.
|
* Returns from for mail event.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getURL(): string
|
public function getFrom(): string
|
||||||
{
|
{
|
||||||
return $this->url;
|
return $this->from;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets type for the mail event (use the constants starting with MAIL_TYPE_*).
|
* Sets body for the mail event.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $body
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setType(string $type): self
|
public function setBody(string $body): self
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->body = $body;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns set type for the mail event.
|
* Returns body for the mail event.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getType(): string
|
public function getBody(): string
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,29 +133,6 @@ class Mail extends Event
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets locale for the mail event.
|
|
||||||
*
|
|
||||||
* @param string $locale
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setLocale(string $locale): self
|
|
||||||
{
|
|
||||||
$this->locale = $locale;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns set locale for the mail event.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLocale(): string
|
|
||||||
{
|
|
||||||
return $this->locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event and sends it to the mails worker.
|
* Executes the event and sends it to the mails worker.
|
||||||
*
|
*
|
||||||
|
@ -166,15 +142,11 @@ class Mail extends Event
|
||||||
public function trigger(): string|bool
|
public function trigger(): string|bool
|
||||||
{
|
{
|
||||||
return Resque::enqueue($this->queue, $this->class, [
|
return Resque::enqueue($this->queue, $this->class, [
|
||||||
'project' => $this->project,
|
'from' => $this->from,
|
||||||
'user' => $this->user,
|
|
||||||
'payload' => $this->payload,
|
|
||||||
'recipient' => $this->recipient,
|
'recipient' => $this->recipient,
|
||||||
'url' => $this->url,
|
|
||||||
'locale' => $this->locale,
|
|
||||||
'type' => $this->type,
|
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'team' => $this->team,
|
'subject' => $this->subject,
|
||||||
|
'body' => $this->body,
|
||||||
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ class Func extends Model
|
||||||
'type' => self::TYPE_INTEGER,
|
'type' => self::TYPE_INTEGER,
|
||||||
'description' => 'Function execution timeout in seconds.',
|
'description' => 'Function execution timeout in seconds.',
|
||||||
'default' => 15,
|
'default' => 15,
|
||||||
'example' => 1592981237,
|
'example' => 15,
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue