2019-05-09 06:54:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-11-11 22:02:42 +00:00
|
|
|
use Appwrite\Specification\Format\OpenAPI3;
|
|
|
|
|
use Appwrite\Specification\Format\Swagger2;
|
|
|
|
|
use Appwrite\Specification\Specification;
|
2021-12-14 09:11:34 +00:00
|
|
|
use Appwrite\Utopia\View;
|
2020-06-28 17:31:21 +00:00
|
|
|
use Utopia\App;
|
2020-03-28 12:42:16 +00:00
|
|
|
use Utopia\Config\Config;
|
2020-11-11 22:02:42 +00:00
|
|
|
use Utopia\Exception;
|
2020-12-23 06:09:16 +00:00
|
|
|
use Utopia\Validator\Range;
|
2020-05-17 05:27:10 +00:00
|
|
|
use Utopia\Validator\WhiteList;
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-29 21:43:34 +00:00
|
|
|
App::init(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2020-06-24 21:16:03 +00:00
|
|
|
$header = new View(__DIR__.'/../../views/home/comps/header.phtml');
|
|
|
|
|
$footer = new View(__DIR__.'/../../views/home/comps/footer.phtml');
|
|
|
|
|
|
|
|
|
|
$footer
|
2020-06-30 11:09:28 +00:00
|
|
|
->setParam('version', App::getEnv('_APP_VERSION', 'UNKNOWN'))
|
2020-06-24 21:16:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
$layout
|
|
|
|
|
->setParam('title', APP_NAME)
|
|
|
|
|
->setParam('description', '')
|
|
|
|
|
->setParam('class', 'home')
|
|
|
|
|
->setParam('platforms', Config::getParam('platforms'))
|
|
|
|
|
->setParam('header', [$header])
|
|
|
|
|
->setParam('footer', [$footer])
|
|
|
|
|
;
|
2020-06-29 21:43:34 +00:00
|
|
|
}, ['layout'], 'home');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-29 21:43:34 +00:00
|
|
|
App::shutdown(function ($response, $layout) {
|
2020-10-29 13:50:49 +00:00
|
|
|
/** @var Appwrite\Utopia\Response $response */
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2020-07-09 09:11:10 +00:00
|
|
|
$response->html($layout->render());
|
2020-06-29 21:43:34 +00:00
|
|
|
}, ['response', 'layout'], 'home');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('response')
|
2021-05-17 09:38:03 +00:00
|
|
|
->inject('dbForConsole')
|
2021-02-23 11:29:12 +00:00
|
|
|
->inject('project')
|
2021-05-17 09:38:03 +00:00
|
|
|
->action(function ($response, $dbForConsole, $project) {
|
2020-10-29 13:50:49 +00:00
|
|
|
/** @var Appwrite\Utopia\Response $response */
|
2021-05-17 09:38:03 +00:00
|
|
|
/** @var Utopia\Database\Database $dbForConsole */
|
|
|
|
|
/** @var Utopia\Database\Document $project */
|
2021-02-23 11:29:12 +00:00
|
|
|
|
|
|
|
|
$response
|
|
|
|
|
->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
|
|
|
|
->addHeader('Expires', 0)
|
|
|
|
|
->addHeader('Pragma', 'no-cache')
|
|
|
|
|
;
|
|
|
|
|
|
2021-05-13 05:59:00 +00:00
|
|
|
if ('console' === $project->getId() || $project->isEmpty()) {
|
2021-08-17 06:24:12 +00:00
|
|
|
$whitelistRoot = App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled');
|
2021-02-23 11:29:12 +00:00
|
|
|
|
2021-08-17 06:24:12 +00:00
|
|
|
if($whitelistRoot !== 'disabled') {
|
|
|
|
|
$count = $dbForConsole->count('users', [], 1);
|
2021-05-13 05:59:00 +00:00
|
|
|
|
2021-08-17 06:24:12 +00:00
|
|
|
if($count !== 0) {
|
2021-02-23 11:29:12 +00:00
|
|
|
return $response->redirect('/auth/signin');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response->redirect('/auth/signup');
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/signin')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/signin.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2021-02-23 11:29:12 +00:00
|
|
|
$page
|
2021-05-12 14:53:25 +00:00
|
|
|
->setParam('root', App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled'))
|
2021-02-23 11:29:12 +00:00
|
|
|
;
|
|
|
|
|
|
2019-05-09 06:54:39 +00:00
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Sign In - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/signup')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/signup.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2021-02-23 11:29:12 +00:00
|
|
|
$page
|
2021-05-12 14:53:25 +00:00
|
|
|
->setParam('root', App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled'))
|
2021-02-23 11:29:12 +00:00
|
|
|
;
|
|
|
|
|
|
2019-05-09 06:54:39 +00:00
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Sign Up - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/recovery')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/recovery.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2021-02-23 12:00:31 +00:00
|
|
|
$page
|
|
|
|
|
->setParam('smtpEnabled', (!empty(App::getEnv('_APP_SMTP_HOST'))))
|
|
|
|
|
;
|
|
|
|
|
|
2019-05-09 06:54:39 +00:00
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Password Recovery - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/confirm')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/confirm.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Account Confirmation - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/join')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/join.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Invitation - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/recovery/reset')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/recovery/reset.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
$layout
|
2019-09-26 18:47:48 +00:00
|
|
|
->setParam('title', 'Password Reset - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2020-04-08 11:00:50 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/oauth2/success')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2020-04-08 11:00:50 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2020-04-08 13:14:52 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/oauth2.phtml');
|
2020-04-08 11:00:50 +00:00
|
|
|
|
|
|
|
|
$layout
|
|
|
|
|
->setParam('title', APP_NAME)
|
|
|
|
|
->setParam('body', $page)
|
|
|
|
|
->setParam('header', [])
|
2021-08-31 09:22:48 +00:00
|
|
|
->setParam('footer', [])
|
|
|
|
|
;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
App::get('/auth/magic-url')
|
|
|
|
|
->groups(['web', 'home'])
|
|
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
|
|
|
|
->inject('layout')
|
2021-08-31 14:05:43 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2021-08-31 09:22:48 +00:00
|
|
|
|
|
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/magicURL.phtml');
|
|
|
|
|
|
|
|
|
|
$layout
|
|
|
|
|
->setParam('title', APP_NAME)
|
|
|
|
|
->setParam('body', $page)
|
|
|
|
|
->setParam('header', [])
|
2020-04-08 11:00:50 +00:00
|
|
|
->setParam('footer', [])
|
|
|
|
|
;
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2020-04-08 11:00:50 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/auth/oauth2/failure')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2020-04-08 11:00:50 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2020-04-08 13:14:52 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/home/auth/oauth2.phtml');
|
2020-04-08 11:00:50 +00:00
|
|
|
|
|
|
|
|
$layout
|
|
|
|
|
->setParam('title', APP_NAME)
|
|
|
|
|
->setParam('body', $page)
|
|
|
|
|
->setParam('header', [])
|
|
|
|
|
->setParam('footer', [])
|
|
|
|
|
;
|
2020-12-26 17:02:50 +00:00
|
|
|
});
|
2020-04-08 11:00:50 +00:00
|
|
|
|
2020-06-28 17:31:21 +00:00
|
|
|
App::get('/error/:code')
|
2020-06-25 18:32:12 +00:00
|
|
|
->groups(['web', 'home'])
|
2019-05-09 06:54:39 +00:00
|
|
|
->label('permission', 'public')
|
|
|
|
|
->label('scope', 'home')
|
|
|
|
|
->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false)
|
2020-12-26 17:02:50 +00:00
|
|
|
->inject('layout')
|
2020-06-30 11:09:28 +00:00
|
|
|
->action(function ($code, $layout) {
|
2021-12-14 09:11:34 +00:00
|
|
|
/** @var Appwrite\Utopia\View $layout */
|
2020-06-30 11:09:28 +00:00
|
|
|
|
2019-12-16 19:35:33 +00:00
|
|
|
$page = new View(__DIR__.'/../../views/error.phtml');
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
$page
|
|
|
|
|
->setParam('code', $code)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
$layout
|
2019-09-06 17:10:41 +00:00
|
|
|
->setParam('title', 'Error'.' - '.APP_NAME)
|
2019-05-09 06:54:39 +00:00
|
|
|
->setParam('body', $page);
|
2021-01-16 06:22:35 +00:00
|
|
|
});
|
2020-05-17 05:27:10 +00:00
|
|
|
|
2021-02-24 18:31:43 +00:00
|
|
|
App::get('/versions')
|
|
|
|
|
->desc('Get Version')
|
|
|
|
|
->groups(['web', 'home'])
|
|
|
|
|
->label('scope', 'public')
|
|
|
|
|
->inject('response')
|
|
|
|
|
->action(function ($response) {
|
|
|
|
|
/** @var Appwrite\Utopia\Response $response */
|
|
|
|
|
|
|
|
|
|
$platforms = Config::getParam('platforms');
|
|
|
|
|
|
|
|
|
|
$versions = [
|
|
|
|
|
'server' => APP_VERSION_STABLE,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach($platforms as $platform) {
|
|
|
|
|
$languages = $platform['languages'] ?? [];
|
|
|
|
|
|
|
|
|
|
foreach ($languages as $key => $language) {
|
|
|
|
|
if(isset($language['dev']) && $language['dev']) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(isset($language['enabled']) && !$language['enabled']) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$platformKey = $platform['key'] ?? '';
|
|
|
|
|
$languageKey = $language['key'] ?? '';
|
|
|
|
|
$version = $language['version'] ?? '';
|
|
|
|
|
$versions[$platformKey . '-' . $languageKey] = $version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response->json($versions);
|
2021-06-04 08:23:29 +00:00
|
|
|
});
|