Web Interfaces of PROSUME

User.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Model\Entity;
  3. use Cake\ORM\Entity;
  4. use Cake\Auth\DefaultPasswordHasher;
  5. /**
  6. * User Entity
  7. *
  8. * @property int $id
  9. * @property string $username
  10. * @property string $password
  11. * @property string|null $emailaddress
  12. * @property string|null $role
  13. * @property \Cake\I18n\FrozenTime|null $created
  14. * @property \Cake\I18n\FrozenTime|null $modified
  15. */
  16. class User extends Entity
  17. {
  18. /**
  19. * Fields that can be mass assigned using newEntity() or patchEntity().
  20. *
  21. * Note that when '*' is set to true, this allows all unspecified fields to
  22. * be mass assigned. For security purposes, it is advised to set '*' to false
  23. * (or remove it), and explicitly make individual fields accessible as needed.
  24. *
  25. * @var array
  26. */
  27. protected $_accessible = [
  28. 'username' => true,
  29. 'password' => true,
  30. 'emailaddress' => true,
  31. 'role' => true,
  32. 'meter_id' => true,
  33. 'created' => true,
  34. 'modified' => true
  35. ];
  36. /**
  37. * Fields that are excluded from JSON versions of the entity.
  38. *
  39. * @var array
  40. */
  41. protected $_hidden = [
  42. 'password'
  43. ];
  44. protected function _setPassword($password)
  45. {
  46. if (strlen($password) > 0) {
  47. return (new DefaultPasswordHasher)->hash($password);
  48. }
  49. }
  50. }