示例#1
0
def createUser(login_session):
    # First check if the user already has an account
    user_id = getUserID(login_session)
    # If the user already has an account, add (or re-add) the user's google or
    # facebook id, and then quit early so as not to create another user
    if user_id:
        user = User.query.filter_by(id=user_id).one()
        if login_session.get('facebook_id'):
            user.facebook_id = login_session['facebook_id'].encode('utf-8')
        if login_session.get('gplus_id'):
            user.gplus_id = login_session['gplus_id'].encode('utf-8')
        session.add(user)
        session.commit()
        return user_id
    # At this point the user doesn't have an account, so we create a new
    # account for the user
    new_user = User(
        name=login_session['username'].encode('utf-8'),
        email=login_session['email'].encode('utf-8'),
        picture=login_session['picture'].encode('utf-8'))

    if login_session.get('facebook_id'):
        new_user.facebook_id = login_session['facebook_id'].encode('utf-8')
    if login_session.get('gplus_id'):
        new_user.gplus_id = login_session['gplus_id'].encode('utf-8')

    session.add(new_user)
    session.commit()
    return getUserID(login_session)
示例#2
0
def createUser(login_session):
    # First check if the user already has an account
    user_id = getUserID(login_session)
    # If the user already has an account, add (or re-add) the user's google or
    # facebook id, and then quit early so as not to create another user
    if user_id:
        user = User.query.filter_by(id=user_id).one()
        if login_session.get('facebook_id'):
            user.facebook_id = login_session['facebook_id']
        if login_session.get('gplus_id'):
            user.gplus_id = login_session['gplus_id']
        session.add(user)
        session.commit()
        return user_id
    # At this point the user doesn't have an account, so we create a new
    # account for the user
    new_user = User(
        name=login_session['username'],
        email=login_session['email'],
        picture=login_session['picture'])

    if login_session.get('facebook_id'):
        new_user.facebook_id = login_session['facebook_id']
    if login_session.get('gplus_id'):
        new_user.gplus_id = login_session['gplus_id']

    session.add(new_user)
    session.commit()
    return getUserID(login_session)
