def add_new_user_facebook(**kwargs): fullname = kwargs['name'] names = fullname.split(' ') first_name = None last_name = None if len(names) >= 1: first_name = names[0] if len(names) >= 2: last_name = names[1] facebook_id = kwargs['id'] session = DBSession() user = session.query(User).filter_by(facebook_id=facebook_id).first() if user: return user new_user = User(firstname=first_name, lastname=last_name, facebook_id=facebook_id) session.add(new_user) try: session.commit() except Exception as e: # Log Exception here session.rollback() return None return new_user
def createUser(login_session): newUser = User( name=login_session['username'], email=login_session['email'], photo=login_session['picture']) session.add(newUser) session.commit() user = session.query(User).filter_by(email=login_session['email']).one() return user.id
def createUser(login_session): DBSession = sessionmaker(bind=engine) session = DBSession() newUser = User(name=login_session['username'], email=login_session['email'], picture=login_session['picture']) session.add(newUser) session.commit() user = session.query(User).filter_by(email=login_session['email']).one() return user.id
def new_user(): DBSession = sessionmaker(bind=engine) session = DBSession() username = request.json.get('username') password = request.json.get('password') if username is None or password is None: print("missing arguments") abort(400) if session.query(User).filter_by(name=username).first() is not None: print("existing user") user = session.query(User).filter_by(name=username).first() return jsonify({'message': 'user already exists'}), 200 # , {'Location': url_for('get_user', id = user.id, _external = True)} user = User(name=username) user.hash_password(password) session.add(user) session.commit() return jsonify({'username': user.name}), 201
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')
def createUser(login_session): newUser = User(name=login_session['username']) session.add(newUser) session.commit() user = session.query(User).filter_by(name=login_session['username']).one() return user.id