[Piwik-svn] r157 - in trunk: config modules modules/API plugins plugins/Installation plugins/Login plugins/UsersManager
svnmaster at piwik.org
svnmaster at piwik.org
Mon Jan 14 03:22:50 CET 2008
Author: matt
Date: 2008-01-14 03:22:49 +0100 (Mon, 14 Jan 2008)
New Revision: 157
Modified:
trunk/config/global.ini.php
trunk/modules/API/Request.php
trunk/modules/Access.php
trunk/modules/Piwik.php
trunk/plugins/Installation/Controller.php
trunk/plugins/Login.php
trunk/plugins/Login/Controller.php
trunk/plugins/UsersManager/API.php
Log:
Added anonymous user!! now you can grant access to your stats for given websites to the anonymous user.
You can't delete or update the anonymous user information.
Modified: trunk/config/global.ini.php
===================================================================
--- trunk/config/global.ini.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/config/global.ini.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -17,7 +17,7 @@
host = localhost
username = root
password =
-dbname = piwik_tests2
+dbname = piwik_tests3
tables_prefix = piwiktests_
adapter = PDO_MYSQL
Modified: trunk/modules/API/Request.php
===================================================================
--- trunk/modules/API/Request.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/modules/API/Request.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -217,8 +217,13 @@
if($outputFormatRequested == 'original')
{
throw $e;
- }
- $toReturn = $this->getExceptionOutput( $e->getMessage(), $outputFormatRequested);
+ }
+ $message = $e->getMessage();
+
+ // it seems that JSON doesn't like line breaks
+ $message = nl2br($message);
+
+ $toReturn = $this->getExceptionOutput( $message, $outputFormatRequested);
}
Modified: trunk/modules/Access.php
===================================================================
--- trunk/modules/Access.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/modules/Access.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -68,8 +68,8 @@
$idsitesByAccess = array( 'view' => array(), 'admin' => array(), 'superuser' => array());
// access = array ( idsite => accessIdSite, idsite2 => accessIdSite2)
- $result = $this->auth->authenticate();
-
+ $result = $this->auth->authenticate();
+
if($result->isValid())
{
$this->identity = $result->getIdentity();
@@ -173,13 +173,7 @@
* @throws Exception
*/
public function checkUserHasSomeAdminAccess()
- {
- //commented because bug when super user method called with unknown websites
-// if($this->isSuperUser)
-// {
-// return;
-// }
-
+ {
$idSitesAccessible = $this->getSitesIdWithAdminAccess();
if(count($idSitesAccessible) == 0)
{
@@ -194,13 +188,7 @@
* @throws Exception If for any of the websites the user doesn't have an ADMIN access
*/
public function checkUserHasAdminAccess( $idSites )
- {
- //commented because bug when super user method called with unknown websites
-// if($this->isSuperUser)
-// {
-// return;
-// }
-
+ {
if(!is_array($idSites))
{
$idSites = array($idSites);
@@ -224,11 +212,6 @@
*/
public function checkUserHasViewAccess( $idSites )
{
- //commented because bug when super user method called with unknown websites
-// if($this->isSuperUser)
-// {
-// return;
-// }
if(!is_array($idSites))
{
$idSites = array($idSites);
Modified: trunk/modules/Piwik.php
===================================================================
--- trunk/modules/Piwik.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/modules/Piwik.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -735,8 +735,21 @@
{
return (preg_match('/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z]{2,4}$/', $email) > 0);
}
+
+ /**
+ * Creates an entry in the User table for the "anonymous" user.
+ *
+ * @return void
+ */
+ static public function createAnonymousUser()
+ {
+ // The anonymous user is the user that is assigned by default
+ // note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
+ $db = Zend_Registry::get('db');
+ $db->query("INSERT INTO ". Piwik::prefixTable("user") . "
+ VALUES ( 'anonymous', '', 'anonymous', 'anonymous at example.org', 'anonymous', CURRENT_TIMESTAMP );" );
+ }
-
static public function createTables()
{
$db = Zend_Registry::get('db');
Modified: trunk/plugins/Installation/Controller.php
===================================================================
--- trunk/plugins/Installation/Controller.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/plugins/Installation/Controller.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -168,6 +168,7 @@
else
{
Piwik::createTables();
+ Piwik::createAnonymousUser();
$view->tablesCreated = true;
$view->showNextStep = true;
Modified: trunk/plugins/Login/Controller.php
===================================================================
--- trunk/plugins/Login/Controller.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/plugins/Login/Controller.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -1,7 +1,8 @@
<?php
require_once "UsersManager/API.php";
require_once "Login/Form.php";
-require_once "View.php";
+require_once "View.php";
+
class Piwik_Login_Controller extends Piwik_Controller
{
function getDefaultAction()
Modified: trunk/plugins/Login.php
===================================================================
--- trunk/plugins/Login.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/plugins/Login.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -68,9 +68,13 @@
$authCookieExpiry = time() + 3600;
$authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
+
+ // by defaul the login is anonymous
+ $login = 'anonymous';
+ // and the token_auth anonymous.
+ // Note that the user created in the DB has a token_auth value of anonymous
+ $tokenAuth = 'anonymous';
- $login = $tokenAuth = 'abc'; // if empty throw an exception
-
if($authCookie->isCookieFound())
{
$login = $authCookie->get('login');
Modified: trunk/plugins/UsersManager/API.php
===================================================================
--- trunk/plugins/UsersManager/API.php 2008-01-14 01:12:26 UTC (rev 156)
+++ trunk/plugins/UsersManager/API.php 2008-01-14 02:22:49 UTC (rev 157)
@@ -280,7 +280,8 @@
*/
static public function updateUser( $userLogin, $password = false, $email = false, $alias = false )
{
- Piwik::checkUserIsSuperUserOrTheUser($userLogin);
+ Piwik::checkUserIsSuperUserOrTheUser($userLogin);
+ self::checkUserIsNotAnonymous( $userLogin );
$userInfo = self::getUser($userLogin);
@@ -334,11 +335,14 @@
static public function deleteUser( $userLogin )
{
Piwik::checkUserIsSuperUser();
+ self::checkUserIsNotAnonymous( $userLogin );
if(!self::userExists($userLogin))
{
throw new Exception("User '$userLogin' doesn't exist therefore it can't be deleted.");
- }
+ }
+
+
self::deleteUserOnly( $userLogin );
self::deleteUserAccess( $userLogin );
}
@@ -377,6 +381,12 @@
{
self::checkAccessType( $access );
self::checkUserExists( $userLogin);
+
+ if($userLogin == 'anonymous'
+ && $access == 'admin')
+ {
+ throw new Exception("You cannot grant 'admin' access to the 'anonymous' user.");
+ }
// in case idSites is null we grant access to all the websites on which the current connected user
// has an 'admin' access
@@ -430,8 +440,15 @@
throw new Exception("User '$userLogin' doesn't exist.");
}
}
+
+ static private function checkUserIsNotAnonymous( $userLogin )
+ {
+ if($userLogin == 'anonymous')
+ {
+ throw new Exception("The anonymous user cannot be edited or deleted. It is used by Piwik to define a user that has not loggued in yet. For example, you can make your statistics public by granting the 'view' access to the 'anonymous' user.");
+ }
+ }
-
static private function checkAccessType($access)
{
$accessList = Piwik_Access::getListAccess();
@@ -498,7 +515,6 @@
static public function getTokenAuth($userLogin, $password)
{
return md5($userLogin . $password );
-
}
/**
More information about the Piwik-svn
mailing list