本文整理汇总了Python中oauth.OAuthSignIn类的典型用法代码示例。如果您正苦于以下问题:Python OAuthSignIn类的具体用法?Python OAuthSignIn怎么用?Python OAuthSignIn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuthSignIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oauth_callback
def oauth_callback():
try:
auth = OAuthSignIn(app)
return auth.callback()
except Exception as e:
print e
auth = OAuthSignIn(app)
session['username'] = auth.generateRandomUsername()
session['isAnonymous'] = True
return redirect(url_for('home'))
示例2: preauth
def preauth():
try:
print request.method
if(request.method == 'POST'):
scope_list = list(request.form)
auth_scope = 'user_read'
if(len(scope_list) > 0):
for i in range(0, len(scope_list)):
auth_scope += '+' + scope_list[i]
auth = OAuthSignIn(app)
return auth.authorize(auth_scope)
return render_template('preauth.jade', title = 'Pre Auth', UrlFor = url_for('preauth'))
except Exception as e:
print e
示例3: oauth_callback
def oauth_callback(provider):
if not current_user.is_anonymous:
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
username, email, picture, source = oauth.callback()
if email is None:
# I need a valid email address for my user identification
flash('Authentication failed.')
return redirect(url_for('index'))
# Look if the user already exists
user = session.query(User).filter_by(email=email).first()
if not user:
# Create the user. Try and use their name returned by Google,
# but if it is not set, split the email address at the @.
nickname = username
if nickname is None or nickname == "":
nickname = email.split('@')[0]
print "nickname: ", nickname
# We can do more work here to ensure a unique nickname, if you
# require that.
user = User(username=nickname, email=email,
picture=picture, user_source=source)
session.add(user)
session.commit()
# Log in the user, by default remembering them for their next visit
# unless they log out.
user.last_login_date = datetime.utcnow()
session.add(user)
session.commit()
login_user(user, remember=False)
return redirect(url_for('index'))
示例4: oauth_callback
def oauth_callback(provider):
if not current_user.is_anonymous:
return redirect(url_for("index"))
oauth = OAuthSignIn.get_provider(provider)
social_id, username, email = oauth.callback()
print ("llamada despues de callback")
print ("social_id " + social_id)
print ("username " + username)
print ("email " + email)
if social_id is None:
flash("Authentication failed.")
return redirect(url_for("index"))
user = User.query.filter_by(social_id=social_id).first()
if not user:
print ("no existia el usuario, lo persisto")
user = User(social_id=social_id, nickname=username, email=email)
db.session.add(user)
db.session.commit()
print ("usuario no logueado")
print (current_user.is_anonymous)
print (current_user.is_authenticated)
login_user(user, True)
print ("usuario logueado")
print ("current user" + str(current_user))
print str(user)
return redirect(url_for("index"))
示例5: oauth_callback
def oauth_callback(provider):
if not current_user.is_anonymous:
print("hello world")
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
return redirect(url_for('index'))
示例6: oauth_callback
def oauth_callback(provider):
# rand_pass will be a new password every time a user logs in
# with oauth.
temp_pass = str(uuid.uuid4())
# lets create the oauth object that will issue the request.
oauth = OAuthSignIn.get_provider(provider)
# assign the response
email, first_name, last_name = oauth.callback()
if email is None:
return unauthorized('Invalid credentials')
# see if this user already exists, and
# and give the user a brand new password.
user = User.query.filter_by(email=email).first()
if user:
user.password = temp_pass
# if there is no user, create a new one and setup
# it's defaults and give it a new password.
else:
user = User.insert_user(password=temp_pass,
username=email,
email=email,
first_name=first_name,
last_name=last_name)
return jsonify({'uuid': temp_pass, 'username': email})
示例7: oauth_callback
def oauth_callback(provider):
if not g.user.is_anonymous:
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
social_id, username, email = oauth.callback()
if social_id is None:
flash('Authentication failed.')
return redirect(url_for('index'))
if email is None:
flash('Authentication failed. User account requires valid email.\
Please sign up, or log in with a different account')
return redirect(url_for('index'))
user = User.query.filter_by(email=email).first()
if not user:
if username is None or username == "":
username = email.split('@')[0]
username = User.create_unique_username(username)
user = User(username=username, email=email)
db.session.add(user)
db.session.commit()
# make the user follow him/herself
db.session.add(user.follow(user))
db.session.commit()
login_user(user, True)
return redirect(url_for('profile'))
示例8: oauth_authorize
def oauth_authorize(provider):
print 'Entro nella function oauth_authorize'
if not current_user.is_anonymous():
return redirect(url_for('index'))
print 'sono anonimo'
oauth = OAuthSignIn.get_provider(provider)
return oauth.authorize()
示例9: oauth_callback
def oauth_callback(provider):
"""
Callback function for OAuth flow. The OAuth provider redirects back
to the application after the user authenticates and gives permission
to share information.
"""
if not current_user.is_anonymous:
return redirect(url_for('showGames'))
# Instantiate the OAuthSignIn provider
oauth = OAuthSignIn.get_provider(provider)
# Get the social_id, nickname and email from the provider
social_id, username, email = oauth.callback()
if social_id is None:
flash('Authentication failed.')
return redirect(url_for('showGames'))
# Query for a user with the social_id previously obtained
user = session.query(User).filter_by(social_id=social_id).first()
# If the previous query does not returns an user, create it and add it to
# the database
if not user:
user = User(social_id=social_id, nickname=username, email=email)
session.add(user)
session.commit()
login_user(user, True)
return redirect(url_for('showGames'))
示例10: oauth_callback
def oauth_callback(provider):
if not current_user.is_anonymous():
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
social_id, username, email,fullname,gender,timezone,image,locale,app_using_friends = oauth.callback()
#print image
if social_id is None:
flash('Authentication failed.')
return redirect(url_for('index'))
user = User.query.filter_by(social_id=social_id).first()
if not user:
user = User(social_id=social_id, nickname=username,username=fullname,email=email,gender=gender,timezone=timezone,image=image,country=locale)
db.session.add(user)
db.session.commit()
# add friends in graph node
for friend in app_using_friends:
friend_social_id = "facebook$"+friend['id']
friend_obj = User.query.filter_by(social_id=friend_social_id).first()
if friend_obj:
friend_id = friend_obj.id
is_friend = Graph_friends.query.filter_by(source_user_id=user.id,end_user_id=friend_id).first()
if not is_friend:
#add into the graph
add_node = Graph_friends(source_user_id=user.id,end_user_id=friend_id)
db.session.add(add_node)
db.session.commit()
login_user(user, True)
return redirect(url_for('index'))
示例11: oauth_authorize
def oauth_authorize(provider, state):
# Flask-Login function
if not current_user.is_anonymous:
return redirect(url_for('index'))
if state != app.config['SECRET_KEY']:
flash("Incorrect state parameter")
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
return oauth.authorize()
示例12: oauth_callback
def oauth_callback(provider):
oauth = OAuthSignIn.get_provider(provider)
oauth_session = oauth.callback()
res = oauth_session.get('username').json()
session['authenticated'] = True
session['username'] = res['username']
session['tgt'] = res['token']
return redirect(url_for('authenticated'))
示例13: oauth_authorize
def oauth_authorize(provider):
try:
if not current_user.is_anonymous():
return redirect(url_for('build_index'))
oauth = OAuthSignIn.get_provider(provider)
except Exception, e:
logger.error('some error happened: {0}'.format(e))
return redirect(url_for('build_index'))
示例14: recommend
def recommend():
try:
#if user is not logged in or does not have a random username assigned, then we should give them one
if((not 'username' in session) or session['username'] == '' or (not 'isAnonymous' in session)):
auth = OAuthSignIn(app)
session['username'] = auth.generateRandomUsername()
session['isAnonymous'] = True
_recommendations = twitchrecommender.generateRecommendationListForUser(session['username'], session['isAnonymous'])
twitchrecommender.storeFollowerRecommendations(session['username'],_recommendations)
session['rec_time_out'] = time.time() + 900
session['dir'] = 'up'
return redirect(url_for('recommendations', rank=1))
except Exception as e:
print e, 'B', sys.exc_traceback.tb_lineno
示例15: oauth_callback
def oauth_callback(provider):
oauth = OAuthSignIn.get_provider(provider)
social, username, email = oauth.callback()
if social is None:
flash('Authentication failed.')
return redirect(url_for('login'))
user = query_social_user(social);
session['social'] = social
if user is None:
insert_social_user(social)
return redirect('/')