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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
<?php
require_once 'Horde/DataTree.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
/**
* Auth_Signup:: This class provides an interface to sign up or have
* new users sign themselves up into the horde installation, depending
* on how the admin has configured Horde.
*
* $Horde: framework/Auth/Auth/Signup.php,v 1.38.2.11 2006/08/14 02:48:48 chuck Exp $
*
* Copyright 2002-2006 Marko Djukic <marko@oblo.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Marko Djukic <marko@oblo.com>
* @since Horde 3.0
* @package Horde_Auth
*/
class Auth_Signup {
/**
* Pointer to a DataTree instance to manage/store signups
*
* @var DataTree
*/
var $_datatree;
function Auth_Signup()
{
global $conf;
if (empty($conf['datatree']['driver'])) {
Horde::fatal(_("You must configure a DataTree backend to use Signups."), __FILE__, __LINE__);
}
$driver = $conf['datatree']['driver'];
$this->_datatree = &DataTree::singleton($driver,
array_merge(Horde::getDriverConfig('datatree', $driver),
array('group' => 'horde.signup')));
}
/**
* Attempts to return a reference to a concrete Auth_Signup
* instance. It will only create a new instance if no Auth_Signup
* instance currently exists.
*
* This method must be invoked as: $var = &Auth_Signup::singleton()
*
* @return Auth_Signup The concrete Auth_Signup reference, or false on error.
*/
function &singleton()
{
static $signup;
if (!isset($signup)) {
$signup = new Auth_Signup();
}
return $signup;
}
/**
* Adds a new user to the system and handles any extra fields that may have
* been compiled, relying on the hooks.php file.
*
* @params mixed $info Reference to array of parameteres to be passed
* to hook
*
* @return mixed PEAR_Error if any errors, otherwise true.
*/
function addSignup(&$info)
{
global $auth, $conf;
// Perform any preprocessing if requested.
if ($conf['signup']['preprocess']) {
$info = Horde::callHook('_horde_hook_signup_preprocess', array($info));
if (is_a($info, 'PEAR_Error')) {
return $info;
}
}
// Attempt to add the user to the system.
$success = $auth->addUser($info['user_name'], array('password' => $info['password']));
if (is_a($success, 'PEAR_Error')) {
return $success;
}
// Attempt to add/update any extra data handed in.
if (!empty($info['extra'])) {
$added = false;
$added = Horde::callHook('_horde_hook_signup_addextra',
array($info['user_name'], $info['extra']));
if (!$added || is_a($added, 'PEAR_Error')) {
Horde::logMessage($added, __FILE__, __LINE__, PEAR_LOG_EMERG);
Horde::fatal(_("Unable to add extra user information when signing up."), __FILE__, __LINE__);
}
}
return true;
}
/**
* Queues the user's submitted registration info for later admin approval.
*
* @params mixed $info Reference to array of parameteres to be passed
* to hook
*
* @return mixed PEAR_Error if any errors, otherwise true.
*/
function &queueSignup(&$info)
{
global $auth,$conf;
// Perform any preprocessing if requested.
if ($conf['signup']['preprocess']) {
$info = Horde::callHook('_horde_hook_signup_preprocess',
array($info));
if (is_a($info, 'PEAR_Error')) {
return $info;
}
}
// Check to see if the username already exists.
if ($auth->exists($info['user_name']) ||
$this->_datatree->exists($info['user_name'])) {
return PEAR::raiseError(sprintf(_("Username \"%s\" already exists."), $info['user_name']));
}
// If it's a unique username, go ahead and queue the request.
$signup = $this->newSignup($info['user_name']);
if (!empty($info['extra'])) {
$signup->data = array_merge($info['extra'],
array('password' => $info['password'],
'dateReceived' => time()));
} else {
$signup->data = array('password' => $info['password'],
'dateReceived' => time());
}
if ($conf['signup']['queue']) {
$result = Horde::callHook('_horde_hook_signup_queued',
array($info['user_name'], $info));
if (is_a($result, 'PEAR_Error')) {
return $result;
}
}
return $this->_datatree->add($signup);
}
/**
* Get a user's queued signup information.
*
* @param string $username The username to retrieve the queued info for.
*
* @return DataTreeObject_Signup The DataTreeObject for the requested
* signup.
*/
function getQueuedSignup($username)
{
return $this->_datatree->getObject($username, 'DataTreeObject_Signup');
}
/**
* Get the queued information for all pending signups.
*
* @return array An array of DataTreeObject_Signup objects, one for
* each signup in the queue.
*/
function getQueuedSignups()
{
$signups = array();
foreach ($this->_datatree->get(DATATREE_FORMAT_FLAT, DATATREE_ROOT, true) as $username) {
if ($username != DATATREE_ROOT) {
$signups[] = $this->_datatree->getObject($username);
}
}
return $signups;
}
/**
* Remove a queued signup.
*
* @param string $username The user to remove from the signup queue.
*/
function removeQueuedSignup($username)
{
$this->_datatree->remove($username);
}
/**
* Return a new signup object.
*
* @param string $name The signups's name.
*
* @return DataTreeObject_Signup A new signup object.
*/
function &newSignup($name)
{
if (empty($name)) {
return PEAR::raiseError('Signup names must be non-empty');
}
$signup = &new DataTreeObject_Signup($name);
return $signup;
}
}
/**
* Extension of the DataTreeObject class for storing Signup
* information in the DataTree driver. If you want to store
* specialized Signup information, you should extend this class
* instead of extending DataTreeObject directly.
*
* @author Marko Djukic <marko@oblo.com>
* @since Horde 3.0
* @package Horde_Auth
*/
class DataTreeObject_Signup extends DataTreeObject {
/**
* We want to see queued signups in descending order of receipt.
* Insert new signups at position 0 and push the rest down.
*
* @var integer
*/
var $order = 0;
/**
* The DataTreeObject_Signup constructor. Just makes sure to call
* the parent constructor so that the signup's is is set
* properly.
*
* @param string $id The id of the signup.
*/
function DataTreeObject_Signup($id)
{
parent::DataTreeObject($id);
if (is_null($this->data)) {
$this->data = array();
}
}
}
/**
* Horde Signup Form, extending of Horde_Form::
*
* Copyright 2003-2006 Marko Djukic <marko@oblo.com>
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Marko Djukic <marko@oblo.com>
* @since Horde 3.0
* @package Horde_Auth
*/
class HordeSignupForm extends Horde_Form {
var $_useFormToken = true;
function HordeSignupForm(&$vars)
{
global $registry;
parent::Horde_Form($vars, sprintf(_("%s Sign Up"), $registry->get('name')));
$this->setButtons(_("Sign up"), true);
$this->addHidden('', 'url', 'text', false);
$this->addVariable(_("Choose a username"), 'user_name', 'text', true);
$this->addVariable(_("Choose a password"), 'password', 'passwordconfirm', true, false, _("type the password twice to confirm"));
/* Use hooks get any extra fields required in signing up. */
$extra = Horde::callHook('_horde_hook_signup_getextra');
if (!is_a($extra, 'PEAR_Error') && !empty($extra)) {
foreach ($extra as $field_name => $field) {
$readonly = isset($field['readonly']) ? $field['readonly'] : null;
$desc = isset($field['desc']) ? $field['desc'] : null;
$required = isset($field['required']) ? $field['required'] : false;
$field_params = isset($field['params']) ? $field['params'] : array();
$this->addVariable($field['label'], 'extra[' . $field_name . ']',
$field['type'], $required, $readonly,
$desc, $field_params);
}
}
}
}
|