示例#1
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    me_dict = oauth.callback()
    email = me_dict['email']

    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 = User.get_or_create(db.session, id=email)
    user.first_name = me_dict['given_name']
    user.family_name = me_dict['family_name']
    user.email = me_dict['email']
    user.picture = me_dict['picture']
    user.name = me_dict['name']
    db.session.commit()

    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    login_user(user, remember=True)
    return redirect(url_for('index'))
示例#2
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email, picture = 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]
        # We can do more work here to ensure a unique nickname, if you 
        # require that.
        user=User(nickname=nickname, email=email, picture=picture)
        session.add(user)
        session.commit()
    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    if picture != user.picture:
    	user.picture = picture
    	session.add(user)
    	session.commit()
    login_user(user, remember=True)
    return redirect(url_for('index'))
示例#3
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = 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 = User.query.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]

        # We can do more work here to ensure a unique nickname, if you
        # require that.
        user = User(nickname=nickname, email=email)
        db.session.add(user)
        db.session.commit()
    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    login_user(user, remember=True)
    return redirect(url_for('index'))
示例#4
0
文件: views.py 项目: aasoliz/Tree
def oauth_authorize(provider):
  # User is already logged in
  if not current_user.is_anonymous():
    return redirect(url_for('index'))

  oauth = OAuthSignIn.get_provider(provider)
  return oauth.authorize()
示例#5
0
def oauth_callback(provider="google"):
    global token
    if token:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    email, oauth_token = oauth.callback()
    api = todoist.TodoistAPI()
    token = api.login_with_google(email, oauth_token)["token"]
    return redirect(url_for('index'))
示例#6
0
def oauth_callback(provider):
    print('---------------', current_user)
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = oauth.callback()

    if email is None:
        print('Authentication failed.')
        return redirect(url_for('index'))

    user = User.find_or_create_by_email(email)
    login_user(user, remember=True)
    return redirect(url_for('index'))
def oauth_callback(provider):
    """The callback function for the OAuth provider"""
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = oauth.callback()
    if email is None:
        flash('Authorization failed.')
        return redirect(url_for('index'))
    user = User.query.filter_by(username=username, email=email).first()
    if not user:
        user = User(username=username, email=email, password='', is_oauth2=True)
        db.session.add(user)
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('index'))
示例#8
0
文件: views.py 项目: aasoliz/Tree
def oauth_callback(provider):
  # User is already logged in
  if not current_user.is_anonymous():
    return redirect(url_for('index'))
  
  oauth = OAuthSignIn.get_provider(provider)
  
  # Get returned Username and Email if successful
  username, email = oauth.callback()

  # There was no email
  if email is None:
    flash('Authentication failed.')
    return redirect(url_for('index'))

  # Get user from database
  user = User.query.filter_by(email=email).first()

  # User was not in database
  if not user:
    nickname = username

    # Try getting username from email
    if nickname is None or nickname == "":
      nickname = email.split('@')[0]

    # Create user
    user = User(nickname=nickname, email=email)
    
    # Add user to database
    db.session.add(user)
    db.session.commit()

    # Make user follow themselves
    u = user.follow(user)
    db.session.add(u)
    db.session.commit()

  # Login user
  login_user(user, remember=True)

  # Set last seen to time they login
  user.last_seen = datetime.now()
  db.session.add(user)
  db.session.commit()

  return redirect(url_for('index'))
示例#9
0
def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = 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 = User.find_or_create_by_email(email)

    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    login_user(user, remember=True)
    return redirect(url_for('index'))
示例#10
0
def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = 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 = User.find_or_create_by_email(email)

    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    login_user(user, remember=True)
    return redirect(url_for('index'))
示例#11
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    # print oauth.callback()
    username, email = oauth.callback()
    if email is None:
        flash('Authentication failed')
        return redirect(url_for('index'))
    user = User.query.filter_by(email=email).first()
    if not user:
        nickname = username
        if nickname is None or nickname == "":
            nickname = email.split('@')[0]
        user = User(nickname=nickname, email=email)
        db.session.add(user)
        db.session.commit()
    login_user(user, remember=True)
    return redirect(url_for('edit'))
示例#12
0
def oauth_authorize(provider):
    # Flask-Login function
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
def oauth_authorize(provider):
    """Authorize a user with the given provider"""
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
示例#14
0
def oauth_authorize(provider):
    # Flask-Login function
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
示例#15
0
def oauth_authorize(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
示例#16
0
def oauth_authorize(provider="google"):
    if token:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()