caterva2.adduser#
- caterva2.adduser(newuser, password=None, superuser=False, urlbase=None, auth_cookie=None)#
Adds a user to the subscriber.
- Parameters:
newuser¶ (str) – Username of the user to add.
password¶ (str, optional) – Password for the user to add.
superuser¶ (bool, optional) – Indicates if the user is a superuser.
urlbase¶ (str, optional) – Base URL to query. Defaults to
caterva2.sub_urlbase_default
.auth_cookie¶ (str, optional) – HTTP cookie for authorization. Must be provided unless specified in a :py_obj:`caterva2.c2context`. The auth_cookie used must be from a superuser.
- Returns:
An explanatory message about the operation’s success or failure.
- Return type:
str
Examples
>>> import caterva2 as cat2 >>> import numpy as np >>> # To add a user you need to be a superuser >>> # This example is intended to work when the subscriber is running locally >>> super_user = {'username': 'superuser@example.com', 'password': 'foo'} >>> super_auth = cat2.get_auth_cookie(cat2.sub_urlbase_default, user_auth=super_user) >>> username = f'user{np.random.randint(0, 100)}@example.com' >>> message = cat2.adduser(username, 'foo', auth_cookie=super_auth) >>> f"User added: username='{username}' password='foo' superuser=False" == message True