Exemplo n.º 1
0
def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('simple_page.index'))

    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        flash(getttext(u'Authentication failed'), 'danger')
        return redirect(url_for('simple_page.index'))

    # check if user exists and if no creates new
    user = User.query.filter_by(social_id=social_id).first()
    if user is None:
        user = User(
            username=username,
            password='',
            email=email,
            social_id=social_id
        )
        db.session.add(user)
        db.session.commit()

    login_user(user, remember=True)
    user.update_login_info()
    return redirect(url_for('simple_page.index'))
Exemplo n.º 2
0
def oauth_callback(provider):
    next_url = request.args.get('next') or url_for('pages.index')
    if not g.user.is_anonymous:
        return redirect(url_for('pages.index'))
    oauth = OAuthSignIn.get_provider(provider)

    social_id, fname, lname, email = oauth.callback(next_url)

    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('pages.index'))

    try:
        user = Profile.objects.get(email=email)
    except Profile.DoesNotExist:
        user = None

    if not user:
        name = "%s %s" %(fname, lname)
        user = Profile(social_id=social_id, name=name, email=email,\
            created_at=datetime.datetime.now())
        user.save()

        emails.welcome_email(user.name, user.email)
    else:
        user.last_login = datetime.datetime.now()
        user.save()

    login_user(user, True)
    return redirect(next_url)
Exemplo n.º 3
0
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()
    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(username)
        user = User(social_id=social_id, nickname=username, email=email)
        db.session.add(user)
        db.session.commit()
        login_user(user, True)
        id = User.query.filter_by(social_id=social_id).first().id
        response = redirect(url_for('index'))
        response.set_cookie('user_id', value=bytes(str(id), 'utf-8'))
        response.set_cookie('new_user', value='')
        return response
    else:
        login_user(user, True)
        id = User.query.filter_by(social_id=social_id).first().id
        response = redirect(url_for('index'))
        response.set_cookie('user_id', value=bytes(str(id), 'utf-8'))
        return response
Exemplo n.º 4
0
def oauth_authorize(provider):
    if not g.user.is_anonymous:
        return redirect(url_for('pages.index'))

    next_url = request.args.get('next') or url_for('pages.index')
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize(next_url)
Exemplo n.º 5
0
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()
    if social_id is None:
        flash('Authentication failed.')
        return redirect('/')
    try:
        user = User.objects().get(social_id=social_id)
    except User.DoesNotExist:
        user = User(social_id=social_id, username=username, email=email)
        user.save()
    login_user(user, True)
    return redirect(url_for('index'))
Exemplo n.º 6
0
 def oauth_callback(self, provider):
     if not current_user.is_anonymous:
         return redirect(url_for('IndexView:get_0'))
     oauth = OAuthSignIn.get_provider(provider)
     social_id, email, name, picture = oauth.callback()
     if social_id is None:
         flash('Authentication failed.')
         return redirect(url_for('IndexView:get_0'))
     user = User.query.filter_by(social_id=social_id).first()
     if not user:
         user = User(social_id=social_id, full_name=name, email=email, picture=picture)
         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('IndexView:get_0'))
Exemplo n.º 7
0
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()
    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, email=email)
        db.session.add(user)
        for c in range(1, 100):
            cap = Cap(number=c, count=0, owner=user)
            db.session.add(cap)
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('index'))
Exemplo n.º 8
0
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()
    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(username)
        user = User(social_id=social_id, nickname=username, email=email)
        db.session.add(user)
        db.session.commit()
        login_user(user, True)
        return redirect(url_for('create_profile'))
    else:
        login_user(user, True)
        return redirect(url_for('index'))
Exemplo n.º 9
0
def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    social_id, nickname, email = oauth.callback()
    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:
        trusted = Trusted.query.filter_by(email=email).first()
        if trusted:
            nickname = User.make_unique_nickname(nickname)
            user = User(social_id=social_id, nickname=nickname, email=email)
            db.session.add(user)
            db.session.commit()
        else:
            flash("Oops, Seems like you are not in the file. Please, contact the site administration.")
            return redirect(url_for('index'))
    login_user(user, True)
    return redirect(url_for('user', nickname=g.user.nickname))
Exemplo n.º 10
0
def oauth_authorize(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('simple_page.index'))

    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
Exemplo n.º 11
0
 def oauth_authorize(self, provider):
     if g.user is not None and g.user.is_authenticated:
         return redirect(url_for('IndexView:get_0'))
     oauth = OAuthSignIn.get_provider(provider)
     return oauth.authorize()
Exemplo n.º 12
0
def oauth_authorize(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()