-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathController.php
137 lines (108 loc) · 3.11 KB
/
Controller.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
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
*
* @category Piwik_Plugins
* @package Piwik_Signup
*/
include_once "lib/securimage/securimage.php";
class Piwik_Signup_Controller extends Piwik_Controller
{
function index()
{
$this->register();
}
function register()
{
$messageNoAccess = null;
$form = new Piwik_Signup_RegisterForm();
if($form->validate())
{
try {
$this->registerFormValidated(
$form->getSubmitValue('form_login'),
$form->getSubmitValue('form_password'),
$form->getSubmitValue('form_email'),
$form->getSubmitValue('form_website_url'),
$form->getSubmitValue('form_website_name')
);
}
catch(Exception $e)
{
$messageNoAccess = $e->getMessage();
}
}
$view = Piwik_View::factory('register');
$view->AccessErrorString = $messageNoAccess;
$view->linkTitle = Piwik::getRandomTitle();
$view->addForm( $form );
$view->subTemplate = 'genericForm.tpl';
$view->rand = rand();
$view->enableCaptcha = Piwik_Signup::$enableCaptcha;
$this->setBasicVariablesView($view);
echo $view->render();
}
function showCaptcha()
{
$img = new securimage();
$img->show();
}
function registerFormValidated($userLogin, $password, $email, $siteUrl, $siteName)
{
Piwik::createAccessObject();
Piwik::setUserIsSuperUser();
$usersManagerApi = Piwik_UsersManager_API::getInstance();
$sitesManagerApi = Piwik_SitesManager_API::getInstance();
$usersManagerApi->addUser($userLogin, $password, $email);
try {
Piwik::createAccessObject();
Piwik::setUserIsSuperUser();
$idSite = $sitesManagerApi->addSite($siteName, $siteUrl);
$usersManagerApi->setUserAccess($userLogin, 'admin', $idSite);
}
catch( Exception $e )
{
// we need to delete user first
$usersManagerApi->deleteUser($userLogin);
throw $e;
}
$javascriptTag = $sitesManagerApi->getJavascriptTag($idSite);
$view = Piwik_View::factory('success');
$view->linkTitle = Piwik::getRandomTitle();
// send email with login, password & javascript tag
try
{
$mail = new Piwik_Mail();
$mail->addTo($email, $userLogin);
$mail->setSubject(Piwik_Translate('Signup_MailSubject'));
$bodyText = str_replace(
'\n',
"\n",
sprintf(Piwik_Translate('Signup_MailBody'), $userLogin, $userLogin, $password, $view->piwikUrl, $javascriptTag)
) . "\n";
$mail->setBodyText($bodyText);
$piwikHost = $_SERVER['HTTP_HOST'];
if(strlen($piwikHost) == 0)
{
$piwikHost = 'piwik.org';
}
$fromEmailName = Zend_Registry::get('config')->General->login_password_recovery_email_name;
$fromEmailAddress = Zend_Registry::get('config')->General->login_password_recovery_email_address;
$fromEmailAddress = str_replace('{DOMAIN}', $piwikHost, $fromEmailAddress);
$mail->setFrom($fromEmailAddress, $fromEmailName);
@$mail->send();
}
catch(Exception $e)
{
$view->ErrorString = $e->getMessage();
}
$view->javascriptTag = $javascriptTag;
$this->setBasicVariablesView($view);
echo $view->render();
exit;
}
}