Browse Source

qr code system added

old
Efe Aydın 6 years ago
parent
commit
5634b7b9d0
5 changed files with 40 additions and 2 deletions
  1. +2
    -0
      server_side/api/app.py
  2. BIN
      server_side/api/images/9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png
  3. +35
    -1
      server_side/api/modules/user_info.py
  4. +0
    -1
      server_side/api/modules/voting_system.py
  5. +3
    -0
      server_side/api/requirements.txt

+ 2
- 0
server_side/api/app.py View File

@ -24,6 +24,8 @@ if __name__ == '__main__':
api.add_resource( user_info.Users, '/users', '/users/' )
api.add_resource( user_info.User, '/users/<path:user_id>', '/users/<path:user_id>/' )
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/')


BIN
server_side/api/images/9vard12ty0ad2yvwp3q53rsf3h43r2vq_qr.png View File

Before After
Width: 410  |  Height: 410  |  Size: 802 B

+ 35
- 1
server_side/api/modules/user_info.py View File

@ -1,12 +1,17 @@
import os
import copy
import json
import base64
import pyDes
import qrcode
from api.modules import utils
from flask import Flask, request
from flask_restful import Resource, Api, abort
enc = pyDes.triple_des(b'Kz\n\x1a\xc1~\x05#\xf9\xad\xc8\xa2\x15\xd5J\x89\xe4RT\x8d\xb3?\x93\x1c')
app = Flask(__name__)
api = Api(app)
db_path = os.path.join(app.root_path, 'databases', 'users.json')
@ -80,9 +85,38 @@ class Login(Resource):
else:
return [False, {}]
class QRCode(Resource):
def post(self):
"""
POST Data:
id=<user_id>
"""
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>
"""
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/<path:user_id>', '/users/<path:user_id>/')
api.add_resource(Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5000)

+ 0
- 1
server_side/api/modules/voting_system.py View File

@ -47,7 +47,6 @@ class Votings(Resource):
"""
args = request.form
args = request.form
voting_id = len(votings) + 1
voting = {
'id': voting_id,


+ 3
- 0
server_side/api/requirements.txt View File

@ -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

Loading…
Cancel
Save