diff options
author | Peter Zhang <peter@innocraft.com> | 2022-07-08 14:24:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 14:24:54 +0300 |
commit | 5df7397b4276a8f23e5537b7ba84394f4238dbed (patch) | |
tree | f38e8706090a4fb6d687415a89b29377d9bfda11 /core | |
parent | 49adc21534740eeb62a700562cdde095c7fa9589 (diff) |
update invite user (#19366)4.11.0-rc2
* update invite
update invite
* update tests and VUE error
update tests and VUE error
* built vue files
* update ui
update ui
* update vue
update vue
* update vue
update vue
* built vue files
* Update UsersManager_spec.js
update tests
* update clean
update clean
* Update UsersManager_spec.js
update success
* Update UsersManager_spec.js
remove popup error
* update tests order
update tests order
* Update UsersManager_next_click.png
updateui
* revert screenshot
revert screenshot
* delete if user if declined
delete use if declined
add privacy
split templated into 3 parts
* remove decline
remove decline
* add invited by column
add invited by column
* Revert "add invited by column"
This reverts commit e2358cb493684dc26fdf9a436d00a29981365861.
* Update UserRepository.php
add view user display
* add email tests and update admin email
add email tests and update admin email
* update php cs
update php cs
* add expire task and default setting
add expire task and default setting
* add api tests
add api tests
* add filter
add filter
* update ui tests
update ui tests
* built vue files
* update tests
update tests
* update signup and tests
update signup and tests
* update tests
update tests
* update screenshots
update screenshots
* update screenshots
update screenshots
* update ui
update ui
* update typo
update typo
* built vue files
* Update core/Updates/4.12.0-b1.php
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* Update plugins/UsersManager/API.php
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* Update plugins/UsersManager/UsersManager.php
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* Update plugins/UsersManager/lang/en.json
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* Update config/global.ini.php
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* update email date
update email date
* update typo
update typo
* update UI
update UI
* Updated UI screenshot
* Update plugins/Login/lang/en.json
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* Update plugins/Login/templates/invitationDecline.twig
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* update some feedbacks
update some feedbacks
* built vue files
* update feedbacks
update feedbacks
* update filter
update filter
* pending your can't reset password
pending your can't reset password
* fix php cs
fix php cs
* update column
update column
* built vue files
* set up terms in tests
set up terms in tests
* Update PendingUsers.php
setup website
* update tests and broken template
update tests
* update password
update password
* update screenshots
update screenshots
* add delete to admin
add delete to admin
* update invite success notification
update invite success notification
* add tests
add tests
* built vue files
* update tests
update tests
* update UI and checkbox
update UI and checkbox
* Update Invite_spec.js
show error screen
* update tests
update tests
* update lang
update lang
* Update OmniFixture-dump.sql
revert OmniFixture
* update wording
update wording
* update version
update version
* fix change column
fix change column
* Update UsersManagerTest.php
update tests
* Update Model.php
update tests
* Update Model.php
update tests
* remove fixes
remove fixes
* Revert "remove fixes"
This reverts commit f8fe33706513a32bf3386bc6b52800d68ec58562.
* update tests
update tests
* revert password reset
revert password reset
* update tests
update tests
* update resend
update resend
* update tests
update tests
* Update PasswordResetter.php
update tests
* correct pending user from last time
correct pending user from last time
* apply some fixes /improvements
* Apply suggestions from code review
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
* Allow composer plugins for dev dependency codesniffer to fix travis builds. (#19468)
Co-authored-by: peterhashair <peterhashair@users.noreply.github.com>
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
Co-authored-by: Ben <ben.burgess@innocraft.com>
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Co-authored-by: dizzy <diosmosis@users.noreply.github.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Db/Schema/Mysql.php | 9 | ||||
-rw-r--r-- | core/Updates/4.11.0-rc2.php | 104 | ||||
-rw-r--r-- | core/Validators/Login.php | 59 | ||||
-rw-r--r-- | core/Version.php | 2 |
4 files changed, 111 insertions, 63 deletions
diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index 00fb8c31e9..75d5787aaa 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 ", @@ -590,8 +593,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 diff --git a/core/Version.php b/core/Version.php index b4a96877dd..5afc9f951a 100644 --- a/core/Version.php +++ b/core/Version.php @@ -21,7 +21,7 @@ final class Version * The current Matomo version. * @var string */ - const VERSION = '4.11.0-rc1'; + const VERSION = '4.11.0-rc2'; const MAJOR_VERSION = 4; |