AuthUsersTable.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @since 3.0.0
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace TestApp\Model\Table;
  14. use Cake\Core\Exception\Exception;
  15. use Cake\ORM\Query;
  16. use Cake\ORM\Table;
  17. /**
  18. * AuthUser class
  19. */
  20. class AuthUsersTable extends Table
  21. {
  22. /**
  23. * Custom finder
  24. *
  25. * @param \Cake\ORM\Query $query The query to find with
  26. * @param array $options The options to find with
  27. * @return \Cake\ORM\Query The query builder
  28. */
  29. public function findAuth(Query $query, array $options)
  30. {
  31. $query->select(['id', 'username', 'password']);
  32. if (!empty($options['return_created'])) {
  33. $query->select(['created']);
  34. }
  35. return $query;
  36. }
  37. /**
  38. * Custom finder
  39. *
  40. * @param \Cake\ORM\Query $query The query to find with
  41. * @param array $options The options to find with
  42. * @return \Cake\ORM\Query The query builder
  43. */
  44. public function findUsername(Query $query, array $options)
  45. {
  46. if (empty($options['username'])) {
  47. throw new Exception(__('Username not defined'));
  48. }
  49. $query = $this->find()
  50. ->where(['username' => $options['username']])
  51. ->select(['id', 'username', 'password']);
  52. return $query;
  53. }
  54. }