def create(self, request): """Create a MAAS user account. This is not safe: the password is sent in plaintext. Avoid it for production, unless you are confident that you can prevent eavesdroppers from observing the request. :param username: Identifier-style username for the new user. :type username: unicode :param email: Email address for the new user. :type email: unicode :param password: Password for the new user. :type password: unicode :param is_superuser: Whether the new user is to be an administrator. :type is_superuser: bool ('0' for False, '1' for True) Returns 400 if any mandatory parameters are missing. """ username = get_mandatory_param(request.data, 'username') email = get_mandatory_param(request.data, 'email') password = get_mandatory_param(request.data, 'password') is_superuser = extract_bool( get_mandatory_param(request.data, 'is_superuser')) if is_superuser: return User.objects.create_superuser(username=username, password=password, email=email) else: return User.objects.create_user(username=username, password=password, email=email)
def create(self, request): """@description-title Create a MAAS user account @description Creates a MAAS user account. This is not safe: the password is sent in plaintext. Avoid it for production, unless you are confident that you can prevent eavesdroppers from observing the request. @param (string) "username" [required=true] Identifier-style username for the new user. @param (string) "email" [required=true] Email address for the new user. @param (string) "password" [required=true] Password for the new user. @param (boolean) "is_superuser" [required=true] Whether the new user is to be an administrator. ('0' == False, '1' == True) @success (http-status-code) "200" 200 @success (json) "success-json" A JSON object containing information about the new user. @success-example "success-json" [exkey=create] placeholder text @error (http-status-code) "400" 400 @error (content) "error-content" Mandatory parameters are missing. @error-example "error-content" No provided username! """ username = get_mandatory_param(request.data, "username") email = get_mandatory_param(request.data, "email") if request.external_auth_info: password = request.data.get("password") else: password = get_mandatory_param(request.data, "password") is_superuser = extract_bool( get_mandatory_param(request.data, "is_superuser")) create_audit_event( EVENT_TYPES.AUTHORISATION, ENDPOINT.API, request, None, description=("Created %s '%s'." % ("admin" if is_superuser else "user", username)), ) if is_superuser: user = User.objects.create_superuser(username=username, password=password, email=email) if request.data.get("key") is not None: request.user = user sshkeys_handler = SSHKeysHandler() sshkeys_handler.create(request) return user else: return User.objects.create_user(username=username, password=password, email=email)
def create(self, request): """Create a MAAS user account. This is not safe: the password is sent in plaintext. Avoid it for production, unless you are confident that you can prevent eavesdroppers from observing the request. :param username: Identifier-style username for the new user. :type username: unicode :param email: Email address for the new user. :type email: unicode :param password: Password for the new user. :type password: unicode :param is_superuser: Whether the new user is to be an administrator. :type is_superuser: bool ('0' for False, '1' for True) Returns 400 if any mandatory parameters are missing. """ username = get_mandatory_param(request.data, 'username') email = get_mandatory_param(request.data, 'email') if request.external_auth_info: password = request.data.get('password') else: password = get_mandatory_param(request.data, 'password') is_superuser = extract_bool( get_mandatory_param(request.data, 'is_superuser')) create_audit_event( EVENT_TYPES.AUTHORISATION, ENDPOINT.API, request, None, description=("Created %s '%s'." % ('admin' if is_superuser else 'user', username))) if is_superuser: user = User.objects.create_superuser(username=username, password=password, email=email) if request.data.get('key') is not None: request.user = user sshkeys_handler = SSHKeysHandler() sshkeys_handler.create(request) return user else: return User.objects.create_user(username=username, password=password, email=email)
def test_1_means_True(self): self.assertEqual(extract_bool("1"), True)
def test_0_means_False(self): self.assertEqual(extract_bool("0"), False)