Skip to content

Commit

Permalink
News-Like
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay9597 committed Apr 16, 2022
1 parent 635b103 commit a644320
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Binary file modified __pycache__/mongodbconfig.cpython-39.pyc
Binary file not shown.
21 changes: 20 additions & 1 deletion authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from flask import Flask, jsonify, request
from flask_jwt_extended import JWTManager, jwt_required, create_access_token
from pymongo import MongoClient
from requests import session
from bson.objectid import ObjectId

import mongodbconfig


client = pymongo.MongoClient(mongodbconfig.conn_str, serverSelectionTimeoutMS=5000)
print(client.server_info())
mydb = client["testdbnewsbuff"]
user = mydb["users"]
news = mydb["article"]

app = Flask(__name__)
jwt = JWTManager(app)
Expand All @@ -20,7 +24,9 @@
@app.route("/dashboard")
@jwt_required()
def dasboard():
return jsonify(message="Welcome! to Newsbuff")
if 'first_name' in session:
print('username',session['first_name'])
return jsonify(message="Welcome! to Newsbuff " + session['first_name'])


@app.route("/register", methods=["POST"])
Expand Down Expand Up @@ -56,5 +62,18 @@ def login():
return jsonify(message="Bad Email or Password"), 401


@app.route("/like", methods=["POST"])
@jwt_required()
def like():
newsid = request.form["newsid"]
test = news.find_one_and_update({"_id" : ObjectId(newsid)},{'$inc' : {'like' : 1}})
if test:
return jsonify(message="Like incremented"), 201
else:
return jsonify(message="Unable to increment like"), 401


return jsonify(message="Welcome! to Newsbuff")

if __name__ == '__main__':
app.run(host="localhost", debug=True)

0 comments on commit a644320

Please sign in to comment.