Пример #1
0
    def obj_create(self, bundle, **kwargs):
        # get the API key associated with the request
        apikey = api.auth.DatabaseAuthentication().get_identifier(
            bundle.request)

        # try and get an existing user
        try:
            bundle.obj = User.objects.get(email=bundle.data['email'])
        # no existing user, create them
        except User.DoesNotExist as e:
            if 'password' not in bundle.data:
                kwargs['password'] = User.generate_password(
                    api.auth.get_nonce(32))

            bundle = super(UserResource, self).obj_create(bundle, **kwargs)

        # create a new account entry
        account = Account()
        account.api_account = apikey.account  # set the api key's account as the creator
        account.save()

        # add the user as an admin to the new account
        accountuser = AccountUser(account=account,
                                  user=bundle.obj,
                                  is_admin=True)
        accountuser.save()

        return bundle
Пример #2
0
    def obj_create(self, bundle, **kwargs):
        bundle = super(UserResource, self).obj_create(bundle, **kwargs)

        # create a new account entry and set the new user as the admin
        account = Account()
        account.save()

        # add the user as an admin to the new account
        accountuser = AccountUser(account=account,
                                  user=bundle.obj,
                                  is_admin=True)
        accountuser.save()

        return bundle