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
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2014-05-04 09:24:45 +0400
committermattab <matthieu.aubry@gmail.com>2014-05-04 09:24:45 +0400
commitbd41c77e035ff2a674a68c749b69bea8cfd727b2 (patch)
tree488cb58169bcf51af4db52400c30dbc8662f6ae7 /plugins/Installation/FormSuperUser.php
parent406f63b9680b02e4dc9a1137efb3d4afd30fbef4 (diff)
Fixes #5080 Installation: when there is already a Super User, skip the installation step
+ rename step name
Diffstat (limited to 'plugins/Installation/FormSuperUser.php')
-rw-r--r--plugins/Installation/FormSuperUser.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/plugins/Installation/FormSuperUser.php b/plugins/Installation/FormSuperUser.php
new file mode 100644
index 0000000000..5e886983e4
--- /dev/null
+++ b/plugins/Installation/FormSuperUser.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\Installation;
+
+use HTML_QuickForm2_DataSource_Array;
+use HTML_QuickForm2_Factory;
+use HTML_QuickForm2_Rule;
+use Piwik\Piwik;
+use Piwik\Plugins\UsersManager\UsersManager;
+use Piwik\QuickForm2;
+
+/**
+ *
+ */
+class FormSuperUser extends QuickForm2
+{
+ function __construct($id = 'generalsetupform', $method = 'post', $attributes = null, $trackSubmit = false)
+ {
+ parent::__construct($id, $method, $attributes = array('autocomplete' => 'off'), $trackSubmit);
+ }
+
+ function init()
+ {
+ HTML_QuickForm2_Factory::registerRule('checkLogin', 'Piwik\Plugins\Installation\Rule_isValidLoginString');
+ HTML_QuickForm2_Factory::registerRule('checkEmail', 'Piwik\Plugins\Installation\Rule_isValidEmailString');
+
+ $login = $this->addElement('text', 'login')
+ ->setLabel(Piwik::translate('Installation_SuperUserLogin'));
+ $login->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_SuperUserLogin')));
+ $login->addRule('checkLogin');
+
+ $password = $this->addElement('password', 'password')
+ ->setLabel(Piwik::translate('Installation_Password'));
+ $password->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_Password')));
+ $pwMinLen = UsersManager::PASSWORD_MIN_LENGTH;
+ $pwMaxLen = UsersManager::PASSWORD_MAX_LENGTH;
+ $pwLenInvalidMessage = Piwik::translate('UsersManager_ExceptionInvalidPassword', array($pwMinLen, $pwMaxLen));
+ $password->addRule('length', $pwLenInvalidMessage, array('min' => $pwMinLen, 'max' => $pwMaxLen));
+
+ $passwordBis = $this->addElement('password', 'password_bis')
+ ->setLabel(Piwik::translate('Installation_PasswordRepeat'));
+ $passwordBis->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_PasswordRepeat')));
+ $passwordBis->addRule('eq', Piwik::translate('Installation_PasswordDoNotMatch'), $password);
+
+ $email = $this->addElement('text', 'email')
+ ->setLabel(Piwik::translate('Installation_Email'));
+ $email->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_Email')));
+ $email->addRule('checkEmail', Piwik::translate('UsersManager_ExceptionInvalidEmail'));
+
+ $this->addElement('checkbox', 'subscribe_newsletter_security', null, array(
+ 'content' => '&nbsp;&nbsp;' . Piwik::translate('Installation_SecurityNewsletter'),
+ ));
+
+ $this->addElement('checkbox', 'subscribe_newsletter_community', null, array(
+ 'content' => '&nbsp;&nbsp;' . Piwik::translate('Installation_CommunityNewsletter'),
+ ));
+
+ $this->addElement('submit', 'submit', array('value' => Piwik::translate('General_Next') . ' ยป', 'class' => 'submit'));
+
+ // default values
+ $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
+ 'subscribe_newsletter_community' => 1,
+ 'subscribe_newsletter_security' => 1,
+ )));
+ }
+}
+
+/**
+ * Login id validation rule
+ *
+ */
+class Rule_isValidLoginString extends HTML_QuickForm2_Rule
+{
+ function validateOwner()
+ {
+ try {
+ $login = $this->owner->getValue();
+ if (!empty($login)) {
+ Piwik::checkValidLoginString($login);
+ }
+ } catch (\Exception $e) {
+ $this->setMessage($e->getMessage());
+ return false;
+ }
+ return true;
+ }
+}
+
+/**
+ * Email address validation rule
+ *
+ */
+class Rule_isValidEmailString extends HTML_QuickForm2_Rule
+{
+ function validateOwner()
+ {
+ return Piwik::isValidEmailString($this->owner->getValue());
+ }
+}