Creates a new account with the given name and password. Args: username: (str) password: (str) role: (Role) Raises: db.users.UserAlreadyExistsError: If a user with the given username already exists on the system. OneAdminRequiredError
(username, password, role)
| 82 | |
| 83 | |
| 84 | def register(username, password, role): |
| 85 | """Creates a new account with the given name and password. |
| 86 | |
| 87 | Args: |
| 88 | username: (str) |
| 89 | password: (str) |
| 90 | role: (Role) |
| 91 | |
| 92 | Raises: |
| 93 | db.users.UserAlreadyExistsError: If a user with the given username |
| 94 | already exists on the system. |
| 95 | OneAdminRequiredError |
| 96 | """ |
| 97 | if len(get_all_accounts()) == 0 and role != Role.ADMIN: |
| 98 | raise OneAdminRequiredError( |
| 99 | 'The very first user account on the system must have admin role.') |
| 100 | |
| 101 | logger.info_sensitive('Adding user %s with role %s', username, role) |
| 102 | db.users.Users().add(username=username, |
| 103 | password_hash=password_check.generate_hash(password), |
| 104 | credentials_change_time=utc.now(), |
| 105 | role=role) |
| 106 | logger.info_sensitive('Created user %s with role %s', username, role) |
| 107 | video_service.restart() |
| 108 | |
| 109 | |
| 110 | def change_password(username, new_password): |
nothing calls this directly
no test coverage detected