From 5634b7b9d08a20e7bdc44f8b42d38bc41691ff21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20Ayd=C4=B1n?= <3feaydin@gmail.com> Date: Mon, 15 Apr 2019 17:09:53 +0300 Subject: [PATCH] qr code system added --- server_side/api/app.py | 2 + .../9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png | Bin 0 -> 802 bytes server_side/api/modules/user_info.py | 36 +++++++++++++++++- server_side/api/modules/voting_system.py | 1 - server_side/api/requirements.txt | 3 ++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 server_side/api/images/9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png diff --git a/server_side/api/app.py b/server_side/api/app.py index 653df3f..d6cf584 100644 --- a/server_side/api/app.py +++ b/server_side/api/app.py @@ -24,6 +24,8 @@ if __name__ == '__main__': api.add_resource( user_info.Users, '/users', '/users/' ) api.add_resource( user_info.User, '/users/', '/users//' ) api.add_resource( user_info.Login, '/login', '/login/' ) + api.add_resource(user_info.QRCode, '/qr', '/qr/') + api.add_resource(user_info.QRRead, '/qr_data', '/qr_data/') api.add_resource(utility.Resources, '/resources', '/resources/') diff --git a/server_side/api/images/9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png b/server_side/api/images/9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png new file mode 100644 index 0000000000000000000000000000000000000000..e86b7fd37b56160dd6a0b90fdfd118b36eaaa120 GIT binary patch literal 802 zcmV+-1Ks?IP);SBb73yorI%d<)W;Otd-*}CA4jl$nPrs?(P3_%aXx_1Qe4FgA z{3VC}59nDDu>$I;63mD=n~1M6&!Lw=wWJ=P)r46C*2SA3#Sf4)z0N#`j)n#^Giw0i zE#;FyPAf=Nhnel6$_&YiDdC0n$`w`N8NiFIL_3@_C zkMLUKLeS8VQ;070BlZEK$u7gX*O=$f(NSaVP^qsaT1{m)1_43pm-yjPB{izj7aOerVHd$PS<`0?FxR{y{qymAE3#43&?4J;7R1WS3Fm$ENgf zMVuWfK4J`73(w>aa`l-bNlq|a5od>%S|gO+!zzo7RHiiPaz&gUS~5#EIYXXnta$|P zBQ67#Sw%f!a1+Fv48mj(WbM7esNaotY)nU+=g{HMwrAOw2E^{czER;m;v!Hx&IYmC z48qfVE6+YFX!XnQM_d5fWtPg#>Qru~OH(P20B|313238;P46M^l$sLhU>1!l;^ffN z9jax>m7XqrDV8~yE8^5pNg&e-n>uvuN31c$qsIB6{f(KY2(i{0xR1C7w7nnk;0l&0 zXg=w8s4fb{oAO26hFq4mnt)hg-OJ5$=pRGR-|1pDh9*o5KSuJ-f*`(?ukd{FcXH@6 z(9*>g5JAKDsS<#-_bN%i+OaVp9B-aOheMCGM(Io}cc{kv!0%#T1Ty{k%;WO^Oy-b7 g4msqILk + """ + user_id = request.form['id'] + if utils.find_by_id(users.values(), user_id): + image_path = os.path.join(app.root_path, '..', 'images', user_id + '_qr' + '.png') + if not os.path.exists(image_path): + encrypted_id = enc.encrypt(user_id, padmode=2) + img = qrcode.make(base64.b64encode(encrypted_id).decode('utf-8')) + img.save(image_path) + + return '/img/' + user_id + '_qr' + '.png' + else: + abort(404, error="User {} doesn't exist".format(user_id)) + +class QRRead(Resource): + def post(self): + """ + POST Data: + qr_data= + """ + + qr_data = base64.b64decode(request.form['qr_data']) + user_id = enc.decrypt(qr_data, padmode=2) + return utils.find_by_id(users.values(), user_id.decode()) + if __name__ == '__main__': api.add_resource(Users, '/users', '/users/') api.add_resource(User, '/users/', '/users//') api.add_resource(Login, '/login', '/login/') - app.run(host='0.0.0.0', port=5000) \ No newline at end of file + app.run(host='0.0.0.0', port=5000) diff --git a/server_side/api/modules/voting_system.py b/server_side/api/modules/voting_system.py index 3c79f8f..842ee30 100644 --- a/server_side/api/modules/voting_system.py +++ b/server_side/api/modules/voting_system.py @@ -47,7 +47,6 @@ class Votings(Resource): """ args = request.form - args = request.form voting_id = len(votings) + 1 voting = { 'id': voting_id, diff --git a/server_side/api/requirements.txt b/server_side/api/requirements.txt index 327aa5d..6d1c379 100644 --- a/server_side/api/requirements.txt +++ b/server_side/api/requirements.txt @@ -9,3 +9,6 @@ MarkupSafe==1.1.1 pytz==2018.9 six==1.12.0 Werkzeug==0.14.1 +pyDes==2.0.1 +qrcode==6.1 +Pillow==6.0.0 \ No newline at end of file