示例#3
0
def createUser(login_session):
    newUser = User(name=login_session['username'],
                   email=login_session['email'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
示例#4
0
def add_user(login_session):
    user = User(
        userName=login_session['userName'],
        email=login_session['email'],
        img_user=login_session['img_user'])
    session.add(user)
    session.commit()
    return
示例#5
0
def createUser(login_session):
    """Create new user in DB"""

    newUser = User(user_name=login_session['username'],
                   user_email=login_session['email'],
                   user_picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(
        user_email=login_session['email']).one()
    return user.user_id
示例#6
0
def register():
    if (request.method == 'POST'):
        if (checkDuplicateUser(request.form['username'] == False)):
            newUser = User (
                username = request.form['username'],
                pwd = request.form['password']
            )
            session.add(newUser)
            session.commit()
            return redirect(url_for('login'))
        else:
            flash("This username has been used!")
            return render_template('register.html')
    else:
        return render_template('register.html')
def createUser(login_session):
    '''
    Create a new user in the database User
    input: login_session
    '''
    new_user = User(
        name=login_session["username"],
        email=login_session["email"],
        picture=login_session["picture"]
    )
    session.add(new_user)
    session.commit()
    user = session.query(
        User).filter_by(
            email=login_session["email"]).one()
    return user.id
示例#8
0
def signup():
    error = None
    if request.method == "post":
        passwd = request.form['passwd']
        repasswd = request.form['repasswd']
        email = request.form['email']
        users = session.query(User).all()
        for i in users:
            if i.email == email:
                error = "Pre registerd email"
                return render_template('signup.html', error)
        if passwd == repasswd:
            hash = hashedPassword(passwd)
            newUser = User(firstName=request.form['fname'],
                           lastName=request.form['lname'],
                           email=email,
                           password=hash)
            session.add(newUser)
            session.commit()
示例#9
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from databaseSetup import Category, Item, Base, User

#Database set up
engine = create_engine('sqlite:///catalogProject.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()
# Add Inital User
User1 = User(name="Me MySelf", email="*****@*****.**")
session.add(User1)
session.commit()

#Set up the intial categories array categories
categories = ["Mexican", "AsianFusion", "Southern", "Deli"]
Mexican = [
    [
        "Willy's Mexicana Grill",
        "Colorful taqueria chain serves up made-to-order burritos alongside other casual Mexican favorites."
    ],
    [
        "Tin Lizzy's Cantina",
        "Tacos, margarita pitchers & live music entertain a vibrant crowd in a laid-back cantina with patio."
    ]
]

AsianFusion = [
示例#10
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from databaseSetup import Categorys, Base, CatItems, User

# This code was from the Udacity course material but changed to
# to build out my example database.

engine = create_engine('sqlite:///waylandDatabase.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

User1 = User(name="Robert McMillen",
             email="*****@*****.**",
             picture="""https://pbs.twimg.com/profile_images/2671170543
    /18debd694829ed78203a5a36dd364160_400x400.png""")
session.add(User1)
session.commit()

pistolesCat = Categorys(user_id=1, name='Pistols')

session.add(pistolesCat)
session.commit()

item1 = CatItems(user_id=1,
                 name='Armat M4A3 Service Pistol',
                 description="""Based on the Colt M1911. The standard issue
    sidearm for the USCM. Holds 12 rounds. Offers greater
    accuracy and firepower than other pistols but at
    a reduced rate of fire.""",
                 categorys=pistolesCat)
示例#11
0
session.add(Category4)
session.commit()

Category5 = Category(name="Snowboarding")
session.add(Category5)
session.commit()

Category6 = Category(name="Rock Climbing")
session.add(Category6)
session.commit()

Category7 = Category(name="Skating")
session.add(Category7)
session.commit()

User1 = User(name="System", email="*****@*****.**")
session.add(User1)
session.commit()

ItemC1 = Item(name="Breakaway rim",
              description="A breakaway rim is a \
              basketball rim that contains a hinge \
              and a spring at the point",
              cat_id=Category1.id,
              user_id=User1.id)
session.add(ItemC1)
session.commit()

ItemC2 = Item(name="Shin Guard",
              description="A shin guard or shin pan is \
              a piece of equipment worn on the front of a \
示例#12
0
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Dummy User
user = User(name="Dummy", email="*****@*****.**")
session.add(user)
session.commit()

print("added user!")

# Category #1
category1 = CatalogCategory(name="Soccer", user_id=1)

session.add(category1)
session.commit()

# Category #2
category2 = CatalogCategory(name="Basketball", user_id=1)

session.add(category2)
示例#13
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from databaseSetup import Category, Item, User, Base

engine = create_engine('sqlite:///catalog.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

categories = [
    'Soccer', 'Basketball', 'Baseball', 'Frisbee', 'Snowboarding',
    'Rock Climbing', 'Foosball', 'Skating', 'Hockey', 'Table Tennis'
]
#creates user in order to assign an owner for all the items
newUser = User(name="Rohan Wadhwa", email="*****@*****.**")
session.add(newUser)
session.commit()
#adds all necessary categories in the database
for category in categories:
    newCategory = Category(name=category)
    session.add(newCategory)
    session.commit()

user = session.query(User).filter_by(email="*****@*****.**").one()
#adds category items for Soccer
category = session.query(Category).filter_by(name="Soccer").one()
session.add(Item(name="Soccer Ball", category=category, user=user))
session.add(
    Item(
        name="Soccer Cleats",
        category=category,
示例#14
0
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# add 2 users
user1 = User(userName="******", email="*****@*****.**")
session.add(user1)
session.commit()

print("added user 1!")

user2 = User(userName="******", email="*****@*****.**")
session.add(user2)
session.commit()

print("added user 2!")

# Category 1
category1 = Category(name="Soccer", user_id=1)

session.add(category1)