5 use Drupal\Core\Entity\EntityChangedInterface;
6 use Drupal\Core\Entity\ContentEntityInterface;
7 use Drupal\Core\Session\AccountInterface;
10 * Provides an interface defining a user entity.
14 interface UserInterface extends ContentEntityInterface, EntityChangedInterface, AccountInterface {
17 * Maximum length of username text field.
19 * Keep this under 191 characters so we can use a unique constraint in MySQL.
21 const USERNAME_MAX_LENGTH = 60;
24 * Only administrators can create user accounts.
26 const REGISTER_ADMINISTRATORS_ONLY = 'admin_only';
29 * Visitors can create their own accounts.
31 const REGISTER_VISITORS = 'visitors';
34 * Visitors can create accounts that only become active with admin approval.
36 const REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 'visitors_admin_approval';
39 * New users will be set to the default time zone at registration.
41 const TIMEZONE_DEFAULT = 0;
44 * New users will get an empty time zone at registration.
46 const TIMEZONE_EMPTY = 1;
49 * New users will select their own timezone at registration.
51 const TIMEZONE_SELECT = 2;
54 * Whether a user has a certain role.
57 * The role ID to check.
60 * Returns TRUE if the user has the role, otherwise FALSE.
62 public function hasRole($rid);
65 * Add a role to a user.
70 public function addRole($rid);
73 * Remove a role from a user.
76 * The role ID to remove.
78 public function removeRole($rid);
81 * Sets the username of this account.
83 * @param string $username
86 * @return \Drupal\user\UserInterface
87 * The called user entity.
89 public function setUsername($username);
92 * Returns the hashed password.
95 * The hashed password.
97 public function getPassword();
100 * Sets the user password.
102 * @param string $password
103 * The new unhashed password.
105 * @return \Drupal\user\UserInterface
106 * The called user entity.
108 public function setPassword($password);
111 * Sets the email address of the user.
113 * @param string $mail
114 * The new email address of the user.
116 * @return \Drupal\user\UserInterface
117 * The called user entity.
119 public function setEmail($mail);
122 * Returns the creation time of the user as a UNIX timestamp.
125 * Timestamp of the creation date.
127 public function getCreatedTime();
130 * Sets the UNIX timestamp when the user last accessed the site..
132 * @param int $timestamp
133 * Timestamp of the last access.
135 * @return \Drupal\user\UserInterface
136 * The called user entity.
138 public function setLastAccessTime($timestamp);
141 * Returns the UNIX timestamp when the user last logged in.
144 * Timestamp of the last login time.
146 public function getLastLoginTime();
149 * Sets the UNIX timestamp when the user last logged in.
151 * @param int $timestamp
152 * Timestamp of the last login time.
154 * @return \Drupal\user\UserInterface
155 * The called user entity.
157 public function setLastLoginTime($timestamp);
160 * Returns TRUE if the user is active.
163 * TRUE if the user is active, false otherwise.
165 public function isActive();
168 * Returns TRUE if the user is blocked.
171 * TRUE if the user is blocked, false otherwise.
173 public function isBlocked();
176 * Activates the user.
178 * @return \Drupal\user\UserInterface
179 * The called user entity.
181 public function activate();
186 * @return \Drupal\user\UserInterface
187 * The called user entity.
189 public function block();
192 * Returns the email that was used when the user was registered.
195 * Initial email address of the user.
197 public function getInitialEmail();
200 * Sets the existing plain text password.
202 * Required for validation when changing the password, name or email fields.
204 * @param string $password
205 * The existing plain text password of the user.
209 public function setExistingPassword($password);
212 * Checks the existing password if set.
214 * @param \Drupal\user\UserInterface $account_unchanged
215 * The unchanged user entity to compare against.
218 * TRUE if the correct existing password was provided.
220 * @see UserInterface::setExistingPassword()
222 public function checkExistingPassword(UserInterface $account_unchanged);