[Eis-commits] SF.net SVN: eis: [206] trunk
Status: Pre-Alpha
Brought to you by:
baslijnse
|
From: <bas...@us...> - 2007-09-11 16:56:22
|
Revision: 206
http://eis.svn.sourceforge.net/eis/?rev=206&view=rev
Author: baslijnse
Date: 2007-09-11 09:56:12 -0700 (Tue, 11 Sep 2007)
Log Message:
-----------
Updated the user library. It now supports authentication based on services as pluggable authentication backends. Also started with a cleanup of the user module. This needs to be finished as most elements will have to be rewritten.
Modified Paths:
--------------
trunk/cfg/applications.xml
trunk/cfg/environments.xml
trunk/lib/engine/application.lib.php
trunk/lib/engine/engine.lib.php
trunk/lib/engine/session.lib.php
trunk/lib/engine/user.lib.php
trunk/mod/eis_engine/applications/servermanager.xml
trunk/mod/eis_engine/config/module.php
trunk/mod/eis_user/elements/ShowLogin.php
Added Paths:
-----------
trunk/lib/base/authservice.lib.php
trunk/mod/eis_engine/services/AuthService.php
trunk/mod/eis_user/locales/
trunk/mod/eis_user/locales/en_en/
trunk/mod/eis_user/locales/en_en/strings.xml
Removed Paths:
-------------
trunk/mod/eis_user/Service.php
trunk/mod/eis_user/elements/ActivateUser.php
trunk/mod/eis_user/elements/ActivateUser_tpl/
trunk/mod/eis_user/elements/AddToGroup.php
trunk/mod/eis_user/elements/DeleteUser.php
trunk/mod/eis_user/elements/DeleteUser_tpl/
trunk/mod/eis_user/elements/DisplayUser.php
trunk/mod/eis_user/elements/DisplayUserImage.php
trunk/mod/eis_user/elements/DisplayUserTitle.php
trunk/mod/eis_user/elements/DisplayUser_tpl/
trunk/mod/eis_user/elements/EditUser.php
trunk/mod/eis_user/elements/RemoveFromGroup.php
trunk/mod/eis_user/elements/SelectUser.php
trunk/mod/eis_user/elements/SignupUser.php
trunk/mod/eis_user/elements/SignupUser_tpl/
trunk/mod/eis_user/info.txt
trunk/mod/eis_user/lang/
trunk/mod/eis_user/mail/
Modified: trunk/cfg/applications.xml
===================================================================
--- trunk/cfg/applications.xml 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/cfg/applications.xml 2007-09-11 16:56:12 UTC (rev 206)
@@ -4,18 +4,18 @@
<name>eis-welcome</name>
<module>eis_engine</module>
<application>welcome</application>
- <environment>install</environment>
+ <environment>minimal</environment>
</application>
<application>
<name>eis-server</name>
<module>eis_engine</module>
<application>servermanager</application>
- <environment>dev</environment>
+ <environment>minimal</environment>
</application>
<application>
<name>eis-examples</name>
<module>eis_examples</module>
<application>examples</application>
- <environment>dev</environment>
+ <environment>minimal</environment>
</application>
</applications>
Modified: trunk/cfg/environments.xml
===================================================================
--- trunk/cfg/environments.xml 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/cfg/environments.xml 2007-09-11 16:56:12 UTC (rev 206)
@@ -10,6 +10,14 @@
<mail_errors>off</mail_errors>
</environment>
<environment>
+ <name>minimal</name>
+ <title>EIS Minimal environment</title>
+ <admin>root@localhost</admin>
+
+ <show_errors>on</show_errors>
+ <mail_errors>off</mail_errors>
+ </environment>
+ <environment>
<name>dev</name>
<title>EIS Development environment</title>
<admin>root@localhost</admin>
Added: trunk/lib/base/authservice.lib.php
===================================================================
--- trunk/lib/base/authservice.lib.php (rev 0)
+++ trunk/lib/base/authservice.lib.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -0,0 +1,30 @@
+<?php
+ /**
+ * Base interface class for authentication services.
+ * If a module implements this interface, EIS can use it to authenticate users
+ */
+ class AuthService extends Service {
+
+ /**
+ * Tries to authenticate a user by a login and password
+ *
+ * @param username the user's user name
+ * @param password the cleartext password
+ * @return a dictionary containing:
+ * id (integer), username, (string), displayname (string), permissions (array), preferences (dictionary)
+ */
+ function authByCredentials($username, $password) {
+ }
+ /**
+ * Tries to authenticate a user by a login and an md5 hash of the password and a seed.
+ * The hash is computed as md5(md5(password) . seed)
+ *
+ * @param username the user's user name
+ * @param seed the seed (random string) that the password is concatenated with
+ * @param hash the hash as computed by the client
+ * @return same dictionary as authByCredentials
+ */
+ function authByMD5($username, $seed, $hash) {
+ }
+ }
+?>
Modified: trunk/lib/engine/application.lib.php
===================================================================
--- trunk/lib/engine/application.lib.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/lib/engine/application.lib.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -14,8 +14,10 @@
var $modules = null;
var $title = null;
- var $version = null;
+ var $session_backend = null;
+ var $authentication_backend = null;
+
var $elements = array();
var $page_root = array();
@@ -61,8 +63,11 @@
$app = $struct->getValue($doc,'application');
$this->title = $struct->getValue($app,'title');
- $this->version = $struct->getValue($app,'version');
+ //Backends
+ $this->session_backend = $struct->getValue($app,'session_backend');
+ $this->authentication_backend = $struct->getValue($app,'authentication_backend');
+
//Module configuration
$modules = $struct->getArray($app,'module');
foreach($modules as $module) {
@@ -300,7 +305,8 @@
$cache = "<?php\n";
$cache .= "\$this->modules =".var_export($this->modules, true).";\n";
$cache .= "\$this->title =".var_export($this->title, true).";\n";
- $cache .= "\$this->version =".var_export($this->version, true).";\n";
+ $cache .= "\$this->session_backend =".var_export($this->session_backend, true).";\n";
+ $cache .= "\$this->authentication_backend =".var_export($this->authentication_backend, true).";\n";
$cache .= "\$this->elements =".var_export($this->elements, true).";\n";
$cache .= "\$this->page_root =".var_export($this->page_root, true).";\n";
$cache .= "\$this->page_notfound =".var_export($this->page_notfound, true).";\n";
@@ -317,6 +323,12 @@
function getEnvironment() {
return $this->environment;
}
+ function getSessionBackend() {
+ return $this->session_backend;
+ }
+ function getAuthenticationBackend() {
+ return $this->authentication_backend;
+ }
function getRequiredModules() {
return array_keys($this->modules);
}
Modified: trunk/lib/engine/engine.lib.php
===================================================================
--- trunk/lib/engine/engine.lib.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/lib/engine/engine.lib.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,8 +1,6 @@
<?php
- /** \todo Update all href* methods to the new url structure */
-
/**
- * The main engine class
+ * The EIS engine class
*/
class Engine {
@@ -11,10 +9,10 @@
var $services = array(); /**< Loaded services*/
var $currentModule = null; /**< Current rendered element's module */
var $currentElement = null; /**< Current rendered element */
- var $moduleConfig = array(); /**< variable containing array of moduleconfig elements*/
+ var $moduleConfig = array(); /**< Variable containing array of moduleconfig elements*/
/**< ENGINE STATUS VARIABLES */
- var $version = 'svn-trunk'; /**< engine version */
+ var $version = 'svn-trunk'; /**< Engine version */
var $baseHost = ''; /** < Host at which this server is located */
var $basePath = ''; /** < Path at which this server is located */
@@ -29,9 +27,10 @@
var $locale = null; /**< The locale instance */
var $session = null; /**< The session instance */
+ var $user = null; /**< The user instance */
/**
- * Creates the engine object and initializes.
+ * Engine constructor, gathers basic info about the environment.
*/
function Engine() {
@@ -45,70 +44,78 @@
$this->baseHost = $basehost;
$this->basePath = dirname($_SERVER['SCRIPT_NAME']).'/';
}
+
/** @name Private functions
* Private EIS functions
**/
/*@{*/
/**
- * Extracts all neccessary information from the request
+ * Extract all neccessary information from the request
*/
function _initRequest() {
require_once("lib/engine/request.lib.php");
$this->request = new Request($this);
}
/**
- * Initalizes the configuration of the EIS server.
+ * Initialize the configuration of the EIS server.
*/
function _initConfig() {
require_once("lib/engine/config.lib.php");
$this->config = new Config($this);
}
/**
- * Initilizes the engine for a request belonging to a web application
+ * Initialize the engine for a request belonging to a web application
*/
function _initApplication($application) {
require_once("lib/engine/application.lib.php");
+ require_once("lib/base/service.lib.php");
+ require_once("lib/base/authservice.lib.php");
require_once("lib/base/element.lib.php");
$this->application = new Application($this);
$this->application->load($application);
}
/**
- * Initializes the engine for a request belonging to a web service
+ * Initialize the engine for a request belonging to a web service
*/
function _initWebService($webservice) {
require_once("lib/engine/webservice.lib.php");
+ require_once("lib/base/service.lib.php");
$this->webservice = new WebService($this);
$this->webservice->load($webservice);
}
/**
- * Initializes the environment based on the
- * request type and config.
+ * Initialize the environment based on the request type and config.
*/
function _initEnvironment($environment) {
require_once("lib/engine/environment.lib.php");
$this->environment = new Environment($this);
$this->environment->load($environment);
}
-
/**
- * Initializes the locale
+ * Initialize locale
*/
function _initLocale($locale) {
require_once("lib/engine/locale.lib.php");
$this->locale = new Locale($this);
$this->locale->setLocale($locale);
}
-
/**
- *Initialize session
+ * Initialize session
*/
function _initSession() {
require("lib/engine/session.lib.php");
-
$this->session = new Session($this);
$this->session->load();
}
+ /**
+ * Initialize user
+ */
+ function _initUser() {
+ require("lib/engine/user.lib.php");
+ $this->user = new User($this);
+ $this->user->load();
+ }
/**
*Initialize logging
@@ -127,28 +134,6 @@
}
*/
/**
- *Initialize User
- */
- /*
- function _initUser() {
-
- $this->user = new User();
- $this->user->setEngine($this);
-
- //Full user support?
- if($this->databaseEnabled && $this->sessionEnabled) {
- $init = $this->user->init(true);
- $this->userEnabled = true;
- } else {
- $init = $this->user->init(false);
- }
-
- if (!$init)
- $this->error(1030, 'Unable tot initialize user: ' . $this->user->getError());
- }
- */
-
- /**
* Return's the main locale for a module. The main locale is
* the locale in which a module is maintained. Other locales are
* are translations of the main locale.
@@ -220,7 +205,6 @@
* Creates a service instance
*/
function _loadService($module, $service) {
- require_once("lib/base/service.lib.php");
$file = 'mod/'.$module.'/services/'.$service.'.php';
$class = $module.'_'.$service;
@@ -652,8 +636,8 @@
//Initialize the session
$this->_initSession();
- //Initialize user
- //Init user
+ //Initialize the user
+ $this->_initUser();
//Catch errors
ini_set('display_errors',TRUE);
@@ -1027,18 +1011,7 @@
function getPath() {
return $this->request->getPath();
}
- /**
- * Returns the id of the authenticated user or 0 if no user is authenticated
- */
- function getUserId() {
- //TODO
- }
- function getUserPermissions() {
- //TODO
- }
- function getUserPreferences() {
- //TODO
- }
+
function getLocale() {
//TODO: Get this from session/browser/whatever
return 'en_en';
Modified: trunk/lib/engine/session.lib.php
===================================================================
--- trunk/lib/engine/session.lib.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/lib/engine/session.lib.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -14,7 +14,7 @@
var $status; /**< Session status: new, renewed, expired */
var $age; /**< Session age in seconds */
- var $ttlAnonymous = 30; /**< Time to live for anonymous sessions */
+ var $ttlAnonymous = 3600; /**< Time to live for anonymous sessions */
var $ttlAuthenticated = 3600; /**< Time to live for authenticated sessions */
var $storage = 'file'; /**< Where to store the session data. file or database */
@@ -53,6 +53,9 @@
$this->storage = $storage;
}
}
+ function setUid($uid) {
+ //$this->uid = intval($uid);
+ }
function getStatus() {
return $this->status;
Modified: trunk/lib/engine/user.lib.php
===================================================================
--- trunk/lib/engine/user.lib.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/lib/engine/user.lib.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,259 +1,197 @@
<?php
/**
- *class which handles the user functions
+ * Class handling authentication and user permissions and preferences.
*/
class User {
- var $id; /**< id unknownk */
- var $engine; /**< engine variable */
+ var $e; /**< Reference to EIS engine */
- var $message; /**< message variable */
- var $errors = array(); /**< array of errors */
+ var $id; /**< User's id */
+ var $username; /**< User's user name */
+ var $displayname; /**< User's display name */
+ var $permissions; /**< User's permission */
+ var $preferences; /**< User's preferences */
- var $user = array(); /**< array of the user */
- var $clearances = array(0); /**< array of clearances for the user */
-
- var $login; /**< variable for the login */
- var $fullName; /**< variable for the fullname of a user */
- var $email; /**< variable for the user e-mail */
-
- var $seed;
-
- var $fullSupport;
-
+ var $error; /**< Error storage for authentication error */
/**
- *Set engine variable
- *@param engine engine reference
+ * Constructor
+ * @param engine A reference to the EIS engine
*/
- function setEngine(&$engine) {
- $this->engine =& $engine;
+ function User(&$engine) {
+ $this->e =& $engine;
+ $this->error = null;
+ $this->_resetUserProperties();
}
/**
- *Initialize user
+ * Resets all user related properties to default values.
*/
- function init($fullSupport = true) {
-
- $this->fullSupport = $fullSupport;
-
- if($fullSupport) {
- // Fetch user id from session
- $this->id = $this->engine->session->getUid();
- $this->seed =& $this->engine->session->getReference('login_seed','engine');
-
- if($this->id > 0) {
- $sUser = $this->engine->getService('user');
-
- //Load clearance
- $this->clearances = $sUser->getClearancesByUserId($this->id);
-
- //Load user
- $user = $sUser->getUserById($this->id);
- if($user != null) {
- $this->user = $user;
- $this->login = $user['login_username'];
- $this->fullName = $user['out_name'];
- $this->email = $user['out_email'];
- return true;
- }
- }
- }
-
- $this->id = 4;
- $this->login = "guest";
- $this->fullName = "Guest Account";
- $this->email = null;
- $this->clearances = array(0,4);
-
- return true;
+ function _resetUserProperties() {
+ $this->id = 0;
+ $this->username = '';
+ $this->displayname = 'Anonymous';
+ $this->permissions = array();
+ $this->preferences = array();
}
/**
- *Set message variable
- *@param msg message variable
+ * Sets user related properties based on the user object
+ *
+ * @param user the user object returned by the authentication service
*/
- function _setMessage($msg) {
- $this->message = $msg;
+ function _setUserProperties($user) {
+ $this->id = $user['id'];
+ $this->username = $user['username'];
+ $this->displayname = $user['displayname'];
+ $this->permissions = $user['permissions'];
+ $this->preferences = $user['preferences'];
}
/**
- *Get message from message variable
- *@result message
+ * Checks if the authentication service returned a valid user
+ * and stores it in the session when possible.
+ *
+ * @param user the user object returned by the authentication service
+ * @param error the error object returned by the authentication service
*/
- function getMessage() {
- return $this->message;
+ function _login($user, $error) {
+ if(is_array($user)) {
+ $this->_setUserProperties($user);
+ if($this->e->session !== null) {
+ $this->e->session->set('user',$user,'engine');
+ $this->e->session->setUid($user['id']);
+ $this->e->session->save();
+ return $user['id'];
+ }
+ return 0;
+ } else {
+ $this->error = $error;
+ return 0;
+ }
}
/**
- *Adds error to error array and warning to logfile
- *@param the errormessage to be added
+ * Checks if a user is logged in and loads details when this is the case.
*/
- function _addError($msg) {
- $this->errors[] = $msg;
- $this->engine->log->addWarning('USER-ERROR '.$msg,'user');
+ function load() {
+ //Check the session for a login
+ if($this->e->session !== null) {
+ $user = $this->e->session->get('user','engine');
+ if(is_array($user)) {
+ $this->_setUserProperties($user);
+ return;
+ }
+ }
}
/**
- *Get error from error array
- *@result array containing errors
+ * Login a user based on their username and password.
+ *
+ * @param username the user's username
+ * @param password the users's password
+ * @return the uid of the user (integer) or 0 when the login failed.
*/
- function getError() {
- return $this->errors;
+ function loginByCredentials($username, $password) {
+ $backend = $this->e->application->getAuthenticationBackend();
+ if(!is_array($backend)) {
+ return 0;
+ }
+ $service =& $this->e->getService($backend['module'],$backend['service']);
+
+ $user = $service->authByCredentials($username, $password);
+ $error = $service->getError();
+
+ return $this->_login($user,$error);
}
/**
- *Get Id from Id variable
- *@result variable containing an Id
+ * Log in a user based on their username and a hash of their password with a seed.
+ * The hash should be calculated as hash = md5(md5(password).seed)
+ *
+ * @param username the user's username
+ * @param seed the seed that was used for hashing the password
+ * @param hash the hash calculated from the password and seed
+ * @return the uid of the user (integer) or 0 when the login failed.
*/
- function getId() {
- return $this->id;
+ function loginByMD5($username, $seed, $hash) {
+ $backend = $this->e->application->getAuthenticationBackend();
+ if(!is_array($backend)) {
+ return 0;
+ }
+ $service =& $this->e->getService($backend['module'],$backend['service']);
+
+ $user = $service->authByMD5($username, $seed, $hash);
+ $error = $service->getError();
+
+ return $this->_login($user,$error);
}
/**
- *Get login variable
- *@result variable containing login
+ * Resets the user related properties and removes the user from the session
*/
- function getLogin() {
- return $this->login;
+ function logout() {
+ $this->_resetUserProperties();
+ if($this->e->session !== null) {
+ $this->e->session->clear('user','engine');
+ $this->e->session->setUid(0);
+ $this->e->session->save();
+ }
}
/**
- *Get Full name of user
- *@result full name of a user
+ * Get the error as returned by the authentication service
+ * @return an error datastructure as returned by services.
*/
- function getFullName() {
- return $this->fullName;
+ function getError() {
+ return $this->error;
}
/**
- *Get Clearances
- *@result variable containing clearances
+ * Get id variable
+ * @return user id
*/
- function getClearances() {
- return $this->clearances;
+ function getId() {
+ return $this->id;
}
/**
- *Determine if Clearance by zone
- *@param zone the zone for which clearance has to be retrieved
- *@result true or false
+ * Get username variable
+ * @return username
*/
- function hasClearance($zone) {
- return in_array($zone, $this->clearances);
+ function getUserName() {
+ return $this->username;
}
/**
- *Key generator
- *@result a random genrated key
+ * Get displayname variable
+ * @return displayname
*/
- function generateKey() {
- $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $key = "";
-
- for ($i = 0; $i < 32; $i++) {
- $key = $key . substr($chars, rand(0, 62), 1);
- }
-
- return $key;
+ function getDisplayName() {
+ return $this->displayname;
}
/**
- *Get login seed
- *@result returns variable containing seed
- */
- function getLoginSeed() {
-
- $seed = $this->generateKey();
-
- //Store pre-hashed version of seed
- $this->seed = md5($seed);
- $this->engine->session->save();
-
- return $seed;
+ * Get permissions
+ * @return an array of permission identifiers
+ */
+ function getPermissions() {
+ return $this->permissions;
}
-
/**
- *Log in as User
- *@param username string containing user'susername
- *@param password string containing user's password
- *@param hashed bool is true or false
- *@result user Id on succes or 0 on failure
- */
- function logIn($username, $password, $hashed = true) {
-
- if(!$this->fullSupport)
- return 0;
-
- //Load service
- $sUser = $this->engine->getService('user');
-
- //Try login
- if($hashed)
- $uid = $sUser->getUidByLogin($username, $password, $this->seed);
- else
- $uid = $sUser->getUidByLogin($username, $password, null);
-
- //Chech user
- if($uid == 0) {
- $errors = $sUser->getErrors();
- foreach($errors as $error)
- $this->_addError($error);
-
- $this->_setMessage('auth_failed');
- return 0;
- }
-
- //Init with verified user id
- $this->engine->session->setUid($uid);
- $this->init();
-
- //Set session variable 'me' indicating the authenticated user
- //for use with user module elements.
- $me =& $this->engine->session->getReference('me','module','user');
- $me = $uid;
-
- //Set session variable 'user.me' for general use. Nu skool :)
- $this->engine->session->setValue('user.me',$uid);
-
- $this->engine->session->save();
-
- //Log login action
- $this->engine->log->addMessage('LOGIN '.$this->getFullName(),'user');
-
- return $uid;
+ * Check if a given permission is available
+ * @param permission the required permission
+ * @return true when the user has the permission, false otherwise
+ */
+ function hasPermission($permission) {
+ return in_array($permission, $this->permissions);
}
/**
- *Log in via user Id and not username and password
- *@param id variable containing integer of user Id
- *@result the user Id
+ * Get preferences
+ * @return a dictionary with preference values
*/
- function loginByUserId($id) {
-
- if(!$this->fullSupport)
- return 0;
-
- $this->engine->session->setUid($id);
- $this->init();
-
- $me =& $this->engine->session->getReference('me','module','user');
- $me = $id;
- $this->engine->session->save();
-
- return $id;
+ function getPreferences() {
+ return $this->preferences;
}
/**
- *Log out
- *result user id on succes or 0 on failure
+ * Get the value of a preference
+ * @param default a default value that is returned when the preference is not set for this user.
+ * @return the value of the preference.
*/
- function logOut() {
-
- if(!$this->fullSupport)
- return 0;
-
- //Log logout action
- $this->engine->log->addMessage('LOGOUT '.$this->getFullName(),'user');
-
- $this->engine->session->setUid(0);
- $this->engine->session->clear();
-
- if (! $this->engine->session->save()) {
- $this->_addError("Unable to reset user ID: could not save session");
- return 0;
+ function getPreference($preference, $default = null) {
+ if(isset($this->preferences[$preference])) {
+ return $this->preferences[$preference];
+ } else {
+ return $default;
}
-
- //Reinitialize user
- $this->init();
-
- return $this->id;
}
}
?>
Modified: trunk/mod/eis_engine/applications/servermanager.xml
===================================================================
--- trunk/mod/eis_engine/applications/servermanager.xml 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_engine/applications/servermanager.xml 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,8 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<application>
<title>EIS Server Manager</title>
- <version>0.1</version>
+ <authentication_backend>
+ <module>eis_engine</module>
+ <service>AuthService</service>
+ </authentication_backend>
+
+ <session_backend>
+ <module>eis_session</module>
+ <service>FileStoreSessionService</service>
+ </session_backend>
+
<page_root>
<meta><name>menu-entry</name><value>eis_engine.l.home</value></meta>
<element>
Modified: trunk/mod/eis_engine/config/module.php
===================================================================
--- trunk/mod/eis_engine/config/module.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_engine/config/module.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,4 +1,6 @@
<?php
+ $cfg['admin_password'] = 'eisroxx';
+
$cfg['redirect_404'] = null;
$cfg['redirect_403'] = null;
Added: trunk/mod/eis_engine/services/AuthService.php
===================================================================
--- trunk/mod/eis_engine/services/AuthService.php (rev 0)
+++ trunk/mod/eis_engine/services/AuthService.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -0,0 +1,37 @@
+<?php
+ class eis_engine_AuthService extends AuthService {
+
+ /**
+ * Implementation of the authByCredentials interface of AuthService
+ */
+ function authByCredentials($username, $password) {
+ if($username == 'admin' && $password == $this->mc['admin_password']) {
+ return $this->_getAdminUser();
+ } else {
+ return null;
+ }
+ }
+ /**
+ * Implementation of the authByMD5 interface of AuthService
+ */
+ function authByMD5($username, $seed, $hash) {
+ if($username == 'admin' && md5(md5($this->mc['admin_password']).$seed) == $hash) {
+ return $this->_getAdminUser();
+ } else {
+ return null;
+ }
+ }
+ /**
+ * Returns a hardcoded record for the administrator user
+ */
+ function _getAdminUser() {
+ return array(
+ 'id' => 1,
+ 'username' => 'admin',
+ 'displayname' => 'Administrator',
+ 'permissions' => array('eis_engine.administrator'),
+ 'preferences' => array()
+ );
+ }
+ }
+?>
Deleted: trunk/mod/eis_user/Service.php
===================================================================
--- trunk/mod/eis_user/Service.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_user/Service.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,901 +0,0 @@
-<?php
- /**
- * @defgroup elements_user Elements
- * @ingroup user
- */
-
- /** @defgroup user User
- * User module handles all functions and operations related to users
- * @{*/
-
- class Service_user extends Service {
-
- function getUidByLogin($username, $password, $seed = null ) {
-
- $sql = "SELECT id, login_active FROM user_users ";
- $sql .= "WHERE login_username = '".addslashes($username)."'";
-
- if($seed == null) {
- switch($this->moduleConfig['password_type']) {
- case 'plain':
- $sql .= " AND login_password = '".addslashes($password)."'";
- break;
- case 'md5':
- default:
- $sql .= " AND login_password = '".md5($password)."'";
- break;
- }
- } else {
- $sql .= " AND MD5(CONCAT('".addslashes($seed)."',login_password)) = '".addslashes($password)."'";
- }
-
- $sql .= " AND deleted = 0 ";
-
- $db = new Database();
- $db->setSql($sql);
- $db->query();
-
- $num = $db->getNumRows();
-
- if($num == 0) {
- $this->errors[] = 'error_login_notfound';
- return 0;
- }
- if($num > 1) {
- $this->errors[] = 'error_login_multiplefound';
- return 0;
- }
-
- $row = $db->fetchArray();
-
- if(!$row['login_active']) {
-
- $this->errors[] = 'error_login_inactive';
- return 0;
- } else {
- return $row['id'];
- }
- }
-
- // verifyObject
- function verifyUser($obj) {
-
- if(!isset($obj['type']) || $obj['type'] == null) {
- $this->errors = array('error_unknown_usertype');
- return false;
- }
-
- switch($obj['type']) {
- case 'person':
- return $this->verifyPerson($obj);
- case 'company':
- return $this->verifyCompany($obj);
- case 'group':
- return $this->verifyGroup($obj);
- default:
- $this->errors = array('error_illegal_usertype');
- return false;
- }
- }
-
- function verifyPerson($obj) {
-
- $errors = array();
-
- //Check name
- $name = false;
- if(isset($obj['name_first']) && $obj['name_first'] != '')
- $name = true;
- else if(isset($obj['name_last']) && $obj['name_last'] != '')
- $name = true;
-
- if(!$name)
- $errors[] = 'error_missing_name';
-
- //Check duplicate reference
- if(isset($obj['misc_reference']) && $obj['misc_reference'] != null) {
- $criteria = array();
- $criteria['matches']['!id'] = intval($obj['id']);
- $criteria['matches']['misc_reference'] = $obj['misc_reference'];
- if($this->getNumUsers($criteria))
- $errors[] = 'error_duplicate_reference';
- }
-
- //Check duplicate loginnames
- if(isset($obj['login_username']) && $obj['login_username'] != null) {
- $criteria = array();
- $criteria['matches']['!id'] = intval($obj['id']);
- $criteria['matches']['login_username'] = $obj['login_username'];
- if($this->getNumUsers($criteria))
- $errors[] = 'error_duplicate_username';
- }
-
- //Check if username and password are set for active accounts
- if(isset($obj['login_active']) && $obj['login_active']) {
- if(
- isset($obj['login_username']) &&
- $obj['login_username'] != '' &&
- isset($obj['login_password']) &&
- $obj['login_password']
- ) {} else {
- $errors[] = 'error_missing_accountinfo';
- }
- }
-
- if(isset($obj['in_password1']) || isset($obj['in_password2'])) {
- if($obj['in_password1'] != $obj['in_password2'])
- $errors[] = 'error_password_mismatch';
- }
-
- if(count($errors)) {
- $this->errors = $errors;
- return false;
- }
-
- return true;
- }
-
- function verifyCompany($obj) {
- if(!isset($obj['name_first']) || $obj['name_first'] == '') {
- $errors[] = 'error_missing_name';
- }
-
- //Check duplicate reference
- if(isset($obj['misc_reference']) && $obj['misc_reference'] != null) {
- $criteria = array();
- $criteria['matches']['!id'] = intval($obj['id']);
- $criteria['matches']['misc_reference'] = $obj['misc_reference'];
- if($this->getNumUsers($criteria))
- $errors[] = 'error_duplicate_reference';
- }
-
- if(count($errors)) {
- $this->errors = $errors;
- return false;
- }
-
- return true;
- }
-
- function verifyGroup($obj) {
- if(!isset($obj['name_first']) || $obj['name_first'] == '') {
- $errors[] = 'error_missing_name';
- }
-
- //Check duplicate reference
- if(isset($obj['misc_reference']) && $obj['misc_reference'] != null) {
- $criteria = array();
- $criteria['matches']['!id'] = intval($obj['id']);
- $criteria['matches']['misc_reference'] = $obj['misc_reference'];
- if($this->getNumUsers($criteria))
- $errors[] = 'error_duplicate_reference';
- }
-
- if(count($errors)) {
- $this->errors = $errors;
- return false;
- }
- return true;
- }
-
- // createObject
- function createPerson($obj) {
-
- $obj = $this->dynInPerson($obj);
-
- if(!$this->verifyPerson($obj))
- return 0;
-
- return $this->createObject('user_users',$obj);
- }
-
- function createCompany($obj) {
-
- $obj = $this->dynInCompany($obj);
-
- if(!$this->verifyCompany($obj))
- return 0;
-
- return $this->createObject('user_users',$obj);
- }
-
- function createGroup($obj) {
-
- $obj = $this->dynInGroup($obj);
-
- if(!$this->verifyGroup($obj))
- return 0;
-
- return $this->createObject('user_users',$obj);
- }
-
- // updateObject
-
- function updatePerson($obj) {
-
- if(!$this->verifyPerson($obj))
- return 0;
-
- $obj = $this->dynInPerson($obj);
-
- if(!$this->_onUpdatePerson($obj))
- return 0;
-
- return $this->updateObject('user_users',$obj);
- }
-
- function updateCompany($obj) {
-
- if(!$this->verifyCompany($obj))
- return 0;
-
- $obj = $this->dynInCompany($obj);
-
- if(!$this->_onUpdateCompany($obj))
- return 0;
-
- return $this->updateObject('user_users',$obj);
- }
-
- function updateGroup($obj) {
-
- if(!$this->verifyGroup($obj))
- return 0;
-
- $obj = $this->dynInGroup($obj);
-
- if(!$this->_onUpdateGroup($obj))
- return 0;
-
- return $this->updateObject('user_users',$obj);
- }
-
- // deleteObject
-
- function deletePerson($obj) {
-
- if(!$this->_onDeletePerson($obj))
- return 0;
-
- return $this->deleteObject('user_users', $obj);
- }
-
- function deleteCompany($obj) {
-
- if(!$this->_onDeleteCompany($obj))
- return 0;
-
- return $this->deleteObject('user_users', $obj);
- }
-
- function deleteGroup($obj) {
-
- if(!$this->_onDeletePerson($obj))
- return 0;
-
- return $this->deleteObject('user_users', $obj);
- }
-
- // getDefaultObject
- function getDefaultUser() {
- return $this->getDefaultObject('user_users');
- }
-
- // getObjectById
- function getUserById($id) {
-
- $obj = $this->getObjectById('user_users', $id);
-
- if($obj == null)
- return null;
-
- switch($obj['type']) {
- case 'person': return $this->dynOutPerson($obj); break;
- case 'company': return $this->dynOutCompany($obj); break;
- case 'group': return $this->dynOutGroup($obj); break;
- }
- }
-
- function getPersonById($id) {
-
- $obj = $this->getObjectById('user_users', $id);
-
- if($obj == null)
- return null;
-
- return $this->dynOutPerson($obj);
- }
-
- function getCompanyById($id) {
-
- $obj = $this->getObjectById('user_users', $id);
-
- if($obj == null)
- return null;
-
- return $this->dynOutCompany($obj);
- }
-
- function getGroupById($id) {
-
- $obj = $this->getObjectById('user_users', $id);
-
- if($obj == null)
- return null;
-
- return $this->dynOutGroup($obj);
- }
-
- // getObjects
- function getUsers($criteria = array()) {
-
- $objs = $this->getObjects('user_users', $criteria);
-
- foreach($objs as $i => $obj) {
- switch($obj['type']) {
- case 'person': $objs[$i] = $this->dynOutPerson($obj); break;
- case 'company': $objs[$i] = $this->dynOutCompany($obj); break;
- case 'group': $objs[$i] = $this->dynOutGroup($obj); break;
- }
- }
-
- return $objs;
- }
-
- function getPersons($criteria = array()) {
-
- $criteria['matches']['type'] = 'person';
-
- $objs = $this->getObjects('user_users', $criteria);
-
- foreach($objs as $i => $obj)
- $objs[$i] = $this->dynOutPerson($obj);
-
- return $objs;
- }
-
- function getCompanies($criteria = array()) {
-
- $criteria['matches']['type'] = 'company';
-
- $objs = $this->getObjects('user_users', $criteria);
-
- foreach($objs as $i => $obj)
- $objs[$i] = $this->dynOutCompany($obj);
-
- return $objs;
- }
-
- function getGroups($criteria = array()) {
-
- $criteria['matches']['type'] = 'group';
-
- $objs = $this->getObjects('user_users', $criteria);
-
- foreach($objs as $i => $obj)
- $objs[$i] = $this->dynOutGroup($obj);
-
- return $objs;
- }
-
- // getNumObjects
-
- function getNumUsers($criteria = array()) {
-
- return $this->getNumObjects('user_users',$criteria);
- }
-
- function getNumPersons($criteria = array()) {
-
- $criteria['matches']['type'] = 'person';
-
- return $this->getNumObjects('user_users',$criteria);
- }
-
- function getNumCompanies($criteria = array()) {
-
- $criteria['matches']['type'] = 'company';
-
- return $this->getNumObjects('user_users',$criteria);
- }
-
- function getNumGroups($criteria = array()) {
-
- $criteria['matches']['type'] = 'group';
-
- return $this->getNumObjects('user_users',$criteria);
- }
-
- // Special getObjects
-
- function getUsersByUsername($username) {
- $criteria['only_readable'] = false;
- $criteria['matches']['login_username'] = $username;
-
- return $this->getUsers($criteria);
- }
-
- function getUsersByReference($reference) {
- $criteria['matches']['misc_reference'] = $reference;
-
- return $this->getUsers($criteria);
- }
-
- function getUsersByGroupId($groupId, $criteria = array(), $inverse = false) {
-
- if($inverse) {
- //Getting the inverse list of users requires 2 queries.
- //It would be nice if it could be done with a join in one query.
- $ids = array();
- $users = $this->getUsersByGroupId($groupId,array('fields' => array('id')));
- foreach($users as $user)
- $ids[] = $user['id'];
-
- $criteria['matches']['!id'] = $ids;
- return $this->getUsers($criteria);
- }
-
- $sql = "SELECT u.* FROM user_memberships AS m LEFT JOIN user_users AS u ON (m.user = u.id)";
- $sql .= " WHERE m.group = ".intval($groupId)." AND m.deleted = 0";
-
- if($where = $this->makeCriteriaWhere($criteria,'u')) {
- $sql .= " AND ".$where;
- }
-
- $sql .= $this->makeCriteriaResultSpec($criteria);
-
- $db = new Database();
- $db->setSql($sql);
-
- $users = array();
- while($row = $db->fetchArray()) {
- switch($row['type']) {
- case 'person': $users[] = $this->dynOutPerson($row); break;
- case 'company': $users[] = $this->dynOutCompany($row); break;
- }
- }
-
- return $users;
- }
-
- function getGroupsByUserId($userId, $criteria = array(), $inverse = false) {
-
- if($inverse) {
- //Getting the inverse list of groups requires 2 queries.
- //It would be nice if it could be done with a join in one query.
- $ids = array();
- $groups = $this->getGroupsByUserId($userId,array('fields' => array('id')));
- foreach($groups as $group)
- $ids[] = $group['id'];
-
- $criteria['matches']['!id'] = $ids;
- return $this->getGroups($criteria);
- }
-
- $sql = "SELECT u.* FROM user_memberships AS m LEFT JOIN user_users AS u ON ";
- $sql .= "(m.group = u.id) ";
- $sql .= "WHERE m.user = ".intval($userId)." AND m.deleted = 0";
-
- if($where = $this->makeCriteriaWhere($criteria,'u')) {
- $sql .= " AND ".$where;
- }
-
- $sql .= $this->makeCriteriaResultSpec($criteria);
-
- $db = new Database();
- $db->setSql($sql);
-
- $groups = array();
- while($row = $db->fetchArray()) {
- $groups[] = $this->dynOutGroup($row);
- }
-
- return $groups;
- }
-
- //Special getNumObjects
-
- function getNumUsersByGroupId($groupId, $criteria = array(),$inverse = false) {
-
- $sql = "SELECT COUNT(*) FROM user_memberships AS m LEFT JOIN user_users AS u ON (m.user = u.id)";
- $sql .= " WHERE m.group = ".intval($groupId)." AND m.deleted = 0";
-
- if($where = $this->makeCriteriaWhere($criteria,'u')) {
- $sql .= " AND ".$where;
- }
-
- $db = new Database();
- $db->setSql($sql);
-
- $row = $db->fetchRow();
-
- return $row[0];
- }
-
- function getNumGroupsByUserId($userId, $criteria = array(), $inverse = false) {
-
- if($inverse) {
- $ids = array();
- $groups = $this->getGroupsByUserId($userId,array('fields' => array('id')));
- foreach($groups as $group)
- $ids[] = $group['id'];
-
- $criteria['matches']['!id'] = $ids;
-
- return $this->getNumGroups($criteria);
- }
-
- $criteria['matches']['type'] = 'group';
-
- $sql = "SELECT COUNT(*) FROM user_memberships AS m LEFT JOIN user_users AS u ON (m.user = u.id)";
- $sql .= " WHERE m.user = ".intval($userId)." AND m.deleted = 0";
-
- if($where = $this->makeCriteriaWhere($criteria,'u')) {
- $sql .= " AND ".$where;
- }
-
- $db = new Database();
- $db->setSql($sql);
-
- $row = $db->fetchRow();
-
- return $row[0];
- }
-
- // Dynamic input
-
- function dynInPerson($obj) {
-
- //Split in_name
- if(isset($obj['in_name'])) {
- if($obj['type'] == 'person') {
- $name = array();
- $parts = explode(' ',$obj['in_name']);
-
- foreach($parts as $part) {
- $part = trim($part);
- if($part != '')
- $name[] = $part;
- }
- if(count($name)) {
- $obj['name_first'] = array_shift($name);
- if(count($name)) {
- $obj['name_last'] = array_pop($name);
- }
- if(count($name)) {
- $obj['name_prefix'] = implode(' ',$name);
- }
- }
- } else {
- $obj['name_first'] = $obj['in_name'];
- }
- }
-
- //Password
- if(isset($obj['in_password1']) && isset($obj['in_password2'])) {
- if($this->moduleConfig['password_type'] == 'md5')
- $obj['login_password'] = md5($obj['in_password1']);
- else
- $obj['login_password'] = $obj['in_password1'];
- }
- return $obj;
- }
-
- function dynInCompany($obj) {
- return $obj;
- }
-
- function dynInGroup($obj) {
- return $obj;
- }
-
-
- function dynOutPerson($obj) {
- $obj['out_name'] = $this->_makeUserName($obj);
- $obj['out_address'] = $this->_makeUserAddress($obj);
- $obj['out_email'] = $this->_makeUserEmail($obj);
- $obj['out_phone'] = $this->_makeUserPhone($obj);
- return $obj;
- }
-
- function dynOutCompany($obj) {
- $obj['out_name'] = $this->_makeUserName($obj);
- $obj['out_address'] = $this->_makeUserAddress($obj);
- $obj['out_mail_address'] = $this->_makeUserMailAddress($obj);
- $obj['out_email'] = $this->_makeUserEmail($obj);
- $obj['out_phone'] = $this->_makeUserPhone($obj);
- return $obj;
- }
-
- function dynOutGroup($obj) {
- $obj['out_name'] = $this->_makeUserName($obj);
- return $obj;
- }
-
- // Signup / activation methods
-
- function signupUser($obj) {
-
- //Check Email, Username & Password
- $errors = array();
- if($obj['email1_address'] == '')
- $errors[] = 'error_missing_email';
- if($obj['login_username'] == '')
- $errors[] = 'error_missing_username';
- if($obj['login_password'] == '')
- $errors[] = 'error_missing_password';
-
- if(count($errors)) {
- $this->errors = $errors;
- return 0;
- }
-
- //Create user
- if(! $id = $this->createPerson($obj))
- return 0;
-
- //Send activation email
- $code = $this->getActivationCodeByUserId($id);
-
- $from = $this->moduleConfig['email_signup_from'];
- $subject = $this->moduleConfig['email_signup_subject'];
-
- $body = implode('',file($this->moduleConfig['email_signup_body']));
- $body = str_replace('{NAME}',$obj['in_name'],$body);
- $body = str_replace('{USERNAME}',$obj['login_username'],$body);
- $body = str_replace('{PASSWORD}',$obj['login_password'],$body);
- $body = str_replace('{CODE}',$code,$body);
-
- $activationlink = $this->e->request['baseUrl'];
- $activationlink .= $this->e->hrefPage($this->moduleConfig['pages_signup_activate']);
- $activationlink .= '&username='.urlencode($obj['login_username']).'&activationcode='.urlencode($code);
-
- $body = str_replace('{ACTIVATIONLINK}',$activationlink,$body);
-
- $m = new Email();
-
- $m->setFrom($from);
- $m->setSubject($subject);
- $m->setMsg($body);
-
- $m->addTo($obj['email1_address']);
-
- $m->send();
-
- return $id;
- }
-
- function getActivationCodeByUserId($id) {
-
- $code = substr(md5(rand(time(), time() -1000)),12,10);
-
- $obj = array();
- $obj['id'] = $id;
- $obj['login_activationcode'] = $code;
-
- $this->updateUser($obj);
-
- return $code;
- }
-
- function activateUserAccount($username, $activationcode) {
-
- $criteria['matches']['login_username'] = $username;
- $criteria['matches']['login_activationcode'] = $activationcode;
-
- $users = $this->getUsers($criteria);
-
- if(count($users) == 1) {
-
-
- $user = $users[0];
- $userId = $user['id'];
-
- $user['login_active'] = 1;
- $user['login_activationcode'] = null;
-
- if(!$this->updateUser($user)) {
- $this->errors = array('error_activation_failed');
- return 0;
- }
-
- //Automatic addition to groups
- if(is_array($this->moduleConfig['user_activation_initial_groups'])) {
- foreach($this->moduleConfig['user_activation_initial_groups'] as $groupId) {
- $this->addGroupMember($groupId,$userId);
- }
- }
-
- //Automatic login after activation
- if($this->moduleConfig['user_activation_autologin']) {
- $this->e->user->loginByUserId($userId);
- }
-
- } else {
- $this->errors = array('error_activation_failed');
- return 0;
- }
- }
-
-
- // Clearance method
-
- function getClearancesByUserId($id) {
-
- $clearances = array();
- $clearances[] = 0;
- $clearances[] = $id;
-
- $criteria['matches']['user'] = $id;
- $criteria['matches']['group_type'] = 'group';
-
- $objs = $this->getObjects('user_memberships',$criteria);
-
- foreach($objs as $obj)
- $clearances[] = $obj['group'];
-
- return $clearances;
- }
-
- // Group management methods
-
- function addGroupMember($groupId, $userId) {
- if($this->isGroupMember($groupId, $userId))
- return 0;
-
- //Get types
- $criteria['matches']['id'] = array($groupId, $userId);
- $criteria['index'] = 'id';
- $criteria['fields'] = array('type');
- $objs = $this->getUsers($criteria);
-
- if(count($objs) != 2)
- return 0;
-
- //Create membership
- $membership = array();
- $membership['user'] = $userId;
- $membership['user_type'] = $objs[$userId]['type'];
- $membership['group'] = $groupId;
- $membership['group_type'] = $objs[$groupId]['type'];
-
- if($this->createObject('user_memberships', $membership))
- return $userId;
- else
- return 0;
- }
-
- function removeGroupMember($groupId, $userId) {
-
- //Find membership
- $criteria['matches']['group'] = $groupId;
- $criteria['matches']['user'] = $userId;
-
- $objs = $this->getObjects('user_memberships',$criteria);
-
- //Remove membership
- if(count($objs)) {
- if($this->deleteObject('user_memberships',$objs[0]))
- return $groupId;
- else
- return 0;
- } else {
- return 0;
- }
- }
-
- function isGroupMember($groupId, $userId) {
-
- $criteria['matches']['group'] = $groupId;
- $criteria['matches']['user'] = $userId;
-
- $num = $this->getNumObjects('user_memberships',$criteria);
-
- if($num > 0)
- return true;
- else
- return false;
- }
-
- // Dynamic output
-
- /**@name Private User module function
- *@{**/
- function _makeUserName($obj) {
- $name = array();
- if(isset($obj['name_first']) && $obj['name_first'] != '') $name[] = $obj['name_first'];
- if(isset($obj['name_prefix']) && $obj['name_prefix'] != '') $name[] = $obj['name_prefix'];
- if(isset($obj['name_last']) && $obj['name_last'] != '') $name[] = $obj['name_last'];
-
- return implode(' ',$name);
- }
-
- function _makeUserAddress($obj) {
- if(isset($obj['addr_address']) && isset($obj['addr_address']) && isset($obj['addr_city'])) {
- $addr = $obj['addr_address']."\n";
- $addr .= $obj['addr_pcode'].' '.$obj['addr_city']."\n";
-
- return $addr;
- } else {
- return '';
- }
- }
- function _makeUserMailAddress($obj) {
- if(isset($obj['addr_mail_address']) && isset($obj['addr_mail_address']) && isset($obj['addr_mail_city'])) {
- $addr = $obj['addr_mail_address']."\n";
- $addr .= $obj['addr_mail_pcode'].' '.$obj['addr_mail_city']."\n";
-
- return $addr;
- } else {
- return '';
- }
- }
-
- function _makeUserEmail($obj) {
- if(isset($obj['email_work']) && $obj['email_work'] != '')
- return $obj['email_work'];
- if(isset($obj['email_home']) && $obj['email_home'] != '')
- return $obj['email_home'];
-
- return null;
- }
-
- function _makeUserPhone($obj) {
- if(isset($obj['phone_work']) && $obj['phone_work'] != '')
- return $obj['phone_work'];
- if(isset($obj['phone_mobile']) && $obj['phone_mobile'] != '')
- return $obj['phone_mobile'];
- if(isset($obj['phone_home']) && $obj['phone_home'] != '')
- return $obj['phone_home'];
-
- return null;
- }
-
- // Event handlers
-
- function _onCreatePerson($obj) {
- return 1;
- }
- function _onCreateCompany($obj) {
- return 1;
- }
- function _onCreateGroup($obj) {
- return 1;
- }
-
- function _onUpdatePerson($obj) {
- return 1;
- }
- function _onUpdateCompany($obj) {
- return 1;
- }
- function _onUpdateGroup($obj) {
- return 1;
- }
-
- function _onDeletePerson($obj) {
-
- //Delete memberships
- if(!$this->deleteObjectsByField('user_memberships','user',intval($obj['id'])))
- return 0;
-
- return 1;
- }
- function _onDeleteCompany($obj) {
- //Delete memberships
- if(!$this->deleteObjectsByField('user_memberships','user',intval($obj['id'])))
- return 0;
-
- return 1;
- }
- function _onDeleteGroup($obj) {
- //Delete memberships
- if(!$this->deleteObjectsByField('user_memberships','group',intval($obj['id'])))
- return 0;
-
- return 1;
- }
- /**@}*/
- }
- /** @} */
-?>
Deleted: trunk/mod/eis_user/elements/ActivateUser.php
===================================================================
--- trunk/mod/eis_user/elements/ActivateUser.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_user/elements/ActivateUser.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,45 +0,0 @@
-<?php
- /**
- *@ingroup elements_user
- *@{
- */
- /** Element to activate a user account with an activation code*/
- class user_ActivateUser extends Element {
-
- function view_default() {
-
- $sWidget =& $this->e->getService('widget');
-
- $t = new Template();
- $t->assign('MAIN','main.tpl');
-
- $defaults = array('username'=>'','activationcode'=>'');
- $fields = $this->getFields($defaults);
-
- //Fill form
- $t->addkey('_ACTION',$this->e->hrefAction('activate'));
-
- $t->addkey('_USERNAME',$sWidget->inputString('username',$fields['username']));
- $t->addkey('_ACTIVATIONCODE',$sWidget->inputString('activationcode',$fields['activationcode']));
-
- $t->addkey('_ACTIVATE',$sWidget->buttonSubmit('Activate'));
-
- $t->parse('OUT','MAIN');
- $t->show('OUT');
- }
-
- function action_activate($data) {
-
- $sUser =& $this->e->getService('user');
-
- if($sUser->activateUserAccount($data['username'],$data['activationcode'])) {
- if($this->elementConfig['page_next'] != null)
- $this->e->redirect($this->e->hrefPage($this->elementConfig['page_next']));
- } else {
- $this->setFields($data);
- $this->setError($sUser->getErrors());
- }
- }
- }
- /**@}*/
-?>
Deleted: trunk/mod/eis_user/elements/AddToGroup.php
===================================================================
--- trunk/mod/eis_user/elements/AddToGroup.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_user/elements/AddToGroup.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,111 +0,0 @@
-<?php
- /**
- *@ingroup elements_user
- *@{
- */
- /** Element to add a user to a group*/
- class user_AddToGroup extends Element {
-
- function view_default() {
-
- $type = $this->elementConfig['type'];
-
- $sUser =& $this->e->getService('user');
- $sWidget =& $this->e->getService('widget');
-
-
- $user_var = $this->elementConfig['user_var'];
- $user_id =& $this->e->session->getReference($user_var,'site');
- $group_var = $this->elementConfig['group_var'];
- $group_id =& $this->e->session->getReference($group_var,'site');
-
- $options = array();
-
- $criteria = array();
- $criteria['only_writable'] = true;
- $criteria['matches']['type'] = $type;
-
- //Load users/groups
- switch($type) {
- case 'person':
- $label = 'Persoon';
- $users = $sUser->getUsersByGroupId(intval($group_id), $criteria, true);
- $options[] = array('value' => 0, 'label' => 'Kies een persoon...');
- break;
- case 'company':
- $label = 'Bedrijf';
- $users = $sUser->getUsersByGroupId(intval($group_id), $criteria, true);
- $options[] = array('value' => 0, 'label' => 'Kies een bedrijf...');
- break;
- case 'group':
- $label = 'Groep';
- $users = $sUser->getGroupsByUserId(intval($user_id), $criteria, true);
- $options[] = array('value' => 0, 'label' => 'Kies een groep...');
- break;
- }
-
- //Prepare options
- foreach($users as $user) {
- $options[] = array('value' => $user['id'], 'label' => $user['out_name']);
- }
-
- $rows = array();
- $rows[0][0] = $label;
- $rows[0][1] = $sWidget->inputInteger('id', 0, $options);
-
- //Create form
- $action = $this->e->hrefAction('ok');
-
- $inputs = $sWidget->fieldset($sWidget->formTable($rows),'Toevoegen');
- $inputs .= $sWidget->buttonSetOkCancel(
- $this->e->hrefAction($action),
- $this->e->hrefAction('cancel'));
- $inputs = $sWidget->form($inputs, $this->e->hrefAction($action));
-
- print $inputs;
- }
-
- function action_ok($data) {
-
- $id = intval($data['id']);
-
- $sUser =& $this->e->getService('user');
-
- $user_var =& $this->e->session->getReference($this->elementConfig['user_var'],'site');
- $group_var =& $this->e->session->getReference($this->elementConfig['group_var'],'site');
-
- switch($this->elementConfig['type']) {
- case 'person':
- case 'company':
- $ret =$sUser->addGroupMember(intval($group_var),$id);
- break;
- case 'group':
- $ret =$sUser->addGroupMember($id,intval($user_var));
- break;
- }
-
- if($ret) {
- //Store added id
- if($this->elementConfig['type'] == 'group')
- $group_var = $id;
- else
- $user_var = $id;
-
- $this->e->session->save();
-
- if($this->elementConfig['page_ok'] != null)
- $this->e->redirect($this->e->hrefPage($this->elementConfig['page_ok']));
- else
- $this->e->redirect($this->e->hrefPreviousPage());
- }
- }
-
- function action_cancel($data) {
- if($this->elementConfig['page_cancel'] != null)
- $this->e->redirect($this->e->hrefPage($this->elementConfig['page_cancel']));
- else
- $this->e->redirect($this->e->hrefPreviousPage());
- }
- }
- /**@}*/
-?>
Deleted: trunk/mod/eis_user/elements/DeleteUser.php
===================================================================
--- trunk/mod/eis_user/elements/DeleteUser.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_user/elements/DeleteUser.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,69 +0,0 @@
-<?php
- /**
- *@ingroup elements_user
- *@{
- */
- /** Element to delete a user */
- class user_DeleteUser extends Element {
-
- function view_default() {
-
- $sUser =& $this->e->getService('user');
- $sWidget =& $this->e->getService('widget');
-
- $id =& $this->e->session->getReference($this->elementConfig['var'],'site');
- $id = intval($id);
-
- $user = $sUser->getUserById($id);
-
- $question = 'Weet u zeker dat u "'.$user['out_name'].'" wilt verwijderen?';
-
- print $sWidget->fieldset($question,'Verwijderen');
- print $sWidget->buttonSetYesNo(
- $this->e->hrefAction('ok'),
- $this->e->hrefAction('cancel'),false);
- }
-
- function action_ok($data) {
-
- $sUser =& $this->e->getService('user');
-
- $id =& $this->e->session->getReference($this->elementConfig['var'],'site');
-
- $obj = $sUser->getUserById(intval($id));
-
- switch($obj['type']) {
- case 'person':
- $ret = $sUser->deletePerson($obj);
- break;
- case 'company':
- $ret = $sUser->deleteCompany($obj);
- break;
- case 'group':
- $ret = $sUser->deleteGroup($obj);
- break;
- }
-
- if($ret) {
- //Clear var
- $id = null;
- $this->e->session->save();
-
- if($this->elementConfig['page_ok'] != null)
- $this->e->redirect($this->e->hrefPage($this->elementConfig['page_ok']));
- else
- $this->e->redirect($this->e->hrefPreviousPage());
- } else {
- //TODO: ERROR
- }
- }
- function action_cancel($data) {
-
- if($this->elementConfig['page_cancel'] != null)
- $this->e->redirect($this->e->hrefPage($this->elemenConfig['page_cancel']));
- else
- $this->e->redirect($this->e->hrefPreviousPage());
- }
- }
- /**@}*/
-?>
Deleted: trunk/mod/eis_user/elements/DisplayUser.php
===================================================================
--- trunk/mod/eis_user/elements/DisplayUser.php 2007-09-11 12:18:06 UTC (rev 205)
+++ trunk/mod/eis_user/elements/DisplayUser.php 2007-09-11 16:56:12 UTC (rev 206)
@@ -1,192 +0,0 @@
-<?php
- /**
- *@ingroup elements_user
- *@{
- */
- /** Element to display a user*/
- class user_DisplayUser extends Element {
-
- function view_default() {
-
- $sUser = $this->e->getService('user');
- $sImage = $this->e->getService('image');
- $sWidget = $this->e->getService('widget');
-
- $id =& $this->e->session->getReference($this->elementConfig['var'],'site');
- $id = intval($id);
-
- $meid =& $this->e->session->getReference('me','module','user');
- $me = $sUser->getUserById($meid);
-
- $user = $sUser->getUserById($id);
-
- //Summary
- if($this->elementConfig['display_all'] || $this->elementConfig['display_person_summary']) {
- $rows = array();
- $rows[] = array('Naam',$sWidget->displayString($user['out_name']));
- $rows[] = array('Adres',$sWidget->displayString($user['out_address']));
- $rows[] = array('Telefoon',$sWidget->displayString($user['out_phone']));
- $rows[] = array('E-mail',$sWidget->displayString($user['out_email']));
- $rows[] = array('Gebruikersnaam',
- $sWidget->displayString($user['login_username']).
- ($user['login_active'] ? '' : ' (inactief)'));
-
- print $sWidget->fieldset($sWidget->formTable($rows),'Samenvatting');
- }
- //Personal info
- if($this->elementConfig['display_all'] || $this->elementConfig['display_person']) {
-
- $rows = array();
- //Name
- $rows[] = array('Titel',$sWidget->displayString($user['name_title']));
- $rows[] = array('Voornaam',$sWidget->displayString($user['name_first']));
- $rows[] = array('Initialen',$sWidget->displayString($user['name_initials']));
- $rows[] = array('Tussenvoegsel',$sWidget->displayString($user['name_prefix']));
- $rows[] = array('Achternaam',$sWidget->displayString($user['name_last']));
- $rows[] = array('Toevoeging',$sWidget->displayString($user['name_addition']));
-
- //Gender
- if($user['misc_gender'] == 'm')
- $rows[] = array('Geslacht',$sWidget->icon('male'));
- if($user['misc_gender'] == 'f')
- $rows[] = array('Geslacht',$sWidget->icon('female'));
-
- //Birthday
- $rows[] = array('Geboortedatum',$sWidget->displayDate($user['misc_birthday']));
-
- //Occupation
- $rows[] = array('Beroep',$sWidget->displayString($user['misc_occupation']));
-
- print $sWidget->fieldset($sWidget->formTable($rows),'Persoonsgegevens');
- }
- //Company information
- if($this->elementConfig['display_all'] || $this->elementConfig['display_company_summary']) {
- $rows = array();
- $rows[] = array('Naam',$sWidget->displayString($user['out_name']));
- $rows[] = array('Adres',$sWidget->displayString($user['out_address']));
- $rows[] = array('Telefoon',$user['phone_work']);
- $rows[] = array('E-mail',$user['email_work']);
- print $sWidget->fieldset($sWidget->formTable($rows),'Bedrijf');
- }
-
- //Company information
- if($this->elementConfig['display_all'] || $this->elementConfig['display_company']) {
- $rows = array();
- $rows[] = array('Naam',$sWidget->displayString($user['out_name']));
- $rows[] = array('Adres',$sWidget->displayString($user['out_address']));
- $rows[] = array('Telefoon',$user['phone_work']);
- $rows[] = array('Fax',$user['fax_work']);
- $rows[] = array('E-mail',$user['email_work']);
- $rows[] = array('Website',$user['website_work']);
- if($user['addr_mail_address']) {
- $rows[] = array('Post Adres',$sWidget->displayString($user['out_mail_address']));
- }
- print $sWidget->fieldset($sWidget->formTable($rows),'Bedrijf');
- }
-
- //Group information
- if($this->elementConfig['display_all'] || $this->elementConfig['display_group']) {
- $numMembers = $sUser->getNumUsersByGroupId($user['id']);
-
- $rows = array();
- $rows[] = array('Naam',$sWidget->displayString($user['out_name']));
- $rows[] = array('Aantal leden',$sWidget->displayInteger($numMembers));
-
- print $sWidget->fieldset($sWidget->formTable($rows),'Groep');
- }
- //Image
- if($this->elementConfig['display_all'] || $this->elementConfig['display_image']) ...
[truncated message content] |