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