def add_new_user(**kwargs): ''' kwargs must match the User Schema. ''' session = DBSession() new_user = User(username=kwargs['username'], firstname=kwargs['firstname'], lastname=kwargs['lastname'], email=kwargs['email']) new_user.set_password(kwargs['password']) session.add(new_user) try: session.commit() except Exception as e: # Log Exception here return None return new_user
def insert_users(): """ 'username': '******', 'firstname': 'Michael', 'lastname': 'Jackson', 'email': '*****@*****.**', 'id': 1, 'password': '******', """ try: for user in users: # print('user: {}'.format(user)) u = User(username=user['username'], firstname=user['firstname'], lastname=user['lastname'], email=user['email'], id=user['id']) u.set_password(user['password']) session.add(u) session.commit() except: sys.exit('Error inserting users')