UserInterface.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace Drupal\user;
  3. use Drupal\Core\Entity\EntityChangedInterface;
  4. use Drupal\Core\Entity\ContentEntityInterface;
  5. use Drupal\Core\Session\AccountInterface;
  6. /**
  7. * Provides an interface defining a user entity.
  8. *
  9. * @ingroup user_api
  10. */
  11. interface UserInterface extends ContentEntityInterface, EntityChangedInterface, AccountInterface {
  12. /**
  13. * Maximum length of username text field.
  14. *
  15. * Keep this under 191 characters so we can use a unique constraint in MySQL.
  16. */
  17. const USERNAME_MAX_LENGTH = 60;
  18. /**
  19. * Only administrators can create user accounts.
  20. */
  21. const REGISTER_ADMINISTRATORS_ONLY = 'admin_only';
  22. /**
  23. * Visitors can create their own accounts.
  24. */
  25. const REGISTER_VISITORS = 'visitors';
  26. /**
  27. * Visitors can create accounts that only become active with admin approval.
  28. */
  29. const REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 'visitors_admin_approval';
  30. /**
  31. * New users will be set to the default time zone at registration.
  32. */
  33. const TIMEZONE_DEFAULT = 0;
  34. /**
  35. * New users will get an empty time zone at registration.
  36. */
  37. const TIMEZONE_EMPTY = 1;
  38. /**
  39. * New users will select their own timezone at registration.
  40. */
  41. const TIMEZONE_SELECT = 2;
  42. /**
  43. * Whether a user has a certain role.
  44. *
  45. * @param string $rid
  46. * The role ID to check.
  47. *
  48. * @return bool
  49. * Returns TRUE if the user has the role, otherwise FALSE.
  50. */
  51. public function hasRole($rid);
  52. /**
  53. * Add a role to a user.
  54. *
  55. * @param string $rid
  56. * The role ID to add.
  57. */
  58. public function addRole($rid);
  59. /**
  60. * Remove a role from a user.
  61. *
  62. * @param string $rid
  63. * The role ID to remove.
  64. */
  65. public function removeRole($rid);
  66. /**
  67. * Sets the username of this account.
  68. *
  69. * @param string $username
  70. * The new user name.
  71. *
  72. * @return $this
  73. * The called user entity.
  74. */
  75. public function setUsername($username);
  76. /**
  77. * Returns the hashed password.
  78. *
  79. * @return string
  80. * The hashed password.
  81. */
  82. public function getPassword();
  83. /**
  84. * Sets the user password.
  85. *
  86. * @param string $password
  87. * The new unhashed password.
  88. *
  89. * @return $this
  90. * The called user entity.
  91. */
  92. public function setPassword($password);
  93. /**
  94. * Sets the email address of the user.
  95. *
  96. * @param string $mail
  97. * The new email address of the user.
  98. *
  99. * @return $this
  100. * The called user entity.
  101. */
  102. public function setEmail($mail);
  103. /**
  104. * Returns the creation time of the user as a UNIX timestamp.
  105. *
  106. * @return int
  107. * Timestamp of the creation date.
  108. */
  109. public function getCreatedTime();
  110. /**
  111. * Sets the UNIX timestamp when the user last accessed the site..
  112. *
  113. * @param int $timestamp
  114. * Timestamp of the last access.
  115. *
  116. * @return $this
  117. * The called user entity.
  118. */
  119. public function setLastAccessTime($timestamp);
  120. /**
  121. * Returns the UNIX timestamp when the user last logged in.
  122. *
  123. * @return int
  124. * Timestamp of the last login time.
  125. */
  126. public function getLastLoginTime();
  127. /**
  128. * Sets the UNIX timestamp when the user last logged in.
  129. *
  130. * @param int $timestamp
  131. * Timestamp of the last login time.
  132. *
  133. * @return $this
  134. * The called user entity.
  135. */
  136. public function setLastLoginTime($timestamp);
  137. /**
  138. * Returns TRUE if the user is active.
  139. *
  140. * @return bool
  141. * TRUE if the user is active, false otherwise.
  142. */
  143. public function isActive();
  144. /**
  145. * Returns TRUE if the user is blocked.
  146. *
  147. * @return bool
  148. * TRUE if the user is blocked, false otherwise.
  149. */
  150. public function isBlocked();
  151. /**
  152. * Activates the user.
  153. *
  154. * @return $this
  155. * The called user entity.
  156. */
  157. public function activate();
  158. /**
  159. * Blocks the user.
  160. *
  161. * @return $this
  162. * The called user entity.
  163. */
  164. public function block();
  165. /**
  166. * Returns the email that was used when the user was registered.
  167. *
  168. * @return string
  169. * Initial email address of the user.
  170. */
  171. public function getInitialEmail();
  172. /**
  173. * Sets the existing plain text password.
  174. *
  175. * Required for validation when changing the password, name or email fields.
  176. *
  177. * @param string $password
  178. * The existing plain text password of the user.
  179. *
  180. * @return $this
  181. */
  182. public function setExistingPassword($password);
  183. /**
  184. * Checks the existing password if set.
  185. *
  186. * @param \Drupal\user\UserInterface $account_unchanged
  187. * The unchanged user entity to compare against.
  188. *
  189. * @return bool
  190. * TRUE if the correct existing password was provided.
  191. *
  192. * @see UserInterface::setExistingPassword()
  193. */
  194. public function checkExistingPassword(UserInterface $account_unchanged);
  195. }