-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSignup.php
172 lines (148 loc) · 4.28 KB
/
Signup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace Piwik\Plugins\Signup;
use Piwik\Nonce;
use Piwik\Plugin;
use Piwik\View;
/**
* Add ability to anonymous users to signup
* and create a new site to track.
*/
class Signup extends Plugin
{
/**
* @var bool Whether the next api call requires password confirmation.
* Used to signup as anonymous.
*/
public static $disablePasswordConfirmationOnce = false;
/**
* @var bool
*/
private $allowNewUsersToSignup;
/**
* {@InheritDoc}
*/
public function __construct($pluginName = false)
{
parent::__construct($pluginName);
$settings = new SystemSettings();
$this->allowNewUsersToSignup = $settings->allowNewUsersToSignup->getValue();
}
/**
* @see \Piwik\Plugin::registerEvents()
*/
public function registerEvents()
{
return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Template.loginNav' => 'addSignupButton',
'Template.beforeContent' => 'addSignupForms',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Login.userRequiresPasswordConfirmation' => 'userRequiresPasswordConfirmation',
);
}
/**
* Listener to disable password confirmation once,
* to allow to signup as anonymous from api.
*/
public function userRequiresPasswordConfirmation(&$requiresPasswordConfirmation, $login)
{
if (self::$disablePasswordConfirmationOnce) {
$requiresPasswordConfirmation = false;
self::$disablePasswordConfirmationOnce = false;
}
}
/**
* Inject signup button in login form.
*
* @param string $html
* @param string $position
*/
public function addSignupButton(&$html, $position)
{
if ('bottom' !== $position) {
return;
}
$view = new View('@Signup/_signup-button');
$view->allowNewUsersToSignup = $this->allowNewUsersToSignup;
$html .= $view->render();
}
/**
* Inject forms needed for user and site creation
* in login page. Forms are hidden at the beginning.
*
* @param string $html
* @param string $page
*/
public function addSignupForms(&$html, $page)
{
if ('login' !== $page) {
return;
}
if (!$this->allowNewUsersToSignup) {
return;
}
$this->injectCreateUserForm($html, $page);
$this->injectCreateSiteForm($html, $page);
}
/**
* Inject user creation form.
*
* @param string $html
* @param string $page
*/
public function injectCreateUserForm(&$html, $page)
{
$view = new View('@Signup/_create-user-form');
$view->addForm(new FormSignup());
$view->nonce = Nonce::getNonce('Signup.signup');
$html .= $view->render();
}
/**
* Inject site creation form.
*
* @param string $html
* @param string $page
*/
public function injectCreateSiteForm(&$html, $page)
{
$view = new View('@Signup/_create-site-form');
$html .= $view->render();
}
/**
* Return list of plug-in specific JavaScript files to be imported by the asset manager.
*
* @param array $jsFiles
*
* @see \Piwik\AssetManager
*/
public function getJsFiles(&$jsFiles)
{
if (!$this->allowNewUsersToSignup) {
return;
}
$jsFiles[] = 'plugins/Signup/javascripts/signup.js';
}
/**
* Return list of plug-in specific CSS files to be imported by the asset manager.
*
* @param array $stylesheetFiles
*
* @see \Piwik\AssetManager
*/
public function getStylesheetFiles(&$stylesheetFiles)
{
$stylesheetFiles[] = 'plugins/Signup/stylesheets/signup.less';
}
/**
* Return list of plug-in specific translations keys needed in Javascript.
*
* @param array $translationKeys
*/
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = 'Installation_PasswordDoNotMatch';
$translationKeys[] = 'Installation_SetupWebsiteSetupSuccess';
$translationKeys[] = 'Signup_CancelSiteConfirm';
}
}