Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorsgiehl <stefan@matomo.org>2022-07-08 14:46:36 +0300
committersgiehl <stefan@matomo.org>2022-07-08 16:18:40 +0300
commit2890ce3f97d5d3a85b4038d26b98187cb6f3c95f (patch)
tree7baa8818605b5a9d85124d67a9d5b297904d6b43 /core
parent89a44abd03df0102f860306628bd0d75987c3626 (diff)
parent5df7397b4276a8f23e5537b7ba84394f4238dbed (diff)
Merge branch 'next_release' into 4.x-dev
Diffstat (limited to 'core')
-rw-r--r--core/Db/Schema/Mysql.php9
-rw-r--r--core/Updates/4.11.0-rc2.php104
-rw-r--r--core/Validators/Login.php59
3 files changed, 110 insertions, 62 deletions
diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php
index 71bd54f39e..1f8bc7d5f9 100644
--- a/core/Db/Schema/Mysql.php
+++ b/core/Db/Schema/Mysql.php
@@ -53,7 +53,10 @@ class Mysql implements SchemaInterface
date_registered TIMESTAMP NULL,
ts_password_modified TIMESTAMP NULL,
idchange_last_viewed TIMESTAMP NULL,
- invite_status enum('accept','pending','decline','expired') DEFAULT 'accept',
+ invited_by VARCHAR(100) NULL,
+ invite_token VARCHAR(191) NULL,
+ invite_expired_at TIMESTAMP NULL,
+ invite_accept_at TIMESTAMP NULL,
PRIMARY KEY(login)
) ENGINE=$engine DEFAULT CHARSET=$charset
",
@@ -591,8 +594,8 @@ class Mysql implements SchemaInterface
$db = $this->getDb();
$db->query("INSERT IGNORE INTO " . Common::prefixTable("user") . "
(`login`, `password`, `email`, `twofactor_secret`, `superuser_access`, `date_registered`, `ts_password_modified`,
- `idchange_last_viewed`, `invite_status`)
- VALUES ( 'anonymous', '', 'anonymous@example.org', '', 0, '$now', '$now' , NULL, 'accept');");
+ `idchange_last_viewed`)
+ VALUES ( 'anonymous', '', 'anonymous@example.org', '', 0, '$now', '$now' , NULL);");
$model = new Model();
$model->addTokenAuth('anonymous', 'anonymous', 'anonymous default token', $now);
diff --git a/core/Updates/4.11.0-rc2.php b/core/Updates/4.11.0-rc2.php
new file mode 100644
index 0000000000..745abe583a
--- /dev/null
+++ b/core/Updates/4.11.0-rc2.php
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik\Updates;
+
+use Piwik\Common;
+use Piwik\Container\StaticContainer;
+use Piwik\Db;
+use Piwik\Piwik;
+use Piwik\Plugins\UsersManager\Emails\UserInviteEmail;
+use Piwik\Plugins\UsersManager\Model;
+use Piwik\Site;
+use Piwik\Updater;
+use Piwik\Updater\Migration;
+use Piwik\Updater\Migration\Factory as MigrationFactory;
+use Piwik\Updates as PiwikUpdates;
+
+/**
+ * Update for version 4.11.0-rc2
+ */
+class Updates_4_11_0_rc2 extends PiwikUpdates
+{
+ /**
+ * @var MigrationFactory
+ */
+ private $migration;
+
+ private $pendingUsers;
+
+ private $userTable;
+
+ public function __construct(MigrationFactory $factory)
+ {
+ $this->migration = $factory;
+ $this->userTable = Common::prefixTable('user');
+ }
+
+ /**
+ * @param Updater $updater
+ *
+ * @return Migration[]
+ */
+ public function getMigrations(Updater $updater)
+ {
+ try {
+ $this->pendingUsers = Db::fetchAll(
+ "SELECT * FROM $this->userTable WHERE invite_status = ? ",
+ ['pending']
+ );
+ } catch (\Exception $e) {
+ // ignore any errors. The column might not exist when updating from an older version,
+ // so there wouldn't be anything to update anyway
+ }
+ return [
+ $this->migration->db->dropColumn('user', 'invite_status'),
+ $this->migration->db->addColumns('user', ['invite_token' => 'VARCHAR(191) DEFAULT null']),
+ $this->migration->db->addColumns('user', ['invited_by' => 'VARCHAR(100) DEFAULT null']),
+ $this->migration->db->addColumns('user', ['invite_expired_at' => 'TIMESTAMP null DEFAULT null']),
+ $this->migration->db->addColumns('user', ['invite_accept_at' => 'TIMESTAMP null DEFAULT null']),
+ ];
+ }
+
+ public function doUpdate(Updater $updater)
+ {
+ $updater->executeMigrations(__FILE__, $this->getMigrations($updater));
+
+ $model = new Model();
+ if (!empty($this->pendingUsers)) {
+ foreach ($this->pendingUsers as $user) {
+ $model->deleteAllTokensForUser($user['login']);
+
+ $site = $model->getSitesAccessFromUser($user['login']);
+ if (isset($site[0])) {
+ $site = new Site($site[0]['site']);
+ $siteName = $site->getName();
+ } else {
+ $siteName = "Default Site";
+ }
+ //generate Token
+ $generatedToken = $model->generateRandomTokenAuth();
+
+ //attach token to user
+ $model->attachInviteToken($user['login'], $generatedToken, 7);
+
+ // send email
+ $email = StaticContainer::getContainer()->make(UserInviteEmail::class, [
+ 'currentUser' => Piwik::getCurrentUserLogin(),
+ 'invitedUser' => $user,
+ 'siteName' => $siteName,
+ 'token' => $generatedToken,
+ 'expiryInDays' => 7
+ ]);
+ $email->safeSend();
+ }
+ }
+ }
+}
diff --git a/core/Validators/Login.php b/core/Validators/Login.php
deleted file mode 100644
index f377f79bec..0000000000
--- a/core/Validators/Login.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-/**
- * Matomo - free/libre analytics platform
- *
- * @link https://matomo.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- */
-
-namespace Piwik\Validators;
-
-use Piwik\Piwik;
-use Piwik\SettingsPiwik;
-use Piwik\Plugins\UsersManager\API as APIUsersManager;
-
-class Login extends BaseValidator
-{
- protected $login;
- const loginMinimumLength = 2;
- const loginMaximumLength = 100;
-
-
- public function validate($value)
- {
- if (!SettingsPiwik::isUserCredentialsSanityCheckEnabled()
- && !empty($value)
- ) {
- return;
- }
-
- $l = strlen($value);
- if (!($l >= self::loginMinimumLength
- && $l <= self::loginMaximumLength
- && (preg_match('/^[A-Za-zÄäÖöÜüß0-9_.@+-]*$/D', $value) > 0))
- ) {
- throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidLoginFormat',
- array(self::loginMinimumLength, self::loginMaximumLength)));
- }
-
- $this->login = $value;
- return $this;
- }
-
- public function isUnique()
- {
- if (empty($this->login)) {
- throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidLoginFormat',
- array(self::loginMinimumLength, self::loginMaximumLength)));
- }
-
- if (APIUsersManager::getInstance()->userExists($this->login)) {
- throw new Exception(Piwik::translate('UsersManager_ExceptionLoginExists', $this->login));
- }
-
- if (APIUsersManager::getInstance()->userEmailExists($this->login)) {
- throw new Exception(Piwik::translate('UsersManager_ExceptionLoginExistsAsEmail', $this->login));
- }
- }
-} \ No newline at end of file