PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jvit/library/Zend/Gdata/Gapps/Extension/Login.php

https://github.com/juanjack/JUANJACK
PHP | 485 lines | 223 code | 31 blank | 231 comment | 44 complexity | 63730329951d26919002f198065c352d MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gapps
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Login.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * @see Zend_Gdata_Gapps
  28. */
  29. require_once 'Zend/Gdata/Gapps.php';
  30. /**
  31. * Represents the apps:login element used by the Apps data API. This
  32. * class is used to describe properties of a user, and is usually contained
  33. * within instances of Zene_Gdata_Gapps_UserEntry or any other class
  34. * which is linked to a particular username.
  35. *
  36. * @category Zend
  37. * @package Zend_Gdata
  38. * @subpackage Gapps
  39. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. */
  42. class Zend_Gdata_Gapps_Extension_Login extends Zend_Gdata_Extension
  43. {
  44. protected $_rootNamespace = 'apps';
  45. protected $_rootElement = 'login';
  46. /**
  47. * The username for this user. This is used as the user's email address
  48. * and when logging in to Google Apps-hosted services.
  49. *
  50. * @var string
  51. */
  52. protected $_username = null;
  53. /**
  54. * The password for the user. May be in cleartext or as an SHA-1
  55. * digest, depending on the value of _hashFunctionName.
  56. *
  57. * @var string
  58. */
  59. protected $_password = null;
  60. /**
  61. * Specifies whether the password stored in _password is in cleartext
  62. * or is an SHA-1 digest of a password. If the password is cleartext,
  63. * then this should be null. If the password is an SHA-1 digest, then
  64. * this should be set to 'SHA-1'.
  65. *
  66. * At the time of writing, no other hash functions are supported
  67. *
  68. * @var string
  69. */
  70. protected $_hashFunctionName = null;
  71. /**
  72. * True if the user has administrative rights for this domain, false
  73. * otherwise.
  74. *
  75. * @var boolean
  76. */
  77. protected $_admin = null;
  78. /**
  79. * True if the user has agreed to the terms of service for Google Apps,
  80. * false otherwise.
  81. *
  82. * @var boolean.
  83. */
  84. protected $_agreedToTerms = null;
  85. /**
  86. * True if this user has been suspended, false otherwise.
  87. *
  88. * @var boolean
  89. */
  90. protected $_suspended = null;
  91. /**
  92. * True if the user will be required to change their password at
  93. * their next login, false otherwise.
  94. *
  95. * @var boolean
  96. */
  97. protected $_changePasswordAtNextLogin = null;
  98. /**
  99. * Constructs a new Zend_Gdata_Gapps_Extension_Login object.
  100. *
  101. * @param string $username (optional) The username to be used for this
  102. * login.
  103. * @param string $password (optional) The password to be used for this
  104. * login.
  105. * @param string $hashFunctionName (optional) The name of the hash
  106. * function used to protect the password, or null if no
  107. * has function has been applied. As of this writing,
  108. * the only valid values are 'SHA-1' or null.
  109. * @param boolean $admin (optional) Whether the user is an administrator
  110. * or not.
  111. * @param boolean $suspended (optional) Whether this login is suspended or not.
  112. * @param boolean $changePasswordAtNextLogin (optional) Whether
  113. * the user is required to change their password at their
  114. * next login.
  115. * @param boolean $agreedToTerms (optional) Whether the user has
  116. * agreed to the terms of service.
  117. */
  118. public function __construct($username = null, $password = null,
  119. $hashFunctionName = null, $admin = null, $suspended = null,
  120. $changePasswordAtNextLogin = null, $agreedToTerms = null)
  121. {
  122. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  123. parent::__construct();
  124. $this->_username = $username;
  125. $this->_password = $password;
  126. $this->_hashFunctionName = $hashFunctionName;
  127. $this->_admin = $admin;
  128. $this->_agreedToTerms = $agreedToTerms;
  129. $this->_suspended = $suspended;
  130. $this->_changePasswordAtNextLogin = $changePasswordAtNextLogin;
  131. }
  132. /**
  133. * Retrieves a DOMElement which corresponds to this element and all
  134. * child properties. This is used to build an entry back into a DOM
  135. * and eventually XML text for sending to the server upon updates, or
  136. * for application storage/persistence.
  137. *
  138. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  139. * @return DOMElement The DOMElement representing this element and all
  140. * child properties.
  141. */
  142. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  143. {
  144. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  145. if ($this->_username !== null) {
  146. $element->setAttribute('userName', $this->_username);
  147. }
  148. if ($this->_password !== null) {
  149. $element->setAttribute('password', $this->_password);
  150. }
  151. if ($this->_hashFunctionName !== null) {
  152. $element->setAttribute('hashFunctionName', $this->_hashFunctionName);
  153. }
  154. if ($this->_admin !== null) {
  155. $element->setAttribute('admin', ($this->_admin ? "true" : "false"));
  156. }
  157. if ($this->_agreedToTerms !== null) {
  158. $element->setAttribute('agreedToTerms', ($this->_agreedToTerms ? "true" : "false"));
  159. }
  160. if ($this->_suspended !== null) {
  161. $element->setAttribute('suspended', ($this->_suspended ? "true" : "false"));
  162. }
  163. if ($this->_changePasswordAtNextLogin !== null) {
  164. $element->setAttribute('changePasswordAtNextLogin', ($this->_changePasswordAtNextLogin ? "true" : "false"));
  165. }
  166. return $element;
  167. }
  168. /**
  169. * Given a DOMNode representing an attribute, tries to map the data into
  170. * instance members. If no mapping is defined, the name and value are
  171. * stored in an array.
  172. *
  173. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  174. * @throws Zend_Gdata_App_InvalidArgumentException
  175. */
  176. protected function takeAttributeFromDOM($attribute)
  177. {
  178. switch ($attribute->localName) {
  179. case 'userName':
  180. $this->_username = $attribute->nodeValue;
  181. break;
  182. case 'password':
  183. $this->_password = $attribute->nodeValue;
  184. break;
  185. case 'hashFunctionName':
  186. $this->_hashFunctionName = $attribute->nodeValue;
  187. break;
  188. case 'admin':
  189. if ($attribute->nodeValue == "true") {
  190. $this->_admin = true;
  191. }
  192. else if ($attribute->nodeValue == "false") {
  193. $this->_admin = false;
  194. }
  195. else {
  196. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  197. throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#admin.");
  198. }
  199. break;
  200. case 'agreedToTerms':
  201. if ($attribute->nodeValue == "true") {
  202. $this->_agreedToTerms = true;
  203. }
  204. else if ($attribute->nodeValue == "false") {
  205. $this->_agreedToTerms = false;
  206. }
  207. else {
  208. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  209. throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#agreedToTerms.");
  210. }
  211. break;
  212. case 'suspended':
  213. if ($attribute->nodeValue == "true") {
  214. $this->_suspended = true;
  215. }
  216. else if ($attribute->nodeValue == "false") {
  217. $this->_suspended = false;
  218. }
  219. else {
  220. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  221. throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#suspended.");
  222. }
  223. break;
  224. case 'changePasswordAtNextLogin':
  225. if ($attribute->nodeValue == "true") {
  226. $this->_changePasswordAtNextLogin = true;
  227. }
  228. else if ($attribute->nodeValue == "false") {
  229. $this->_changePasswordAtNextLogin = false;
  230. }
  231. else {
  232. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  233. throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#changePasswordAtNextLogin.");
  234. }
  235. break;
  236. default:
  237. parent::takeAttributeFromDOM($attribute);
  238. }
  239. }
  240. /**
  241. * Get the value for this element's username attribute.
  242. *
  243. * @see setUsername
  244. * @return string The attribute being modified.
  245. */
  246. public function getUsername()
  247. {
  248. return $this->_username;
  249. }
  250. /**
  251. * Set the value for this element's username attribute. This string
  252. * is used to uniquely identify the user in this domian and is used
  253. * to form this user's email address.
  254. *
  255. * @param string $value The desired value for this attribute.
  256. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  257. */
  258. public function setUsername($value)
  259. {
  260. $this->_username = $value;
  261. return $this;
  262. }
  263. /**
  264. * Get the value for this element's password attribute.
  265. *
  266. * @see setPassword
  267. * @return string The requested attribute.
  268. */
  269. public function getPassword()
  270. {
  271. return $this->_password;
  272. }
  273. /**
  274. * Set the value for this element's password attribute. As of this
  275. * writing, this can be either be provided as plaintext or hashed using
  276. * the SHA-1 algorithm for protection. If using a hash function,
  277. * this must be indicated by calling setHashFunctionName().
  278. *
  279. * @param string $value The desired value for this attribute.
  280. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  281. */
  282. public function setPassword($value)
  283. {
  284. $this->_password = $value;
  285. return $this;
  286. }
  287. /**
  288. * Get the value for this element's hashFunctionName attribute.
  289. *
  290. * @see setHashFunctionName
  291. * @return string The requested attribute.
  292. */
  293. public function getHashFunctionName()
  294. {
  295. return $this->_hashFunctionName;
  296. }
  297. /**
  298. * Set the value for this element's hashFunctionName attribute. This
  299. * indicates whether the password supplied with setPassword() is in
  300. * plaintext or has had a hash function applied to it. If null,
  301. * plaintext is assumed. As of this writing, the only valid hash
  302. * function is 'SHA-1'.
  303. *
  304. * @param string $value The desired value for this attribute.
  305. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  306. */
  307. public function setHashFunctionName($value)
  308. {
  309. $this->_hashFunctionName = $value;
  310. return $this;
  311. }
  312. /**
  313. * Get the value for this element's admin attribute.
  314. *
  315. * @see setAdmin
  316. * @return boolean The requested attribute.
  317. * @throws Zend_Gdata_App_InvalidArgumentException
  318. */
  319. public function getAdmin()
  320. {
  321. if (!(is_bool($this->_admin))) {
  322. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  323. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for admin.');
  324. }
  325. return $this->_admin;
  326. }
  327. /**
  328. * Set the value for this element's admin attribute. This indicates
  329. * whether this user is an administrator for this domain.
  330. *
  331. * @param boolean $value The desired value for this attribute.
  332. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  333. * @throws Zend_Gdata_App_InvalidArgumentException
  334. */
  335. public function setAdmin($value)
  336. {
  337. if (!(is_bool($value))) {
  338. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  339. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
  340. }
  341. $this->_admin = $value;
  342. return $this;
  343. }
  344. /**
  345. * Get the value for this element's agreedToTerms attribute.
  346. *
  347. * @see setAgreedToTerms
  348. * @return boolean The requested attribute.
  349. * @throws Zend_Gdata_App_InvalidArgumentException
  350. */
  351. public function getAgreedToTerms()
  352. {
  353. if (!(is_bool($this->_agreedToTerms))) {
  354. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  355. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for agreedToTerms.');
  356. }
  357. return $this->_agreedToTerms;
  358. }
  359. /**
  360. * Set the value for this element's agreedToTerms attribute. This
  361. * indicates whether this user has agreed to the terms of service.
  362. *
  363. * @param boolean $value The desired value for this attribute.
  364. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  365. * @throws Zend_Gdata_App_InvalidArgumentException
  366. */
  367. public function setAgreedToTerms($value)
  368. {
  369. if (!(is_bool($value))) {
  370. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  371. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
  372. }
  373. $this->_agreedToTerms = $value;
  374. return $this;
  375. }
  376. /**
  377. * Get the value for this element's suspended attribute.
  378. *
  379. * @see setSuspended
  380. * @return boolean The requested attribute.
  381. * @throws Zend_Gdata_App_InvalidArgumentException
  382. */
  383. public function getSuspended()
  384. {
  385. if (!(is_bool($this->_suspended))) {
  386. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  387. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for suspended.');
  388. }
  389. return $this->_suspended;
  390. }
  391. /**
  392. * Set the value for this element's suspended attribute. If true, the
  393. * user will not be able to login to this domain until unsuspended.
  394. *
  395. * @param boolean $value The desired value for this attribute.
  396. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  397. * @throws Zend_Gdata_App_InvalidArgumentException
  398. */
  399. public function setSuspended($value)
  400. {
  401. if (!(is_bool($value))) {
  402. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  403. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
  404. }
  405. $this->_suspended = $value;
  406. return $this;
  407. }
  408. /**
  409. * Get the value for this element's changePasswordAtNextLogin attribute.
  410. *
  411. * @see setChangePasswordAtNextLogin
  412. * @return boolean The requested attribute.
  413. * @throws Zend_Gdata_App_InvalidArgumentException
  414. */
  415. public function getChangePasswordAtNextLogin()
  416. {
  417. if (!(is_bool($this->_changePasswordAtNextLogin))) {
  418. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  419. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for changePasswordAtNextLogin.');
  420. }
  421. return $this->_changePasswordAtNextLogin;
  422. }
  423. /**
  424. * Set the value for this element's changePasswordAtNextLogin attribute.
  425. * If true, the user will be forced to set a new password the next
  426. * time they login.
  427. *
  428. * @param boolean $value The desired value for this attribute.
  429. * @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
  430. * @throws Zend_Gdata_App_InvalidArgumentException
  431. */
  432. public function setChangePasswordAtNextLogin($value)
  433. {
  434. if (!(is_bool($value))) {
  435. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  436. throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
  437. }
  438. $this->_changePasswordAtNextLogin = $value;
  439. return $this;
  440. }
  441. /**
  442. * Magic toString method allows using this directly via echo
  443. * Works best in PHP >= 4.2.0
  444. */
  445. public function __toString()
  446. {
  447. return "Username: " . $this->getUsername() .
  448. "\nPassword: " . (($this->getPassword() === null) ? "NOT SET" : "SET") .
  449. "\nPassword Hash Function: " . $this->getHashFunctionName() .
  450. "\nAdministrator: " . ($this->getAdmin() ? "Yes" : "No") .
  451. "\nAgreed To Terms: " . ($this->getAgreedToTerms() ? "Yes" : "No") .
  452. "\nSuspended: " . ($this->getSuspended() ? "Yes" : "No");
  453. }
  454. }