apiqvittercheckemail.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Check email
  6. *
  7. * Returns 1 if email is already in use on this instance, 0 if not. Error if site is private.
  8. *
  9. * PHP version 5
  10. *
  11. * LICENCE: This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * @category API
  25. * @package GNUsocial
  26. * @author Hannes Mannerheim <h@nnesmannerhe.im>
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://www.gnu.org/software/social/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. class ApiQvitterCheckEmailAction extends ApiAction
  32. {
  33. var $email = null;
  34. protected function prepare(array $args=array())
  35. {
  36. parent::prepare($args);
  37. $this->format = 'json';
  38. $this->email = $this->trimmed('email');
  39. if(!Validate::email($this->email, common_config('email', 'check_domain'))) {
  40. $this->clientError('Not a valid email address.', 400);
  41. }
  42. if (common_config('site', 'private')) {
  43. $this->clientError(_('This site is private.'), 403);
  44. }
  45. return true;
  46. }
  47. protected function handle()
  48. {
  49. parent::handle();
  50. if($this->emailExists($this->email)) {
  51. $email_exists = 1;
  52. } else {
  53. $email_exists = 0;
  54. }
  55. $this->initDocument('json');
  56. $this->showJsonObjects($email_exists);
  57. $this->endDocument('json');
  58. }
  59. /**
  60. * Does the given email address already exist?
  61. *
  62. * Checks a canonical email address against the database.
  63. *
  64. * @param string $email email address to check
  65. *
  66. * @return boolean true if the address already exists
  67. */
  68. function emailExists($email)
  69. {
  70. $user = User::getKV('email', $email);
  71. return is_object($user);
  72. }
  73. }