feat(cloudron): add tirreno package artifacts
- Add CloudronStack/output/CloudronPackages-Artifacts/tirreno/ directory and its contents - Includes package manifest, Dockerfile, source code, documentation, and build artifacts - Add tirreno-1761840148.tar.gz as a build artifact - Add tirreno-cloudron-package-1761841304.tar.gz as the Cloudron package - Include all necessary files for the tirreno Cloudron package This adds the complete tirreno Cloudron package artifacts to the repository.
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
abstract class Base {
|
||||
use \Traits\Debug;
|
||||
use \Traits\ApiKeys;
|
||||
|
||||
protected $f3;
|
||||
protected $page;
|
||||
|
||||
public function __construct() {
|
||||
$this->f3 = \Base::instance();
|
||||
|
||||
if (!$this->f3->exists('SESSION.csrf')) {
|
||||
// Set anti-CSRF token.
|
||||
$this->f3->set('SESSION.csrf', bin2hex(\openssl_random_pseudo_bytes(16)));
|
||||
}
|
||||
|
||||
$this->f3->CSRF = $this->f3->get('SESSION.csrf');
|
||||
}
|
||||
|
||||
public function isPostRequest(): bool {
|
||||
return $this->f3->VERB === 'POST';
|
||||
}
|
||||
|
||||
// TODO: reverse
|
||||
public function getPageTitle(): string {
|
||||
$title = $this->f3->get(sprintf('%s_page_title', $this->page));
|
||||
|
||||
return $this->getInternalPageTitleWithPostfix($title);
|
||||
}
|
||||
|
||||
public function getInternalPageTitleWithPostfix(string $title): string {
|
||||
$title = $title ? $title : \Utils\Constants::get('UNAUTHORIZED_USERID');
|
||||
$safeTitle = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
|
||||
$title = sprintf('%s %s', $safeTitle, \Utils\Constants::get('PAGE_TITLE_POSTFIX'));
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getBreadcrumbTitle(): string {
|
||||
$page = $this->page;
|
||||
$i18nKey = sprintf('%s_breadcrumb_title', $page);
|
||||
|
||||
return $this->f3->get($i18nKey) ?? '';
|
||||
}
|
||||
|
||||
public function applyPageParams(array $params): array {
|
||||
$errorCode = $params['ERROR_CODE'] ?? null;
|
||||
$successCode = $params['SUCCESS_CODE'] ?? null;
|
||||
|
||||
if (!isset($params['PAGE_TITLE'])) {
|
||||
$pageTitle = $this->getPageTitle();
|
||||
$params['PAGE_TITLE'] = $pageTitle;
|
||||
}
|
||||
|
||||
if ($this->f3->get('EXTRA_CSS')) {
|
||||
$params['EXTRA_CSS'] = $this->f3->get('EXTRA_CSS');
|
||||
}
|
||||
|
||||
$breadCrumbTitle = $this->getBreadcrumbTitle();
|
||||
$params['BREADCRUMB_TITLE'] = $breadCrumbTitle;
|
||||
$params['CURRENT_PATH'] = $this->f3->PATH;
|
||||
|
||||
if ($errorCode) {
|
||||
$errorI18nCode = sprintf('error_%s', $errorCode);
|
||||
$errorMessage = $this->f3->get($errorI18nCode);
|
||||
$params['ERROR_MESSAGE'] = $errorMessage;
|
||||
}
|
||||
|
||||
if ($successCode) {
|
||||
$successI18nCode = sprintf('error_%s', $successCode);
|
||||
$successMessage = $this->f3->get($successI18nCode);
|
||||
$params['SUCCESS_MESSAGE'] = $successMessage;
|
||||
}
|
||||
|
||||
if (array_key_exists('ERROR_MESSAGE', $params)) {
|
||||
$time = gmdate('Y-m-d H:i:s');
|
||||
\Utils\TimeZones::localizeForActiveOperator($time);
|
||||
$params['ERROR_MESSAGE_TIMESTAMP'] = $time;
|
||||
}
|
||||
|
||||
if (array_key_exists('SUCCESS_MESSAGE', $params)) {
|
||||
$time = gmdate('Y-m-d H:i:s');
|
||||
\Utils\TimeZones::localizeForActiveOperator($time);
|
||||
$params['SUCCESS_MESSAGE_TIMESTAMP'] = $time;
|
||||
}
|
||||
|
||||
$currentOperator = $this->f3->get('CURRENT_USER');
|
||||
if ($currentOperator) {
|
||||
$cnt = $currentOperator->review_queue_cnt > 999 ? 999 : ($currentOperator->review_queue_cnt ?? 0);
|
||||
$params['NUMBER_OF_NOT_REVIEWED_USERS'] = $cnt;
|
||||
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
$now = time() + $offset;
|
||||
$day = (int) ceil(($now - mktime(0, 0, 0, 1, 1, gmdate('Y'))) / (60 * 60 * 24));
|
||||
|
||||
$params['OFFSET'] = $offset;
|
||||
$params['DAY'] = ($day < 10 ? '00' : ($day < 100 ? '0' : '')) . strval($day);
|
||||
$params['TIME_HIS'] = date('H:i:s', $now);
|
||||
$params['TIMEZONE'] = 'UTC' . (($offset < 0) ? '-' . date('H:i', -$offset) : '+' . date('H:i', $offset));
|
||||
}
|
||||
|
||||
$params['ALLOW_EMAIL_PHONE'] = \Utils\Variables::getEmailPhoneAllowed();
|
||||
|
||||
$page = $this->page;
|
||||
\Utils\DictManager::load($page);
|
||||
|
||||
$code = $this->f3->get('SESSION.extra_message_code');
|
||||
if ($code !== null) {
|
||||
$this->f3->clear('SESSION.extra_message_code');
|
||||
|
||||
if (!isset($params['SYSTEM_MESSAGES'])) {
|
||||
$params['SYSTEM_MESSAGES'] = [];
|
||||
}
|
||||
|
||||
$params['SYSTEM_MESSAGES'][] = [
|
||||
'text' => $this->f3->get('error_' . $code),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
$extra = $this->f3->get('EXTRA_APPLY_PAGE_PARAMS');
|
||||
if ($extra && is_callable($extra)) {
|
||||
$params = $extra($params, $page);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function integerParam($param): int {
|
||||
$validated = filter_var($param, FILTER_VALIDATE_INT);
|
||||
|
||||
return $validated !== false ? $validated : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class ChangeEmail extends Base {
|
||||
public $page = 'ChangeEmail';
|
||||
|
||||
public function getPageParams(): array {
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'changeEmail.html',
|
||||
];
|
||||
|
||||
$renewKey = $this->f3->get('PARAMS.renewKey');
|
||||
$errorCode = $this->validate($renewKey);
|
||||
$pageParams['SUCCESS_CODE'] = $errorCode;
|
||||
|
||||
if (!$errorCode) {
|
||||
//logout
|
||||
$this->f3->clear('SESSION');
|
||||
session_commit();
|
||||
|
||||
//change email
|
||||
$changeEmailModel = new \Models\ChangeEmail();
|
||||
$changeEmailModel->getByRenewKey($renewKey);
|
||||
|
||||
$newEmail = $changeEmailModel->email;
|
||||
$operatorId = $changeEmailModel->operator_id;
|
||||
|
||||
$changeEmailModel->deactivate();
|
||||
|
||||
$params = [
|
||||
'id' => $operatorId,
|
||||
'email' => $newEmail,
|
||||
];
|
||||
$operatorModel = new \Models\Operator();
|
||||
$operatorModel->updateEmail($params);
|
||||
|
||||
//update success message
|
||||
$pageParams['SUCCESS_CODE'] = \Utils\ErrorCodes::EMAIL_CHANGED;
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
|
||||
private function validate($renewKey): int|false {
|
||||
if (!$renewKey) {
|
||||
return \Utils\ErrorCodes::CHANGE_EMAIL_KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
$changeEmailModel = new \Models\ChangeEmail();
|
||||
$changeEmailModel->getByRenewKey($renewKey);
|
||||
if (!$changeEmailModel->loaded()) {
|
||||
return \Utils\ErrorCodes::CHANGE_EMAIL_KEY_IS_NOT_CORRECT;
|
||||
}
|
||||
|
||||
$currentTime = time();
|
||||
$linkTime = strtotime($changeEmailModel->created_at);
|
||||
$lifeTime = $this->f3->get('RENEW_PASSWORD_LINK_TIME');
|
||||
|
||||
if ($currentTime > $linkTime + $lifeTime) {
|
||||
return \Utils\ErrorCodes::CHANGE_EMAIL_KEY_WAS_EXPIRED;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class Error extends Base {
|
||||
public function getPageParams($errorData): array {
|
||||
$pageTitle = $this->getInternalPageTitleWithPostfix($errorData['code']);
|
||||
|
||||
return [
|
||||
'HTML_FILE' => 'error.html',
|
||||
'ERROR_DATA' => $errorData,
|
||||
'PAGE_TITLE' => $pageTitle,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class ForgotPassword extends Base {
|
||||
public $page = 'ForgotPassword';
|
||||
|
||||
public function getPageParams(): array {
|
||||
if (!\Utils\Variables::getForgotPasswordAllowed()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'forgotPassword.html',
|
||||
];
|
||||
|
||||
if ($this->isPostRequest()) {
|
||||
$params = $this->f3->get('POST');
|
||||
$errorCode = $this->validate($params);
|
||||
|
||||
if (!$errorCode) {
|
||||
$operatorModel = new \Models\Operator();
|
||||
$operatorModel->getActivatedByEmail($params['email']);
|
||||
|
||||
if ($operatorModel->loaded()) {
|
||||
// Create forgot password record.
|
||||
$forgotPasswordModel = new \Models\ForgotPassword();
|
||||
$forgotPasswordModel->add($operatorModel->id);
|
||||
|
||||
// Send forgot password email.
|
||||
$this->sendPasswordRenewEmail($operatorModel, $forgotPasswordModel);
|
||||
}
|
||||
|
||||
// Random sleep between 0.5 and 1 second to prevent timing attacks.
|
||||
usleep(rand(500000, 1000000));
|
||||
|
||||
// Always report back that the email was sent.
|
||||
$pageParams['SUCCESS_CODE'] = \Utils\ErrorCodes::RENEW_KEY_CREATED;
|
||||
}
|
||||
|
||||
$pageParams['VALUES'] = $params;
|
||||
$pageParams['ERROR_CODE'] = $errorCode;
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
|
||||
private function validate(array $params): int|false {
|
||||
$errorCode = \Utils\Access::CSRFTokenValid($params, $this->f3);
|
||||
if ($errorCode) {
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
if (!($params['email'] ?? null)) {
|
||||
return \Utils\ErrorCodes::EMAIL_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function sendPasswordRenewEmail(\Models\Operator $operatorModel, \Models\ForgotPassword $forgotPasswordModel): void {
|
||||
$url = \Utils\Variables::getSiteWithProtocol();
|
||||
|
||||
$toName = $operatorModel->firstname;
|
||||
$toAddress = $operatorModel->email;
|
||||
$renewKey = $forgotPasswordModel->renew_key;
|
||||
|
||||
$subject = $this->f3->get('ForgotPassowrd_renew_password_subject');
|
||||
$message = $this->f3->get('ForgotPassowrd_renew_password_body');
|
||||
|
||||
$renewUrl = sprintf('%s/password-recovering/%s', $url, $renewKey);
|
||||
$message = sprintf($message, $renewUrl);
|
||||
|
||||
\Utils\Mailer::send($toName, $toAddress, $subject, $message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class Login extends Base {
|
||||
public $page = 'Login';
|
||||
|
||||
public function getPageParams(): array {
|
||||
if (!\Utils\Variables::completedConfig()) {
|
||||
$this->f3->error(503);
|
||||
}
|
||||
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'login.html',
|
||||
'JS' => 'user_main.js',
|
||||
'ALLOW_FORGOT_PASSWORD' => \Utils\Variables::getForgotPasswordAllowed(),
|
||||
];
|
||||
|
||||
if ($this->isPostRequest()) {
|
||||
$params = $this->f3->get('POST');
|
||||
$errorCode = $this->validate($params);
|
||||
|
||||
if (!$errorCode) {
|
||||
$operatorsModel = new \Models\Operator();
|
||||
$operatorsModel->getActivatedByEmail($params['email']);
|
||||
|
||||
if ($operatorsModel->loaded() && $operatorsModel->verifyPassword($params['password'])) {
|
||||
$controller = new \Controllers\Admin\ReviewQueue\Navigation();
|
||||
$controller->getNumberOfNotReviewedUsers(true, true); // use cache, overall count
|
||||
|
||||
$this->f3->set('SESSION.active_user_id', $operatorsModel->id);
|
||||
$extra = $this->f3->get('EXTRA_LOGIN');
|
||||
if ($extra && is_callable($extra)) {
|
||||
$params = $extra();
|
||||
}
|
||||
$this->f3->reroute('/');
|
||||
} else {
|
||||
$errorCode = \Utils\ErrorCodes::EMAIL_OR_PASSWORD_IS_NOT_CORRECT;
|
||||
}
|
||||
}
|
||||
|
||||
$pageParams['VALUES'] = $params;
|
||||
$pageParams['ERROR_CODE'] = $errorCode;
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
|
||||
private function validate(array $params): int|false {
|
||||
$errorCode = \Utils\Access::CSRFTokenValid($params, $this->f3);
|
||||
if ($errorCode) {
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
if (!$params['email']) {
|
||||
return \Utils\ErrorCodes::EMAIL_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (!$params['password']) {
|
||||
return \Utils\ErrorCodes::PASSWORD_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class Logout extends Base {
|
||||
public $page = 'Logout';
|
||||
|
||||
public function getPageParams() {
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'logout.html',
|
||||
'JS' => 'user_main.js',
|
||||
];
|
||||
|
||||
if ($this->isPostRequest()) {
|
||||
$params = $this->f3->get('POST');
|
||||
$errorCode = \Utils\Access::CSRFTokenValid($params, $this->f3);
|
||||
|
||||
if (!$errorCode) {
|
||||
$this->f3->clear('SESSION');
|
||||
session_commit();
|
||||
|
||||
$this->f3->reroute('/');
|
||||
}
|
||||
|
||||
$pageParams['ERROR_CODE'] = $errorCode;
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class PasswordRecovering extends Base {
|
||||
public $page = 'PasswordRecovering';
|
||||
|
||||
public function getPageParams(): array {
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'passwordRecovering.html',
|
||||
];
|
||||
|
||||
$renewKey = $this->f3->get('PARAMS.renewKey');
|
||||
$errorCode = $this->validate($renewKey);
|
||||
$pageParams['SUCCESS_CODE'] = $errorCode;
|
||||
|
||||
if ($this->isPostRequest()) {
|
||||
$params = $this->f3->get('POST');
|
||||
$errorCode = $this->validatePost($params);
|
||||
|
||||
$pageParams['SUCCESS_CODE'] = 0;
|
||||
$pageParams['ERROR_CODE'] = $errorCode;
|
||||
|
||||
if (!$errorCode) {
|
||||
$forgotPasswordModel = new \Models\ForgotPassword();
|
||||
$forgotPasswordModel->getUnusedByRenewKey($renewKey);
|
||||
$operatorId = $forgotPasswordModel->operator_id;
|
||||
|
||||
$forgotPasswordModel->deactivate();
|
||||
|
||||
$params = [
|
||||
'id' => $operatorId,
|
||||
'new-password' => $params['new-password'],
|
||||
];
|
||||
|
||||
$operatorModel = new \Models\Operator();
|
||||
$operatorModel->updatePassword($params);
|
||||
$operatorModel->activateByOperator($operatorId);
|
||||
|
||||
$pageParams['SUCCESS_CODE'] = \Utils\ErrorCodes::ACCOUNT_ACTIVATED;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
|
||||
private function validate(string $renewKey): int|false {
|
||||
if (!$renewKey) {
|
||||
return \Utils\ErrorCodes::RENEW_KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
$forgotPasswordModel = new \Models\ForgotPassword();
|
||||
$forgotPasswordModel->getUnusedByRenewKey($renewKey);
|
||||
if (!$forgotPasswordModel->loaded()) {
|
||||
return \Utils\ErrorCodes::RENEW_KEY_IS_NOT_CORRECT;
|
||||
}
|
||||
|
||||
$currentTime = time();
|
||||
$linkTime = strtotime($forgotPasswordModel->created_at);
|
||||
$lifeTime = $this->f3->get('RENEW_PASSWORD_LINK_TIME');
|
||||
|
||||
if ($currentTime > $linkTime + $lifeTime) {
|
||||
return \Utils\ErrorCodes::RENEW_KEY_WAS_EXPIRED;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function validatePost(array $params): int|false {
|
||||
$errorCode = \Utils\Access::CSRFTokenValid($params, $this->f3);
|
||||
if ($errorCode) {
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
$newPassword = $params['new-password'];
|
||||
if (!$newPassword) {
|
||||
return \Utils\ErrorCodes::NEW_PASSWORD_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
$newPasswordLegth = strlen($newPassword);
|
||||
$minPasswordLegth = $this->f3->get('MIN_PASSWORD_LENGTH');
|
||||
if ($newPasswordLegth < $minPasswordLegth) {
|
||||
return \Utils\ErrorCodes::PASSWORD_IS_TO_SHORT;
|
||||
}
|
||||
|
||||
$passwordConfirmation = $params['password-confirmation'];
|
||||
if (!$passwordConfirmation) {
|
||||
return \Utils\ErrorCodes::PASSWORD_CONFIRMATION_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ($newPassword !== $passwordConfirmation) {
|
||||
return \Utils\ErrorCodes::PASSWORDS_ARE_NOT_EQUAL;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Controllers\Pages;
|
||||
|
||||
class Signup extends Base {
|
||||
public $page = 'Signup';
|
||||
|
||||
public function getPageParams() {
|
||||
$model = new \Models\Operator();
|
||||
if (count($model->getAll())) {
|
||||
$this->f3->error(404);
|
||||
}
|
||||
|
||||
$pageParams = [
|
||||
'HTML_FILE' => 'signup.html',
|
||||
'TIMEZONES' => \Utils\TimeZones::timeZonesList(),
|
||||
];
|
||||
|
||||
if ($this->isPostRequest()) {
|
||||
$params = $this->f3->get('POST');
|
||||
$errorCode = $this->validate($params);
|
||||
|
||||
$pageParams['ERROR_CODE'] = $errorCode;
|
||||
|
||||
if ($errorCode) {
|
||||
$pageParams['VALUES'] = $params;
|
||||
} else {
|
||||
$operatorModel = $this->addUser($params);
|
||||
|
||||
$operatorId = $operatorModel->id;
|
||||
$apiKey = $this->addDefaultApiKey($operatorId);
|
||||
$this->addDefaultRules($apiKey);
|
||||
|
||||
//$this->sendActivationEmail($operatorModel);
|
||||
$pageParams['SUCCESS_CODE'] = \Utils\ErrorCodes::ACCOUNT_CREATED;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::applyPageParams($pageParams);
|
||||
}
|
||||
|
||||
private function addDefaultApiKey($operatorId) {
|
||||
$data = [
|
||||
'quote' => $this->f3->get('DEFAULT_API_KEY_QUOTE'),
|
||||
'operator_id' => $operatorId,
|
||||
'skip_enriching_attributes' => \json_encode(array_keys(\Utils\Constants::get('ENRICHING_ATTRIBUTES'))),
|
||||
'skip_blacklist_sync' => true,
|
||||
];
|
||||
|
||||
$model = new \Models\ApiKeys();
|
||||
|
||||
return $model->add($data);
|
||||
}
|
||||
|
||||
private function addDefaultRules(int $apiKey): void {
|
||||
$model = new \Models\OperatorsRules();
|
||||
$defaultRules = \Utils\Constants::get('DEFAULT_RULES');
|
||||
|
||||
if (\Utils\Variables::getEmailPhoneAllowed()) {
|
||||
$defaultRules = array_merge($defaultRules, \Utils\Constants::get('DEFAULT_RULES_EXTENSION'));
|
||||
}
|
||||
|
||||
foreach ($defaultRules as $key => $value) {
|
||||
$model->updateRule($key, $value, $apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
private function addUser($data) {
|
||||
$model = new \Models\Operator();
|
||||
$model->add($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
private function sendActivationEmail(\Models\Operator $operatorModel): void {
|
||||
$url = \Utils\Variables::getSiteWithProtocol();
|
||||
|
||||
$toName = $operatorModel->firstname;
|
||||
$toAddress = $operatorModel->email;
|
||||
$activationKey = $operatorModel->activation_key;
|
||||
|
||||
$subject = $this->f3->get('Signup_activation_email_subject');
|
||||
$message = $this->f3->get('Signup_activation_email_body');
|
||||
|
||||
$activationUrl = sprintf('%s/account-activation/%s', $url, $activationKey);
|
||||
$message = sprintf($message, $activationUrl);
|
||||
|
||||
\Utils\Mailer::send($toName, $toAddress, $subject, $message);
|
||||
}
|
||||
|
||||
private function validate(array $params): int|false {
|
||||
$errorCode = \Utils\Access::CSRFTokenValid($params, $this->f3);
|
||||
if ($errorCode) {
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
$email = $params['email'];
|
||||
$password = $params['password'];
|
||||
|
||||
if (!$email) {
|
||||
return \Utils\ErrorCodes::EMAIL_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
$audit = \Audit::instance();
|
||||
if (!$audit->email($email, true)) {
|
||||
return \Utils\ErrorCodes::EMAIL_IS_NOT_CORRECT;
|
||||
}
|
||||
|
||||
$operatorsModel = new \Models\Operator();
|
||||
$operator = $operatorsModel->getByEmail($email);
|
||||
if ($operator) {
|
||||
return \Utils\ErrorCodes::EMAIL_ALREADY_EXIST;
|
||||
}
|
||||
|
||||
if (!$password) {
|
||||
return \Utils\ErrorCodes::PASSWORD_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
$passwordLegth = strlen($password);
|
||||
$minPasswordLegth = $this->f3->get('MIN_PASSWORD_LENGTH');
|
||||
if ($passwordLegth < $minPasswordLegth) {
|
||||
return \Utils\ErrorCodes::PASSWORD_IS_TO_SHORT;
|
||||
}
|
||||
|
||||
$timezone = $params['timezone'] ?? null;
|
||||
$timezones = $this->f3->get('timezones');
|
||||
if (!$timezone || !array_key_exists($timezone, $timezones)) {
|
||||
return \Utils\ErrorCodes::TIME_ZONE_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user