| @@ 173-184 (lines=12) @@ | ||
| 170 | * |
|
| 171 | * @return bool true if role was added, false if user already had the role |
|
| 172 | */ |
|
| 173 | public function addRole($username, $role) |
|
| 174 | { |
|
| 175 | $user = $this->findUserByUsernameOrThrowException($username); |
|
| 176 | if ($user->hasRole($role)) { |
|
| 177 | return false; |
|
| 178 | } |
|
| 179 | ||
| 180 | $user->addRole($role); |
|
| 181 | $this->userManager->updateUser($user); |
|
| 182 | ||
| 183 | return true; |
|
| 184 | } |
|
| 185 | ||
| 186 | /** |
|
| 187 | * Removes role from the given user. |
|
| @@ 194-205 (lines=12) @@ | ||
| 191 | * |
|
| 192 | * @return bool true if role was removed, false if user didn't have the role |
|
| 193 | */ |
|
| 194 | public function removeRole($username, $role) |
|
| 195 | { |
|
| 196 | $user = $this->findUserByUsernameOrThrowException($username); |
|
| 197 | if (!$user->hasRole($role)) { |
|
| 198 | return false; |
|
| 199 | } |
|
| 200 | ||
| 201 | $user->removeRole($role); |
|
| 202 | $this->userManager->updateUser($user); |
|
| 203 | ||
| 204 | return true; |
|
| 205 | } |
|
| 206 | ||
| 207 | /** |
|
| 208 | * Finds a user by his username and throws an exception if we can't find it. |
|