def connect(): flow = flow_from_clientsecrets( '/home/ubuntu/udacity-linux-configuration/client_secrets.json', scope=scope, redirect_uri=url_for('connect', _external=True)) # exchange the token for credentials try: code = request.args.get('code') if code is not None: credentials = flow.step2_exchange(code) else: return "access was denied" except FlowExchangeError: return "failed to aqcuire authorization" # use the credentials to get the users information # and store it in the login_session userinfo_url = "https://www.googleapis.com/oauth2/v2/userinfo" params = {'access_token': credentials.access_token} answer = requests.get(userinfo_url, params=params) data = answer.json() login_session['name'] = data['name'] login_session['picture'] = data['picture'] login_session['email'] = data['email'] login_session['access_token'] = credentials.access_token if session.query(User).filter_by( email=login_session['email']).count() == 0: newUser = User(email=login_session['email'], name=login_session['name'], picture=login_session['picture']) session.add(newUser) session.commit() flash('logged in as ' + login_session['name']) return redirect(url_for('showCategory'))
def createUser(login_session): 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(): 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(username=username).first() is not None: print "existing user" user = session.query(User).filter_by(username=username).first() return jsonify({'message': 'user already exists'}), 200 user = User(username=username) user.hash_password(password) session.add(user) session.commit() return jsonify({'username': user.username}), 201
def createUser(login_session): ''' Create an user in the database''' newUser = User(username=login_session['username'], email=login_session['email'], picture=login_session['picture'], provider=login_session['provider']) session.add(newUser) session.commit() user = session.query(User).filter_by(email=login_session['email']).one() return user.id
def createUser(login_session): ''' This function creates a User in the database along with its attributes (Name,Email,Picture) ''' 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 verify_password(username_or_token, password): #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( username=username_or_token).first() if not user or not user.verify_password(password): return False g.user = user return True
from catalog_database import User, Category, Item engine = create_engine('sqlite:///Catalog.db') DBSession = sessionmaker(bind=engine) session = DBSession() ############################################################################### # Create user system ############################################################################### user_sys = User( username="******", email="*****@*****.**", origin="Internal", password_hash="SecretPassword123!@#") session.add(user_sys) session.add session.commit() user = session.query(User).filter_by(email="*****@*****.**").one() ############################################################################### # Create 7 categories and log it ############################################################################### for cat in ["Soccer", "BasketBall", "Baseball", "Frisbee", "Snowboarding", "Rock Climbing", "Foosball", "Skating", "Hockey"]: categoryN = Category(name=cat)
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() # Create dummy user User1 = User( name="Hana Shamatah", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) session.add(User1) session.commit() # Menu for UrbanBurger categories1 = Categories(user_id=1, name="hair") session.add(categories1) session.commit() catalogItem1 = CatalogItem(user_id=1, category_name="hair", name="Accessories", description="prety blond hair")
#!/usr/bin/python2.7 from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from catalog_database import Base, Item, Item_adds, User engine = create_engine('sqlite:///catalog.db') DBsession = sessionmaker(bind=engine) session = DBsession() # master user right now User1 = User(name="Evan Schoening", email="*****@*****.**", picture="none") session.add(User1) session.commit() # User1 for testing Item1 = Item(user_id=1, item_name="bicycle", description="A bicycle for riding, kind of broken") session.add(Item1) session.commit() Item1_add = Item_adds(user_id=1, item_add_name="Wheel",
# 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() # Create dummy user User1 = User(name='John Smith', email='*****@*****.**', picture='This is his picture') session.add(User1) session.commit() # Create dummy categories Category1 = Category(name='Soccer') session.add(Category1) session.commit() Category2 = Category(name='Basketball') session.add(Category2) session.commit() Category3 = Category(name='Baseball') session.add(Category3)
from sqlalchemy.orm import sessionmaker from catalog_database import Base, Sport, Jersey, User engine = create_engine('sqlite:///sportscatalog.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() # User list user1 = User( name="Chris Jeon", email="*****@*****.**", picture= 'http://perfectfitcomputers.ca/wp-content/uploads/2014/08/aviato-logo.jpg') session.add(user1) session.commit() user2 = User( name="Richard Hendriks", email="*****@*****.**", picture= 'https://ih0.redbubble.net/image.222702072.4474/flat,800x800,075,f.jpg') session.add(user2) session.commit() # Catalog for Soccer sport1 = Sport(name="Soccer")
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from catalog_database import Base, ActivityCategory, ActivityItem, User engine = create_engine('sqlite:///activitiescatalogwithuser.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create dummy user user1 = User( name="Robo Barista", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) session.add(user1) session.commit() # Create categories category1 = ActivityCategory(name='Family') session.add(category1) session.commit() # Create items for category 1 item1 = ActivityItem( name='5Wits', description= """5 Wits adventures are cutting-edge, live-action entertainment venues that