protected function lostPasswordFormValidated($loginMail, $urlToRedirect) { Piwik::setUserIsSuperUser(); $user = null; $isSuperUser = false; if ($loginMail == Zend_Registry::get('config')->superuser->email || $loginMail == Zend_Registry::get('config')->superuser->login) { $isSuperUser = true; $user = array('login' => Zend_Registry::get('config')->superuser->login, 'email' => Zend_Registry::get('config')->superuser->email); } else { if (Piwik_UsersManager_API::userExists($loginMail)) { $user = Piwik_UsersManager_API::getUser($loginMail); } else { if (Piwik_UsersManager_API::userEmailExists($loginMail)) { $user = Piwik_UsersManager_API::getUserByEmail($loginMail); } } } if ($user === null) { $messageNoAccess = Piwik_Translate('Login_InvalidUsernameEmail'); } else { $view = new Piwik_View('Login/templates/passwordsent.tpl'); $login = $user['login']; $email = $user['email']; $randomPassword = Piwik_Common::getRandomString(8); if ($isSuperUser) { $user['password'] = md5($randomPassword); Zend_Registry::get('config')->superuser = $user; } else { Piwik_UsersManager_API::updateUser($login, $randomPassword); } // send email with new password try { $mail = new Piwik_Mail(); $mail->addTo($email, $login); $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordRecovery')); $mail->setBodyText(str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordRecoveryBody'), $login, $randomPassword, Piwik_Url::getCurrentUrlWithoutQueryString()))); $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->linkTitle = Piwik::getRandomTitle(); $view->urlToRedirect = $urlToRedirect; echo $view->render(); } }
/** * normal case */ function test_getUser() { $login = "******"; $password = "******"; $email = "*****@*****.**"; $alias = ""; Piwik_UsersManager_API::addUser($login, $password, $email, $alias); $user = Piwik_UsersManager_API::getUser($login); // check that all fields are the same $this->assertEqual($user['login'], $login); $this->assertIsA($user['password'], 'string'); $this->assertIsA($user['date_registered'], 'string'); $this->assertEqual($user['email'], $email); //alias shouldnt be empty even if no alias specified $this->assertTrue(strlen($user['alias']) > 0); }
/** * Get user information * * @param string $loginMail (user login or email address) * @return array ("login" => '...', "email" => '...', "password" => '...') or null, if user not found */ protected function getUserInformation($loginMail) { Piwik::setUserIsSuperUser(); $user = null; if ($loginMail == Zend_Registry::get('config')->superuser->email || $loginMail == Zend_Registry::get('config')->superuser->login) { $user = array('login' => Zend_Registry::get('config')->superuser->login, 'email' => Zend_Registry::get('config')->superuser->email, 'password' => Zend_Registry::get('config')->superuser->password); } else { if (Piwik_UsersManager_API::userExists($loginMail)) { $user = Piwik_UsersManager_API::getUser($loginMail); } else { if (Piwik_UsersManager_API::userEmailExists($loginMail)) { $user = Piwik_UsersManager_API::getUserByEmail($loginMail); } } } return $user; }