From ff51fbbba5bb6cf05e642451b9bc90d6865913f6 Mon Sep 17 00:00:00 2001 From: Trulydev50 <76103867+Trulydev50@users.noreply.github.com> Date: Wed, 27 Oct 2021 21:55:24 +0800 Subject: [PATCH 1/5] done --- main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index fc7fbd4..cf5dc03 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,12 @@ # Write your flask code here app = Flask(__name__) - +app.config['SECRET_KEY'] = AUTH_SECRET_KEY app.register_blueprint(profiles_api, url_prefix="/profiles") app.register_blueprint(auth_api, url_prefix="/auth") + +@app.route("/", methods = ["GET"]) +def hello(): + return "halo" +if __name__== "main": + app.run("localhost", port=8080) \ No newline at end of file From d39ed9de11df3182a8580a6d70727056aff65ed8 Mon Sep 17 00:00:00 2001 From: Trulydev50 <76103867+Trulydev50@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:38:57 +0800 Subject: [PATCH 2/5] editted --- Profiles/ProfilesAPI.py | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/Profiles/ProfilesAPI.py b/Profiles/ProfilesAPI.py index 4467047..a22075d 100644 --- a/Profiles/ProfilesAPI.py +++ b/Profiles/ProfilesAPI.py @@ -1,7 +1,56 @@ # Profile API here -from flask import Blueprint +from flask import Blueprint, request, jsonify import sys from db import db sys.path.append("../") -profiles_api = Blueprint("profiles", __name__) +profiles_api = Blueprint("profiles", name) + +@profiles_api.route('//', methods = ["GET"]) +def retrieve(id): + if id > len(db)-1: + return jsonify({"Status" : "Error", "Message" : "Don't have"}) + + else: + dets = db[id] + return jsonify({"Status" : "Success", "Details" : dets}) + +@profiles_api.route('/', methods = ["POST"])#wont work on googlechrome only on postman,check on postman +def postid(): + newprofile = {} + newprofname = request.form.get('name') + newprofile["name"] = newprofname + + db.append(newprofile) + + return jsonify({"Status" : "Success", "Details" : newprofile}) + + +@profiles_api.route('//', methods = ["DELETE"]) +def deleteid(id): + if id > len(db)-1: + return jsonify({"Status" : "Error", "Message" : "No such ID"}) + + else: + deleted = db[id] + del db[id] + + return jsonify({"Status" : "Success", "New db" : db, "Deleted profile" : deleted}) + + +@profiles_api.route('//score', methods = ["GET"]) +def getabovemin(id): + if id > len(db)-1: + return jsonify({"Status" : "Error", "Message" : "No such ID"}) + + minscore = request.args.get('minScore') + scores = db[id]["scores"] + + if minscore == '': + return jsonify({"Status" : "Success", "Details" : scores}) + + abovemin = list(filter(lambda score: score > int(minscore), scores))#use assig + + + return jsonify({"Status" : "Success", "Details" : abovemin}) + From 2368f3c89265e2ae74aa48d189b71269a51e0fc2 Mon Sep 17 00:00:00 2001 From: Trulydev50 <76103867+Trulydev50@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:41:22 +0800 Subject: [PATCH 3/5] editted --- db.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db.py b/db.py index 777200b..50f9713 100644 --- a/db.py +++ b/db.py @@ -9,3 +9,6 @@ "name": "Hui Hui", "scores": [9, 29, 34] }] +cred = [{"username" : "Dev", "passwordHash" : "12345"}] + +AUTH_SECRET_KEY = 'key1' \ No newline at end of file From 5beb586af584abca899ea9ebed01b456d08f2f4a Mon Sep 17 00:00:00 2001 From: Trulydev50 <76103867+Trulydev50@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:59:07 +0800 Subject: [PATCH 4/5] edit --- Auth/AuthAPI.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Auth/AuthAPI.py b/Auth/AuthAPI.py index b903496..c140476 100644 --- a/Auth/AuthAPI.py +++ b/Auth/AuthAPI.py @@ -1,7 +1,48 @@ # Score API here -from flask import Blueprint +from flask import Blueprint, request, jsonify, current_app import sys -from db import db +from db import db, cred +import jwt sys.path.append("../") auth_api = Blueprint("auth", __name__) +@auth_api.route('/register', methods = ["POST"]) +def reg(): + + def regdet(argsform): + username = argsform.get('username') + hashedPassword = argsform.get('passwordHash') + + if (username == '') or (hashedPassword == ''): + return jsonify({"Status" : "Failed", "Message" : "Username or Password not available"}) + else: + cred.append({"username" : username, "passwordHash" : hashedPassword}) + return jsonify({"Status" : "Success", "Message" : "Registered"}) + + if request.args.get('username'): + return regdet(request.args) + + elif request.form.get('username'): + return regdet(request.form) + +@auth_api.route('/login', methods = ["POST"]) +def login(): + + def logindetails(): + username = request.form.get('username') + hashedPassword = request.form.get('passwordHash') + return username, hashedPassword + + det = logindetails() + username = det[0] + hashedPassword = det[1] + + checkuser = {"username":username, "passwordHash":hashedPassword} + if checkuser in cred: + token = jwt.encode({'userID': username, + 'passwordHash': hashedPassword + }, current_app.config['SECRET_KEY'], algorithm="HS256") + + return jsonify({'Status': 'Success', 'token': token}) + + return jsonify({'Status': 'Failed', 'Message': 'Username or Password does not match'}) \ No newline at end of file From a2a00935304059bf3084a9d0b467019e20cfc09a Mon Sep 17 00:00:00 2001 From: Trulydev50 <76103867+Trulydev50@users.noreply.github.com> Date: Wed, 27 Oct 2021 23:22:54 +0800 Subject: [PATCH 5/5] done --- Auth/__pycache__/AuthAPI.cpython-37.pyc | Bin 0 -> 1584 bytes Profiles/ProfilesAPI.py | 16 +- .../__pycache__/ProfilesAPI.cpython-37.pyc | Bin 0 -> 1674 bytes README.md | 141 ++++++++++++++---- __pycache__/db.cpython-37.pyc | Bin 0 -> 362 bytes main.py | 2 +- 6 files changed, 122 insertions(+), 37 deletions(-) create mode 100644 Auth/__pycache__/AuthAPI.cpython-37.pyc create mode 100644 Profiles/__pycache__/ProfilesAPI.cpython-37.pyc create mode 100644 __pycache__/db.cpython-37.pyc diff --git a/Auth/__pycache__/AuthAPI.cpython-37.pyc b/Auth/__pycache__/AuthAPI.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..547622aca3e41030cd6c981b1a792cf0a663bd4f GIT binary patch literal 1584 zcmZux&2HO95Z)h>qG(xm>i*bho2qRtJlF<|v?z)oXq>2UP}DUnw?GL20>fSFj}+D2 zRRat3rOq{P;DdeagY+f#+EZSkr_QXT#3;JN4rgbEJG1kB%ft2ch`{(Ozer~RA%Ejy zH9SzhgQ@=jA&8(kDQH3qmau{+yzml_qMhY_;=`NgK@lWDQA=t|dzggMAJuOn;oVY7 zBo)3~yJAU0Hb(0r5VbxP;cF)9B6>xxXwr1{wYT<$Sa;$cWxB!EdR$U%Ay4?ckd)tq+}* zqg4VPpMj{z4QzZ%FR9ZQXsn`wkC}c@L6R|32Zjny_#(JwE)l!o z6$M}I8louyZwMV+dR@Zk*oHGL)g&#XZA??GUzSQ7rFvkA4Zcr@Ike-8pO+D>QngN& zF|A2yTIuf)k-o?!v@htG)XcQ4{V26g`(RRaC|e9U~d?+eZf$j#} zCx^8o&;S-I0#)RS0N#M|4smFE@a7e(xbUyprB``|j02SzI%3WW*cv|aL~Vy4*01@c zZ+sC|zF1pw!WVE?M02rBb&#rNy*vc4(Da-xt2^DqCG=c1I_ zk-bPwHh{eNooeD9!GgAY^wQWsPO?%+g?H8lSvff$_8qk$Y6olyhx0D_g)K?y*+6Dv zEL(jF>;JaMcgOw&Jo-Zrgol1WLmILOWB|`5YclmYc;Zd#JEAK@aDjrmQmzuNFSNq$ zx>D7B(5yF2%|P8lHSG29>i2p!#NQqK3WwHL/', methods = ["GET"]) def retrieve(id): @@ -29,7 +29,7 @@ def postid(): @profiles_api.route('//', methods = ["DELETE"]) def deleteid(id): if id > len(db)-1: - return jsonify({"Status" : "Error", "Message" : "No such ID"}) + return jsonify({"Status" : "Error", "Message" : "Don't have"}) else: deleted = db[id] @@ -43,14 +43,14 @@ def getabovemin(id): if id > len(db)-1: return jsonify({"Status" : "Error", "Message" : "No such ID"}) - minscore = request.args.get('minScore') - scores = db[id]["scores"] + min = request.args.get('minScore') + s = db[id]["scores"] - if minscore == '': - return jsonify({"Status" : "Success", "Details" : scores}) + if min == '': + return jsonify({"Status" : "Success", "Details" : s}) - abovemin = list(filter(lambda score: score > int(minscore), scores))#use assig + score = list(filter(lambda s: s > int(min), s))#use assig - return jsonify({"Status" : "Success", "Details" : abovemin}) + return jsonify({"Status" : "Success", "Details" : score}) diff --git a/Profiles/__pycache__/ProfilesAPI.cpython-37.pyc b/Profiles/__pycache__/ProfilesAPI.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..95452b1285350c9f650bb4d964425dbf44492e1c GIT binary patch literal 1674 zcma)6%Wfk@6s@X$`ki?I9-#qm(5M$l5MqHwCK`e*W~9MHIIw70vO2DE(stY3RJAjT z<*Yms!-79xk+9=S_=noEnl(FC+*|GhhYhq;-M3FY@44sHVXams@cf=!L?5|?{DD6= zj}5^yXzEvZal&arW;CQT7P6TYS`;ys*r5$yD{*E{=ujf;iF@U7`ytf zn8adfuOsp(P84KnC1Nfe03{v_CbO7BJw&d4BXS3zzuKdxgYT4(YViDMz=fLTX*T%w zd8hmR?qPTLlihI=sp;UT;Ndp-;^@U*cA>Uxpif)2&yD^I0MYu@DtcQZO@~bkX4vn zq%3O~yV8P>w#TWQY3meDhM8+O$}%zM1p{GuE?yO74J$=#)Ii{hE z2bfK()MsTTADRA6_ht9Ed#C!ipQ-*c2>xgFA>YplY5??rDzH!+g$g7xDv{f}8ZdR1 z73?%DSO!?SJ@Kjq+HG`1B67i7MV^5r>o|5x2(ke{=<&_KP1=S4le@pcWBwRM71?jf z>N5F0V9Uloeo&)Sid!161h@}=RR*vBpuw8hR}Ocs=}(0rxQnKEL%26(@+A=C11+V( zGH&kuNXC?xdF3_WYcSF!Gh^V=CnYrW{)Xa#8t{aHNkC+z#-e3S(G%OGth@iDoA}I`|Z3{t1mN zAA>lflk{A`$h~%wj-o^zK(HAX`2Q+bq3cMVD)}DF*LD)amF2?KlnV*f#bU}2vBxpl znB4;^TZo&AR/ + +retrieve the names and scores + +Function used : retrieve(id) +Source: ProfilesAPI.py + +Parameters : None + +Response : JSON of status and profile + +Example : + {"Status" : "Success", "Details" : {"name": "Nobel", "scores": [1, 2, 3, 4, 5]} } + +3) POST /profiles + +Create new profile + +Function used : postid() +Source: ProfilesAPI.py + +Parameters : None + +Response : JSON of status and details of new profile + +Example : + {"Status" : "Success", "Details" : {"name": "Vina"}} + +4) DELETE /profiles// + +Delete profile + +Function used : deleteid(id) +Source: ProfilesAPI.py + +Parameters : None + +Response : JSON of status and details of deleted profile. If failed then json of status and message 'No such ID' + +Example : + {"Status" : "Success", "Details" : {"name": "Nobel", "scores": [1, 2, 3, 4, 5]}} + or +{"Status" : "Error", "Message" : "No such ID"} + +5) GET /profiles//score + +Get all scores of a profile, above the min score and if min score not provided, return all scores + +Function used : getabovemin(id) +Source: ProfilesAPI.py + +Parameters : min + +Response : JSON of status and details of scores. If failed then json of status and message 'Don't have' + +Example : if min=3``` {"Status" : "Success", "Details" : [4, 5]}} + or +{"Status" : "Error", "Message" : "Don't have"} + or if min= +{"Status" : "Success", "Details" : [1, 2 ,3, 4, 5]}} + +6) POST /auth/register + +Stores a username and hashedPassword (given as hashed) and store it in a local array ('creds') + +Function used : reg() +Source: AuthAPI.py + +Parameters : + +username (Required) +Username of user + +passwordHash (Required) +Password of user + +Response : JSON of message - registered and status. If failed then json of status and message 'No such ID' + +Example : +{"Message": "Registered","Status": "Success"} + + +6) POST /auth/login + +Checks if the provided information is valid and return a jwt token + success message + +Function used : login() +Source: AuthAPI.py + +Parameters : + +username (Required) +Username of user + +passwordHash (Required) +Password of user + +Response : JWT token and status. + diff --git a/__pycache__/db.cpython-37.pyc b/__pycache__/db.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..45eea8b02f7a511193755bff37dcec85d44beb43 GIT binary patch literal 362 zcmXw!&q~8U5XLvVNz>M*sb>+yTZ9U&dJz$=4FrWEX)Cw{$|ke6C9Nr0qtsXM6?_3- zDOXQ@1y9b39r%9Czx|f!IZmBme2BH!GYI+C#WrkAu2AY00R#-7z`z7+YC+|bf(;f{ z47#};W%%E7vOMQxJBB;@#TQ%q}n8jH^ literal 0 HcmV?d00001 diff --git a/main.py b/main.py index cf5dc03..bfed903 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ # Write your flask code here app = Flask(__name__) -app.config['SECRET_KEY'] = AUTH_SECRET_KEY +app.config['SECRET_KEY'] = 'Key1' app.register_blueprint(profiles_api, url_prefix="/profiles") app.register_blueprint(auth_api, url_prefix="/auth")