customlogin.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Login
  4. *
  5. * Copyright 2010 by Jason Coward <jason@modx.com> and Shaun McCormick <shaun+login@modx.com>
  6. *
  7. * Login is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option) any
  10. * later version.
  11. *
  12. * Login is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * Login; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. * Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * @package login
  21. */
  22. /**
  23. * Custom login processor to enable login via username or email address (either one!)
  24. *
  25. * @package login
  26. * @subpackage processors
  27. */
  28. require_once MODX_CORE_PATH.'model/modx/processors/security/login.class.php';
  29. class CustomLoginProcessor extends modSecurityLoginProcessor {
  30. /**
  31. * {@inheritDoc}
  32. *
  33. * @return bool|null|string
  34. */
  35. public function getUser() {
  36. // Only accept login via email address if it exists only once!
  37. $count = $this->modx->getCount('modUserProfile', array(
  38. 'email' => $this->username,
  39. ));
  40. if ($count > 1) {
  41. $criteria = array ('modUser.username' => $this->username);
  42. } else {
  43. $criteria = array(
  44. array('modUser.username' => $this->username),
  45. array('OR:Profile.email:=' => $this->username)
  46. );
  47. }
  48. /** @var $user modUser */
  49. $this->user = $this->modx->getObjectGraph('modUser', '{"Profile":{},"UserSettings":{}}', $criteria);
  50. return $this->fireOnUserNotFoundEvent();
  51. }
  52. }
  53. return 'CustomLoginProcessor';