def external_auth(): oauth = FacebookSignIn() facebook_id, email, first_name, last_name = oauth.callback() if facebook_id is None: flash('Authentication failed') # change the status of async operation for 'error' status_error = AsyncOperationStatus.query.filter_by(code='error').first() # print "external auth" + session['async_operation_id'] async_operation = AsyncOperation.query.filter_by(id=session['async_operation_id']).first() print async_operation.id async_operation.async_operation_status_id = status_error.id db.session.add(async_operation) db.session.commit() return redirect(url_for('error')) # retrieve the user data from the database user = UserProfile.query.filter_by(facebook_id=facebook_id).first() # if the user is new, we store theirs credentials in user_profile table if not user: user = UserProfile(facebook_id=facebook_id, email=email, first_name=first_name, last_name=last_name) db.session.add(user) db.session.commit() # change the status of the async operation for 'ok' and insert the value of the user id # to the async_operation table status_ok = AsyncOperationStatus.query.filter_by(code='ok').first() async_operation = AsyncOperation.query.filter_by(id=session['async_operation_id']).first() async_operation.async_operation_status_id = status_ok.id async_operation.user_profile_id = user.id db.session.add(async_operation) db.session.commit()
def facebook_authorize(): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = FacebookSignIn() return oauth.authorize()