Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
def verify_password(username_or_token, password):
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    # Try to see if it's a token first
    user_id = User.verify_auth_token(username_or_token)
    if user_id:
        user = session.query(User).filter_by(id=user_id).one()
    else:
        user = session.query(User).filter_by(name=username_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
Beispiel #7
0
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')
Beispiel #8
0
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