8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_Extension
27 require_once 'Zend/Gdata/Extension.php';
30 * @see Zend_Gdata_Gapps
32 require_once 'Zend/Gdata/Gapps.php';
35 * Represents the apps:login element used by the Apps data API. This
36 * class is used to describe properties of a user, and is usually contained
37 * within instances of Zene_Gdata_Gapps_UserEntry or any other class
38 * which is linked to a particular username.
43 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
44 * @license http://framework.zend.com/license/new-bsd New BSD License
46 class Zend_Gdata_Gapps_Extension_Login extends Zend_Gdata_Extension
49 protected $_rootNamespace = 'apps';
50 protected $_rootElement = 'login';
53 * The username for this user. This is used as the user's email address
54 * and when logging in to Google Apps-hosted services.
58 protected $_username = null;
61 * The password for the user. May be in cleartext or as an SHA-1
62 * digest, depending on the value of _hashFunctionName.
66 protected $_password = null;
69 * Specifies whether the password stored in _password is in cleartext
70 * or is an SHA-1 digest of a password. If the password is cleartext,
71 * then this should be null. If the password is an SHA-1 digest, then
72 * this should be set to 'SHA-1'.
74 * At the time of writing, no other hash functions are supported
78 protected $_hashFunctionName = null;
81 * True if the user has administrative rights for this domain, false
86 protected $_admin = null;
89 * True if the user has agreed to the terms of service for Google Apps,
94 protected $_agreedToTerms = null;
97 * True if this user has been suspended, false otherwise.
101 protected $_suspended = null;
104 * True if the user will be required to change their password at
105 * their next login, false otherwise.
109 protected $_changePasswordAtNextLogin = null;
112 * Constructs a new Zend_Gdata_Gapps_Extension_Login object.
114 * @param string $username (optional) The username to be used for this
116 * @param string $password (optional) The password to be used for this
118 * @param string $hashFunctionName (optional) The name of the hash
119 * function used to protect the password, or null if no
120 * has function has been applied. As of this writing,
121 * the only valid values are 'SHA-1' or null.
122 * @param boolean $admin (optional) Whether the user is an administrator
124 * @param boolean $suspended (optional) Whether this login is suspended or not.
125 * @param boolean $changePasswordAtNextLogin (optional) Whether
126 * the user is required to change their password at their
128 * @param boolean $agreedToTerms (optional) Whether the user has
129 * agreed to the terms of service.
131 public function __construct($username = null, $password = null,
132 $hashFunctionName = null, $admin = null, $suspended = null,
133 $changePasswordAtNextLogin = null, $agreedToTerms = null)
135 $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
136 parent::__construct();
137 $this->_username = $username;
138 $this->_password = $password;
139 $this->_hashFunctionName = $hashFunctionName;
140 $this->_admin = $admin;
141 $this->_agreedToTerms = $agreedToTerms;
142 $this->_suspended = $suspended;
143 $this->_changePasswordAtNextLogin = $changePasswordAtNextLogin;
147 * Retrieves a DOMElement which corresponds to this element and all
148 * child properties. This is used to build an entry back into a DOM
149 * and eventually XML text for sending to the server upon updates, or
150 * for application storage/persistence.
152 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
153 * @return DOMElement The DOMElement representing this element and all
156 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
158 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
159 if ($this->_username !== null) {
160 $element->setAttribute('userName', $this->_username);
162 if ($this->_password !== null) {
163 $element->setAttribute('password', $this->_password);
165 if ($this->_hashFunctionName !== null) {
166 $element->setAttribute('hashFunctionName', $this->_hashFunctionName);
168 if ($this->_admin !== null) {
169 $element->setAttribute('admin', ($this->_admin ? "true" : "false"));
171 if ($this->_agreedToTerms !== null) {
172 $element->setAttribute('agreedToTerms', ($this->_agreedToTerms ? "true" : "false"));
174 if ($this->_suspended !== null) {
175 $element->setAttribute('suspended', ($this->_suspended ? "true" : "false"));
177 if ($this->_changePasswordAtNextLogin !== null) {
178 $element->setAttribute('changePasswordAtNextLogin', ($this->_changePasswordAtNextLogin ? "true" : "false"));
185 * Given a DOMNode representing an attribute, tries to map the data into
186 * instance members. If no mapping is defined, the name and value are
187 * stored in an array.
189 * @param DOMNode $attribute The DOMNode attribute needed to be handled
190 * @throws Zend_Gdata_App_InvalidArgumentException
192 protected function takeAttributeFromDOM($attribute)
194 switch ($attribute->localName) {
196 $this->_username = $attribute->nodeValue;
199 $this->_password = $attribute->nodeValue;
201 case 'hashFunctionName':
202 $this->_hashFunctionName = $attribute->nodeValue;
205 if ($attribute->nodeValue == "true") {
206 $this->_admin = true;
208 else if ($attribute->nodeValue == "false") {
209 $this->_admin = false;
212 require_once('Zend/Gdata/App/InvalidArgumentException.php');
213 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#admin.");
216 case 'agreedToTerms':
217 if ($attribute->nodeValue == "true") {
218 $this->_agreedToTerms = true;
220 else if ($attribute->nodeValue == "false") {
221 $this->_agreedToTerms = false;
224 require_once('Zend/Gdata/App/InvalidArgumentException.php');
225 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#agreedToTerms.");
229 if ($attribute->nodeValue == "true") {
230 $this->_suspended = true;
232 else if ($attribute->nodeValue == "false") {
233 $this->_suspended = false;
236 require_once('Zend/Gdata/App/InvalidArgumentException.php');
237 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#suspended.");
240 case 'changePasswordAtNextLogin':
241 if ($attribute->nodeValue == "true") {
242 $this->_changePasswordAtNextLogin = true;
244 else if ($attribute->nodeValue == "false") {
245 $this->_changePasswordAtNextLogin = false;
248 require_once('Zend/Gdata/App/InvalidArgumentException.php');
249 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#changePasswordAtNextLogin.");
253 parent::takeAttributeFromDOM($attribute);
258 * Get the value for this element's username attribute.
261 * @return string The attribute being modified.
263 public function getUsername()
265 return $this->_username;
269 * Set the value for this element's username attribute. This string
270 * is used to uniquely identify the user in this domian and is used
271 * to form this user's email address.
273 * @param string $value The desired value for this attribute.
274 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
276 public function setUsername($value)
278 $this->_username = $value;
283 * Get the value for this element's password attribute.
286 * @return string The requested attribute.
288 public function getPassword()
290 return $this->_password;
294 * Set the value for this element's password attribute. As of this
295 * writing, this can be either be provided as plaintext or hashed using
296 * the SHA-1 algorithm for protection. If using a hash function,
297 * this must be indicated by calling setHashFunctionName().
299 * @param string $value The desired value for this attribute.
300 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
302 public function setPassword($value)
304 $this->_password = $value;
309 * Get the value for this element's hashFunctionName attribute.
311 * @see setHashFunctionName
312 * @return string The requested attribute.
314 public function getHashFunctionName()
316 return $this->_hashFunctionName;
320 * Set the value for this element's hashFunctionName attribute. This
321 * indicates whether the password supplied with setPassword() is in
322 * plaintext or has had a hash function applied to it. If null,
323 * plaintext is assumed. As of this writing, the only valid hash
324 * function is 'SHA-1'.
326 * @param string $value The desired value for this attribute.
327 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
329 public function setHashFunctionName($value)
331 $this->_hashFunctionName = $value;
336 * Get the value for this element's admin attribute.
339 * @return boolean The requested attribute.
340 * @throws Zend_Gdata_App_InvalidArgumentException
342 public function getAdmin()
344 if (!(is_bool($this->_admin))) {
345 require_once('Zend/Gdata/App/InvalidArgumentException.php');
346 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for admin.');
348 return $this->_admin;
352 * Set the value for this element's admin attribute. This indicates
353 * whether this user is an administrator for this domain.
355 * @param boolean $value The desired value for this attribute.
356 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
357 * @throws Zend_Gdata_App_InvalidArgumentException
359 public function setAdmin($value)
361 if (!(is_bool($value))) {
362 require_once('Zend/Gdata/App/InvalidArgumentException.php');
363 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
365 $this->_admin = $value;
370 * Get the value for this element's agreedToTerms attribute.
372 * @see setAgreedToTerms
373 * @return boolean The requested attribute.
374 * @throws Zend_Gdata_App_InvalidArgumentException
376 public function getAgreedToTerms()
378 if (!(is_bool($this->_agreedToTerms))) {
379 require_once('Zend/Gdata/App/InvalidArgumentException.php');
380 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for agreedToTerms.');
382 return $this->_agreedToTerms;
386 * Set the value for this element's agreedToTerms attribute. This
387 * indicates whether this user has agreed to the terms of service.
389 * @param boolean $value The desired value for this attribute.
390 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
391 * @throws Zend_Gdata_App_InvalidArgumentException
393 public function setAgreedToTerms($value)
395 if (!(is_bool($value))) {
396 require_once('Zend/Gdata/App/InvalidArgumentException.php');
397 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
399 $this->_agreedToTerms = $value;
404 * Get the value for this element's suspended attribute.
407 * @return boolean The requested attribute.
408 * @throws Zend_Gdata_App_InvalidArgumentException
410 public function getSuspended()
412 if (!(is_bool($this->_suspended))) {
413 require_once('Zend/Gdata/App/InvalidArgumentException.php');
414 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for suspended.');
416 return $this->_suspended;
420 * Set the value for this element's suspended attribute. If true, the
421 * user will not be able to login to this domain until unsuspended.
423 * @param boolean $value The desired value for this attribute.
424 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
425 * @throws Zend_Gdata_App_InvalidArgumentException
427 public function setSuspended($value)
429 if (!(is_bool($value))) {
430 require_once('Zend/Gdata/App/InvalidArgumentException.php');
431 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
433 $this->_suspended = $value;
438 * Get the value for this element's changePasswordAtNextLogin attribute.
440 * @see setChangePasswordAtNextLogin
441 * @return boolean The requested attribute.
442 * @throws Zend_Gdata_App_InvalidArgumentException
444 public function getChangePasswordAtNextLogin()
446 if (!(is_bool($this->_changePasswordAtNextLogin))) {
447 require_once('Zend/Gdata/App/InvalidArgumentException.php');
448 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for changePasswordAtNextLogin.');
450 return $this->_changePasswordAtNextLogin;
454 * Set the value for this element's changePasswordAtNextLogin attribute.
455 * If true, the user will be forced to set a new password the next
458 * @param boolean $value The desired value for this attribute.
459 * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
460 * @throws Zend_Gdata_App_InvalidArgumentException
462 public function setChangePasswordAtNextLogin($value)
464 if (!(is_bool($value))) {
465 require_once('Zend/Gdata/App/InvalidArgumentException.php');
466 throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
468 $this->_changePasswordAtNextLogin = $value;
473 * Magic toString method allows using this directly via echo
474 * Works best in PHP >= 4.2.0
476 public function __toString()
478 return "Username: " . $this->getUsername() .
479 "\nPassword: " . (($this->getPassword() === null) ? "NOT SET" : "SET") .
480 "\nPassword Hash Function: " . $this->getHashFunctionName() .
481 "\nAdministrator: " . ($this->getAdmin() ? "Yes" : "No") .
482 "\nAgreed To Terms: " . ($this->getAgreedToTerms() ? "Yes" : "No") .
483 "\nSuspended: " . ($this->getSuspended() ? "Yes" : "No");