[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once 'Horde/DataTree.php'; 4 require_once 'Horde/Form.php'; 5 require_once 'Horde/Form/Renderer.php'; 6 7 /** 8 * Auth_Signup:: This class provides an interface to sign up or have 9 * new users sign themselves up into the horde installation, depending 10 * on how the admin has configured Horde. 11 * 12 * $Horde: framework/Auth/Auth/Signup.php,v 1.38.2.11 2006/08/14 02:48:48 chuck Exp $ 13 * 14 * Copyright 2002-2006 Marko Djukic <marko@oblo.com> 15 * 16 * See the enclosed file COPYING for license information (LGPL). If you 17 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 18 * 19 * @author Marko Djukic <marko@oblo.com> 20 * @since Horde 3.0 21 * @package Horde_Auth 22 */ 23 class Auth_Signup { 24 25 /** 26 * Pointer to a DataTree instance to manage/store signups 27 * 28 * @var DataTree 29 */ 30 var $_datatree; 31 32 function Auth_Signup() 33 { 34 global $conf; 35 36 if (empty($conf['datatree']['driver'])) { 37 Horde::fatal(_("You must configure a DataTree backend to use Signups."), __FILE__, __LINE__); 38 } 39 $driver = $conf['datatree']['driver']; 40 $this->_datatree = &DataTree::singleton($driver, 41 array_merge(Horde::getDriverConfig('datatree', $driver), 42 array('group' => 'horde.signup'))); 43 } 44 45 /** 46 * Attempts to return a reference to a concrete Auth_Signup 47 * instance. It will only create a new instance if no Auth_Signup 48 * instance currently exists. 49 * 50 * This method must be invoked as: $var = &Auth_Signup::singleton() 51 * 52 * @return Auth_Signup The concrete Auth_Signup reference, or false on error. 53 */ 54 function &singleton() 55 { 56 static $signup; 57 58 if (!isset($signup)) { 59 $signup = new Auth_Signup(); 60 } 61 62 return $signup; 63 } 64 65 /** 66 * Adds a new user to the system and handles any extra fields that may have 67 * been compiled, relying on the hooks.php file. 68 * 69 * @params mixed $info Reference to array of parameteres to be passed 70 * to hook 71 * 72 * @return mixed PEAR_Error if any errors, otherwise true. 73 */ 74 function addSignup(&$info) 75 { 76 global $auth, $conf; 77 78 // Perform any preprocessing if requested. 79 if ($conf['signup']['preprocess']) { 80 $info = Horde::callHook('_horde_hook_signup_preprocess', array($info)); 81 if (is_a($info, 'PEAR_Error')) { 82 return $info; 83 } 84 } 85 86 // Attempt to add the user to the system. 87 $success = $auth->addUser($info['user_name'], array('password' => $info['password'])); 88 if (is_a($success, 'PEAR_Error')) { 89 return $success; 90 } 91 92 // Attempt to add/update any extra data handed in. 93 if (!empty($info['extra'])) { 94 $added = false; 95 $added = Horde::callHook('_horde_hook_signup_addextra', 96 array($info['user_name'], $info['extra'])); 97 if (!$added || is_a($added, 'PEAR_Error')) { 98 Horde::logMessage($added, __FILE__, __LINE__, PEAR_LOG_EMERG); 99 Horde::fatal(_("Unable to add extra user information when signing up."), __FILE__, __LINE__); 100 } 101 } 102 103 return true; 104 } 105 106 /** 107 * Queues the user's submitted registration info for later admin approval. 108 * 109 * @params mixed $info Reference to array of parameteres to be passed 110 * to hook 111 * 112 * @return mixed PEAR_Error if any errors, otherwise true. 113 */ 114 function &queueSignup(&$info) 115 { 116 global $auth,$conf; 117 118 // Perform any preprocessing if requested. 119 if ($conf['signup']['preprocess']) { 120 $info = Horde::callHook('_horde_hook_signup_preprocess', 121 array($info)); 122 if (is_a($info, 'PEAR_Error')) { 123 return $info; 124 } 125 } 126 127 // Check to see if the username already exists. 128 if ($auth->exists($info['user_name']) || 129 $this->_datatree->exists($info['user_name'])) { 130 return PEAR::raiseError(sprintf(_("Username \"%s\" already exists."), $info['user_name'])); 131 } 132 133 // If it's a unique username, go ahead and queue the request. 134 $signup = $this->newSignup($info['user_name']); 135 if (!empty($info['extra'])) { 136 $signup->data = array_merge($info['extra'], 137 array('password' => $info['password'], 138 'dateReceived' => time())); 139 } else { 140 $signup->data = array('password' => $info['password'], 141 'dateReceived' => time()); 142 } 143 144 if ($conf['signup']['queue']) { 145 $result = Horde::callHook('_horde_hook_signup_queued', 146 array($info['user_name'], $info)); 147 if (is_a($result, 'PEAR_Error')) { 148 return $result; 149 } 150 } 151 152 return $this->_datatree->add($signup); 153 } 154 155 /** 156 * Get a user's queued signup information. 157 * 158 * @param string $username The username to retrieve the queued info for. 159 * 160 * @return DataTreeObject_Signup The DataTreeObject for the requested 161 * signup. 162 */ 163 function getQueuedSignup($username) 164 { 165 return $this->_datatree->getObject($username, 'DataTreeObject_Signup'); 166 } 167 168 /** 169 * Get the queued information for all pending signups. 170 * 171 * @return array An array of DataTreeObject_Signup objects, one for 172 * each signup in the queue. 173 */ 174 function getQueuedSignups() 175 { 176 $signups = array(); 177 foreach ($this->_datatree->get(DATATREE_FORMAT_FLAT, DATATREE_ROOT, true) as $username) { 178 if ($username != DATATREE_ROOT) { 179 $signups[] = $this->_datatree->getObject($username); 180 } 181 } 182 return $signups; 183 } 184 185 /** 186 * Remove a queued signup. 187 * 188 * @param string $username The user to remove from the signup queue. 189 */ 190 function removeQueuedSignup($username) 191 { 192 $this->_datatree->remove($username); 193 } 194 195 /** 196 * Return a new signup object. 197 * 198 * @param string $name The signups's name. 199 * 200 * @return DataTreeObject_Signup A new signup object. 201 */ 202 function &newSignup($name) 203 { 204 if (empty($name)) { 205 return PEAR::raiseError('Signup names must be non-empty'); 206 } 207 $signup = &new DataTreeObject_Signup($name); 208 return $signup; 209 } 210 211 } 212 213 /** 214 * Extension of the DataTreeObject class for storing Signup 215 * information in the DataTree driver. If you want to store 216 * specialized Signup information, you should extend this class 217 * instead of extending DataTreeObject directly. 218 * 219 * @author Marko Djukic <marko@oblo.com> 220 * @since Horde 3.0 221 * @package Horde_Auth 222 */ 223 class DataTreeObject_Signup extends DataTreeObject { 224 225 /** 226 * We want to see queued signups in descending order of receipt. 227 * Insert new signups at position 0 and push the rest down. 228 * 229 * @var integer 230 */ 231 var $order = 0; 232 233 /** 234 * The DataTreeObject_Signup constructor. Just makes sure to call 235 * the parent constructor so that the signup's is is set 236 * properly. 237 * 238 * @param string $id The id of the signup. 239 */ 240 function DataTreeObject_Signup($id) 241 { 242 parent::DataTreeObject($id); 243 if (is_null($this->data)) { 244 $this->data = array(); 245 } 246 } 247 248 } 249 250 /** 251 * Horde Signup Form, extending of Horde_Form:: 252 * 253 * Copyright 2003-2006 Marko Djukic <marko@oblo.com> 254 * 255 * See the enclosed file COPYING for license information (GPL). If you 256 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 257 * 258 * @author Marko Djukic <marko@oblo.com> 259 * @since Horde 3.0 260 * @package Horde_Auth 261 */ 262 class HordeSignupForm extends Horde_Form { 263 264 var $_useFormToken = true; 265 266 function HordeSignupForm(&$vars) 267 { 268 global $registry; 269 270 parent::Horde_Form($vars, sprintf(_("%s Sign Up"), $registry->get('name'))); 271 272 $this->setButtons(_("Sign up"), true); 273 274 $this->addHidden('', 'url', 'text', false); 275 $this->addVariable(_("Choose a username"), 'user_name', 'text', true); 276 $this->addVariable(_("Choose a password"), 'password', 'passwordconfirm', true, false, _("type the password twice to confirm")); 277 278 /* Use hooks get any extra fields required in signing up. */ 279 $extra = Horde::callHook('_horde_hook_signup_getextra'); 280 if (!is_a($extra, 'PEAR_Error') && !empty($extra)) { 281 foreach ($extra as $field_name => $field) { 282 $readonly = isset($field['readonly']) ? $field['readonly'] : null; 283 $desc = isset($field['desc']) ? $field['desc'] : null; 284 $required = isset($field['required']) ? $field['required'] : false; 285 $field_params = isset($field['params']) ? $field['params'] : array(); 286 287 $this->addVariable($field['label'], 'extra[' . $field_name . ']', 288 $field['type'], $required, $readonly, 289 $desc, $field_params); 290 } 291 } 292 } 293 294 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |