File indexing completed on 2024-06-23 05:55:22

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Gdata
0018  * @subpackage Gapps
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 /**
0025  * @see Zend_Gdata_Extension
0026  */
0027 // require_once 'Zend/Gdata/Extension.php';
0028 
0029 /**
0030  * @see Zend_Gdata_Gapps
0031  */
0032 // require_once 'Zend/Gdata/Gapps.php';
0033 
0034 /**
0035  * Represents the apps:login element used by the Apps data API. This
0036  * class is used to describe properties of a user, and is usually contained
0037  * within instances of Zene_Gdata_Gapps_UserEntry or any other class
0038  * which is linked to a particular username.
0039  *
0040  * @category   Zend
0041  * @package    Zend_Gdata
0042  * @subpackage Gapps
0043  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0044  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0045  */
0046 class Zend_Gdata_Gapps_Extension_Login extends Zend_Gdata_Extension
0047 {
0048 
0049     protected $_rootNamespace = 'apps';
0050     protected $_rootElement = 'login';
0051 
0052     /**
0053      * The username for this user. This is used as the user's email address
0054      * and when logging in to Google Apps-hosted services.
0055      *
0056      * @var string
0057      */
0058     protected $_username = null;
0059 
0060     /**
0061      * The password for the user. May be in cleartext or as an SHA-1
0062      * digest, depending on the value of _hashFunctionName.
0063      *
0064      * @var string
0065      */
0066     protected $_password = null;
0067 
0068     /**
0069      * Specifies whether the password stored in _password is in cleartext
0070      * or is an SHA-1 digest of a password. If the password is cleartext,
0071      * then this should be null. If the password is an SHA-1 digest, then
0072      * this should be set to 'SHA-1'.
0073      *
0074      * At the time of writing, no other hash functions are supported
0075      *
0076      * @var string
0077      */
0078     protected $_hashFunctionName = null;
0079 
0080     /**
0081      * True if the user has administrative rights for this domain, false
0082      * otherwise.
0083      *
0084      * @var boolean
0085      */
0086     protected $_admin = null;
0087 
0088     /**
0089      * True if the user has agreed to the terms of service for Google Apps,
0090      * false otherwise.
0091      *
0092      * @var boolean.
0093      */
0094     protected $_agreedToTerms = null;
0095 
0096     /**
0097      * True if this user has been suspended, false otherwise.
0098      *
0099      * @var boolean
0100      */
0101     protected $_suspended = null;
0102 
0103     /**
0104      * True if the user will be required to change their password at
0105      * their next login, false otherwise.
0106      *
0107      * @var boolean
0108      */
0109     protected $_changePasswordAtNextLogin = null;
0110 
0111     /**
0112      * Constructs a new Zend_Gdata_Gapps_Extension_Login object.
0113      *
0114      * @param string $username (optional) The username to be used for this
0115      *          login.
0116      * @param string $password (optional) The password to be used for this
0117      *          login.
0118      * @param string $hashFunctionName (optional) The name of the hash
0119      *          function used to protect the password, or null if no
0120      *          has function has been applied. As of this writing,
0121      *          the only valid values are 'SHA-1' or null.
0122      * @param boolean $admin (optional) Whether the user is an administrator
0123      *          or not.
0124      * @param boolean $suspended (optional) Whether this login is suspended or not.
0125      * @param boolean $changePasswordAtNextLogin (optional) Whether
0126      *          the user is required to change their password at their
0127      *          next login.
0128      * @param boolean $agreedToTerms (optional) Whether the user has
0129      *          agreed to the terms of service.
0130      */
0131     public function __construct($username = null, $password = null,
0132         $hashFunctionName = null, $admin = null, $suspended = null,
0133         $changePasswordAtNextLogin = null, $agreedToTerms = null)
0134     {
0135         $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
0136         parent::__construct();
0137         $this->_username = $username;
0138         $this->_password = $password;
0139         $this->_hashFunctionName = $hashFunctionName;
0140         $this->_admin = $admin;
0141         $this->_agreedToTerms = $agreedToTerms;
0142         $this->_suspended = $suspended;
0143         $this->_changePasswordAtNextLogin = $changePasswordAtNextLogin;
0144     }
0145 
0146     /**
0147      * Retrieves a DOMElement which corresponds to this element and all
0148      * child properties.  This is used to build an entry back into a DOM
0149      * and eventually XML text for sending to the server upon updates, or
0150      * for application storage/persistence.
0151      *
0152      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
0153      * @return DOMElement The DOMElement representing this element and all
0154      * child properties.
0155      */
0156     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0157     {
0158         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0159         if ($this->_username !== null) {
0160             $element->setAttribute('userName', $this->_username);
0161         }
0162         if ($this->_password !== null) {
0163             $element->setAttribute('password', $this->_password);
0164         }
0165         if ($this->_hashFunctionName !== null) {
0166             $element->setAttribute('hashFunctionName', $this->_hashFunctionName);
0167         }
0168         if ($this->_admin !== null) {
0169             $element->setAttribute('admin', ($this->_admin ? "true" : "false"));
0170         }
0171         if ($this->_agreedToTerms !== null) {
0172             $element->setAttribute('agreedToTerms', ($this->_agreedToTerms ? "true" : "false"));
0173         }
0174         if ($this->_suspended !== null) {
0175             $element->setAttribute('suspended', ($this->_suspended ? "true" : "false"));
0176         }
0177         if ($this->_changePasswordAtNextLogin !== null) {
0178             $element->setAttribute('changePasswordAtNextLogin', ($this->_changePasswordAtNextLogin ? "true" : "false"));
0179         }
0180 
0181         return $element;
0182     }
0183 
0184     /**
0185      * Given a DOMNode representing an attribute, tries to map the data into
0186      * instance members.  If no mapping is defined, the name and value are
0187      * stored in an array.
0188      *
0189      * @param DOMNode $attribute The DOMNode attribute needed to be handled
0190      * @throws Zend_Gdata_App_InvalidArgumentException
0191      */
0192     protected function takeAttributeFromDOM($attribute)
0193     {
0194         switch ($attribute->localName) {
0195         case 'userName':
0196             $this->_username = $attribute->nodeValue;
0197             break;
0198         case 'password':
0199             $this->_password = $attribute->nodeValue;
0200             break;
0201         case 'hashFunctionName':
0202             $this->_hashFunctionName = $attribute->nodeValue;
0203             break;
0204         case 'admin':
0205             if ($attribute->nodeValue == "true") {
0206                 $this->_admin = true;
0207             }
0208             else if ($attribute->nodeValue == "false") {
0209                 $this->_admin = false;
0210             }
0211             else {
0212                 // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0213                 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#admin.");
0214             }
0215             break;
0216         case 'agreedToTerms':
0217             if ($attribute->nodeValue == "true") {
0218                 $this->_agreedToTerms = true;
0219             }
0220             else if ($attribute->nodeValue == "false") {
0221                 $this->_agreedToTerms = false;
0222             }
0223             else {
0224                 // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0225                 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#agreedToTerms.");
0226             }
0227             break;
0228         case 'suspended':
0229             if ($attribute->nodeValue == "true") {
0230                 $this->_suspended = true;
0231             }
0232             else if ($attribute->nodeValue == "false") {
0233                 $this->_suspended = false;
0234             }
0235             else {
0236                 // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0237                 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#suspended.");
0238             }
0239             break;
0240         case 'changePasswordAtNextLogin':
0241             if ($attribute->nodeValue == "true") {
0242                 $this->_changePasswordAtNextLogin = true;
0243             }
0244             else if ($attribute->nodeValue == "false") {
0245                 $this->_changePasswordAtNextLogin = false;
0246             }
0247             else {
0248                 // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0249                 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#changePasswordAtNextLogin.");
0250             }
0251             break;
0252         default:
0253             parent::takeAttributeFromDOM($attribute);
0254         }
0255     }
0256 
0257     /**
0258      * Get the value for this element's username attribute.
0259      *
0260      * @see setUsername
0261      * @return string The attribute being modified.
0262      */
0263     public function getUsername()
0264     {
0265         return $this->_username;
0266     }
0267 
0268     /**
0269      * Set the value for this element's username attribute. This string
0270      * is used to uniquely identify the user in this domian and is used
0271      * to form this user's email address.
0272      *
0273      * @param string $value The desired value for this attribute.
0274      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0275      */
0276     public function setUsername($value)
0277     {
0278         $this->_username = $value;
0279         return $this;
0280     }
0281 
0282     /**
0283      * Get the value for this element's password attribute.
0284      *
0285      * @see setPassword
0286      * @return string The requested attribute.
0287      */
0288     public function getPassword()
0289     {
0290         return $this->_password;
0291     }
0292 
0293     /**
0294      * Set the value for this element's password attribute. As of this
0295      * writing, this can be either be provided as plaintext or hashed using
0296      * the SHA-1 algorithm for protection. If using a hash function,
0297      * this must be indicated by calling setHashFunctionName().
0298      *
0299      * @param string $value The desired value for this attribute.
0300      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0301      */
0302     public function setPassword($value)
0303     {
0304         $this->_password = $value;
0305         return $this;
0306     }
0307 
0308     /**
0309      * Get the value for this element's hashFunctionName attribute.
0310      *
0311      * @see setHashFunctionName
0312      * @return string The requested attribute.
0313      */
0314     public function getHashFunctionName()
0315     {
0316         return $this->_hashFunctionName;
0317     }
0318 
0319     /**
0320      * Set the value for this element's hashFunctionName attribute. This
0321      * indicates whether the password supplied with setPassword() is in
0322      * plaintext or has had a hash function applied to it. If null,
0323      * plaintext is assumed. As of this writing, the only valid hash
0324      * function is 'SHA-1'.
0325      *
0326      * @param string $value The desired value for this attribute.
0327      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0328      */
0329     public function setHashFunctionName($value)
0330     {
0331         $this->_hashFunctionName = $value;
0332         return $this;
0333     }
0334 
0335     /**
0336      * Get the value for this element's admin attribute.
0337      *
0338      * @see setAdmin
0339      * @return boolean The requested attribute.
0340      * @throws Zend_Gdata_App_InvalidArgumentException
0341      */
0342     public function getAdmin()
0343     {
0344         if (!(is_bool($this->_admin))) {
0345             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0346             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for admin.');
0347         }
0348         return $this->_admin;
0349     }
0350 
0351     /**
0352      * Set the value for this element's admin attribute. This indicates
0353      * whether this user is an administrator for this domain.
0354      *
0355      * @param boolean $value The desired value for this attribute.
0356      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0357      * @throws Zend_Gdata_App_InvalidArgumentException
0358      */
0359     public function setAdmin($value)
0360     {
0361         if (!(is_bool($value))) {
0362             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0363             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
0364         }
0365         $this->_admin = $value;
0366         return $this;
0367     }
0368 
0369     /**
0370      * Get the value for this element's agreedToTerms attribute.
0371      *
0372      * @see setAgreedToTerms
0373      * @return boolean The requested attribute.
0374      * @throws Zend_Gdata_App_InvalidArgumentException
0375      */
0376     public function getAgreedToTerms()
0377     {
0378         if (!(is_bool($this->_agreedToTerms))) {
0379             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0380             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for agreedToTerms.');
0381         }
0382         return $this->_agreedToTerms;
0383     }
0384 
0385     /**
0386      * Set the value for this element's agreedToTerms attribute. This
0387      * indicates whether this user has agreed to the terms of service.
0388      *
0389      * @param boolean $value The desired value for this attribute.
0390      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0391      * @throws Zend_Gdata_App_InvalidArgumentException
0392      */
0393     public function setAgreedToTerms($value)
0394     {
0395         if (!(is_bool($value))) {
0396             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0397             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
0398         }
0399         $this->_agreedToTerms = $value;
0400         return $this;
0401     }
0402 
0403     /**
0404      * Get the value for this element's suspended attribute.
0405      *
0406      * @see setSuspended
0407      * @return boolean The requested attribute.
0408      * @throws Zend_Gdata_App_InvalidArgumentException
0409      */
0410     public function getSuspended()
0411     {
0412         if (!(is_bool($this->_suspended))) {
0413             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0414             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for suspended.');
0415         }
0416         return $this->_suspended;
0417     }
0418 
0419     /**
0420      * Set the value for this element's suspended attribute. If true, the
0421      * user will not be able to login to this domain until unsuspended.
0422      *
0423      * @param boolean $value The desired value for this attribute.
0424      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0425      * @throws Zend_Gdata_App_InvalidArgumentException
0426      */
0427     public function setSuspended($value)
0428     {
0429         if (!(is_bool($value))) {
0430             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0431             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
0432         }
0433         $this->_suspended = $value;
0434         return $this;
0435     }
0436 
0437     /**
0438      * Get the value for this element's changePasswordAtNextLogin attribute.
0439      *
0440      * @see setChangePasswordAtNextLogin
0441      * @return boolean The requested attribute.
0442      * @throws Zend_Gdata_App_InvalidArgumentException
0443      */
0444     public function getChangePasswordAtNextLogin()
0445     {
0446         if (!(is_bool($this->_changePasswordAtNextLogin))) {
0447             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0448             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for changePasswordAtNextLogin.');
0449         }
0450         return $this->_changePasswordAtNextLogin;
0451     }
0452 
0453     /**
0454      * Set the value for this element's changePasswordAtNextLogin attribute.
0455      * If true, the user will be forced to set a new password the next
0456      * time they login.
0457      *
0458      * @param boolean $value The desired value for this attribute.
0459      * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
0460      * @throws Zend_Gdata_App_InvalidArgumentException
0461      */
0462     public function setChangePasswordAtNextLogin($value)
0463     {
0464         if (!(is_bool($value))) {
0465             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0466             throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
0467         }
0468         $this->_changePasswordAtNextLogin = $value;
0469         return $this;
0470     }
0471 
0472     /**
0473      * Magic toString method allows using this directly via echo
0474      * Works best in PHP >= 4.2.0
0475      */
0476     public function __toString()
0477     {
0478         return "Username: " . $this->getUsername() .
0479             "\nPassword: " . (($this->getPassword() === null) ? "NOT SET" : "SET") .
0480             "\nPassword Hash Function: " . $this->getHashFunctionName() .
0481             "\nAdministrator: " . ($this->getAdmin() ? "Yes" : "No") .
0482             "\nAgreed To Terms: " . ($this->getAgreedToTerms() ? "Yes" : "No") .
0483             "\nSuspended: " . ($this->getSuspended() ? "Yes" : "No");
0484     }
0485 }