Beispiel #1
0
def follow_action(user_id, action):
    user = User.query.filter_by(id=user_id).first_or_404()
    if action == 'follow':
        current_user.follow_user(user)
        db.session.commit()
    if action == 'unfollow':
        current_user.unfollow_user(user)
        db.session.commit()
    return redirect(request.referrer)
Beispiel #2
0
def handle_my_custom_fevent( json ):
    user = User.query.filter_by(id=json.get('user_id')).first_or_404()
    if json.get('action') == 'follow':
        current_user.follow_user(user.id)
        db.session.commit()
    if json.get('action') == 'unfollow':
        current_user.unfollow_user(user.id)
        db.session.commit()
    print( str( json ))
    socketio.emit( 'my fresponse', json, callback=messageRecived )
Beispiel #3
0
def follow(username):
    user = User.query.filter_by(username=username).first_or_404()
    if user is None:
        flash('sorry no user found')
        return redirect(url_for('home.main'))
    if user == current_user:
        flash('sorry you can\'t follow your self')
        return redirect(url_for('user.timeline', username=username))
    current_user.follow_user(user)
    db.session.commit()
    return redirect(url_for('user.timeline', username=username))
Beispiel #4
0
def follow_user(id):
    """关注用户
    @id, 被关注用户的id
    """
    user = User.query.get_or_404(id)
    current_user.follow_user(user)

    # 推送消息给被关注用户
    notification = Notification(fuser_id=current_user.id,
                                tuser_id=id,
                                action='follow_user')
    db.session.add(notification)
    db.session.commit()
    return redirect(request.referrer)
Beispiel #5
0
def follow():
    """
        Follow a user
    """

    req = request.get_json()
    username = req['user']

    if username == current_user.username:
        flash('Cannot follow yourself')
        return ('', 403)

    is_following = current_user.following_user(username)

    if is_following:
        current_user.stop_following_user(username)
    else:
        current_user.follow_user(username)

    return jsonify(follow=True)
Beispiel #6
0
def follow(username):
    if not username and len(username) > 36:
        flash("User Not Found!")
        return redirect('/', 302)

    if current_user.is_authenticated:
        user = User.get_user_info(username=username)
        if user and current_user.follow_user(user):
            return redirect(f'/player/{username}')
        flash("User Not Found!")
        return redirect('/', 302)
    flash('Please Login before this action!')
    return redirect('/', 302)
def follow_user(username):
    person = Person.query.filter_by(username=username).first()

    if person is None:
        log = Log('User not found within the database')
        interceptor_manager.execute(log)
        raise Exception

    if person == current_user:
        log = Log('You cannot follow yourself')
        interceptor_manager.execute(log)
        raise Exception

    current_user.follow_user(person)
    db.session.commit()

    log = Log('You are now following {}.'.format(username))
    interceptor_manager.execute(log)

    mediator = Mediator()
    mediator.notify_user(username=session['username'], email=person.email)

    return redirect(url_for('viewpost', username=username))
Beispiel #8
0
def follow_user(user_id):
    user = User.query.filter_by(id=user_id).first()
    current_user.follow_user(user)
    db.session.commit()
    return jsonify({'status': 'success'})