def follow(user_id): if request.method == "POST": auth = request.headers.get('Authorization', None) parts = auth.split() if parts[0].lower() == 'bearer': token = parts[1] followID = jwt.decode(token, 'app.config[SECRET_KEY]') follow = Follows(user_id=int(user_id), follower_id=int(followID['user_Id'])) db.session.add(follow) db.session.commit() user = Users.query.filter_by(id=int(user_id)).first() posts = Post.query.filter_by(user_id=int(user_id)).count() follows = Follows.query.filter_by(user_id=int(user_id)).count() d = {} d['uid'] = user.id d['pphoto'] = user.profile_photo d['fname'] = user.firstname d['lname'] = user.lastname d['location'] = user.location d['bio'] = user.biography d['date'] = user.joined_on d['posts'] = posts d['follows'] = follows return jsonify(d=d) return jsonify({"Follow": "failed"})
def following(user_id): if request.method == "POST": try: id = current_user.id follow = Follows(id, user_id) db.session.add(follow) db.session.commit() #Flash message to indicate a successful following success = "You are now following that user" return jsonify(message=success), 201 except Exception as e: print(e) #Flash message to indicate that an error occurred failure = "Internal error. Failed to follow user" return jsonify(error=failure), 401 else: try: followers = db.session.query(Follows).filter_by( user_id=user_id).all() return jsonify(followers=len(followers)), 201 except Exception as e: print(e) error = "Internal server error!" return jsonify(error=error), 401
def follow(user_id): follower_id = g.current_user['user_id'] follow = Follows(user_id=int(user_id),follower_id=int(follower_id)) db.session.add(follow) db.session.commit() return jsonify({'message':'sucess'})
def followuser(user_id): token = request.headers['Authorization'].split()[1] current_id = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])['id'] follow = Follows(current_id, user_id) db.session.add(follow) db.session.commit() followcount = Follows.query.filter_by(follower_id=user_id).count() return jsonify({"message": "followed user"}), 201
def following(user_id): if current_user.is_authenticated(): id = current_user.id follow = Follows(id, user_id) db.session.add(follow) db.session.commit() #Flash message to indicate a successful following success = "You are now following that user" return jsonify(message=success), 201 #Flash message to indicate that an error occurred failure = "Failed to follow user" return jsonify(error=failure)
def follow(user_id): followerID = current_user.id print(followerID==int(user_id)) if followerID != int(user_id): if Follows.query.filter_by(user_id=user_id,follower_id=followerID).first() is None: newFollow = Follows(user_id,followerID) db.session.add(newFollow) db.session.commit() return jsonify(follow = "New Follower of " + user_id) else: return jsonify(follow = "You are already a follower of this user!") else: return jsonify(follow = "You Cannot Follow Yourself!")
def follow(user_id): findFollow = Follows.query.filter_by(user_id=user_id, follower_id=current_user.id).first() if findFollow is None: follow = Follows(user_id=user_id, follower_id=current_user.id) db.session.add(follow) db.session.commit() succesMessage = {"message": "You are now following this user"} return jsonify(succesMessage=succesMessage) else: Follows.query.filter_by(user_id=user_id, follower_id=current_user.id).delete() db.session.commit() succesMessage = {"message": "You are no longer following this user"} return jsonify(succesMessage=succesMessage)
def follow(userid): following = FollowForm() #print("inside") if request.method == "POST": following.following.data = request.form['following'] if following.validate_on_submit(): followid = following.following.data #print("User to follow: ", followerid) #print("Current user: "******"pass") followDB = Follows(followid, userid) db.session.add(followDB) db.session.commit() return jsonify(message="success") print("failed") return jsonify(message="failed")
def follow(user_id): """ Follow a user""" user = UserProfile.query.filter_by(id=user_id).first() if request.method == 'POST': follow = Follows(user_id, session['current_user']) db.session.add(follow) db.session.commit follows = len(Follows.query.filter_by(user_id=user_id).all()) msg = { "message": "You are now following that user.", "followers": follows } return jsonify(msg) return jsonify(["Bad Request"])
def follow(user_id): request_payload = request.get_json() query = Follows.query.filter_by( user_id=request_payload['user_id'], follower_id=request_payload['follower_id']).first() if query is not None: info = [{'message': "You are not following that user"}] return jsonify(info=info) follow = Follows(request_payload['user_id'], request_payload['follower_id']) db.session.add(follow) db.session.commit() return jsonify(message="You are now following that user.")
def follow(user_id): form = FollowsForm() if form.validate_on_submit: try: follower_id = form.follower_id.data follow = Follows(user_id, follower_id) db.session.add(follow) db.session.commit() #Flash message for a successfully following response = "You are now following this user" return jsonify(message=response), 200 except Exception as e: print(e) #Flash message to indicate that an error occurred response = "An error as occurred." return jsonify(error=response), 400
def follow(user_id): if request.method == "POST": class Form(FlaskForm): follower_id= HiddenField(None,validators=[InputRequired()]) form=Form() followerid=request.form["followerid"] followmessage = [ { "message": "You are now following that user." }] follows = Follows(user_id=user_id, follower_id=followerid) db.session.add(follows) db.session.commit() return jsonify(follow=followmessage) else: followsList=Follows.query.filter_by(user_id=user_id).all() followerList=[follow.follower_id for follow in followsList] if len(followerList)==0: num_followers = [{"followers":0},{"followerList":followerList}] else: num_followers = [{"followers": len(followerList)},{"followerList":followerList}] return jsonify(follow=num_followers)
def follow_user(user_id): """Saves the user you are following""" follow = Follows(user_id=user_id, followID=session['userid']) db.session.add(follow) db.session.commit() return jsonify(message='You are now following this user')