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
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
def create_account(session): account = Account(first_name=names.get_first_name(), last_name=names.get_last_name()) session.add(account) password_generator = PasswordGenerator() authentication = Authentication(account=account, login='******'.format( account.first_name, account.last_name).lower(), password=password_generator.generate()) session.add(authentication) session.commit() return account