Esempio n. 1
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.ui = UiLogIn()
        self.ui.setupUi(self)

        self.nfc_reader = NFCReader()
        self.nfc_reader.start()
        self.nfc_reader.tagged.connect(self.check_valid_uid)

        self.db = DataBase()
        self.idx_display = 0
        self.contact = 0
        self.info = {}

        for val, button in enumerate(self.ui.button_keypad):
            button.clicked.connect(partial(self.display_number, val))

        self.ui.dialog_true.button_no.clicked.connect(self.ui.dialog_true.hide)
        self.ui.dialog_true.button_no.clicked.connect(self.clear_page)
        self.ui.dialog_false.button_ok.clicked.connect(
            self.ui.dialog_false.hide)
        self.ui.dialog_false.button_ok.clicked.connect(self.clear_page)

        self.ui.button_NFC.clicked.connect(self.ui.dialog_nfc.show)
        self.ui.dialog_nfc.button_ok.clicked.connect(self.ui.dialog_nfc.hide)
Esempio n. 2
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.ui = UiInUse()
        self.ui.setupUi(self)

        self.db = DataBase()
        self.time = QTime(0, 0)
        self.elapsed_timer = QElapsedTimer()
        self.timer = QTimer(self)
        self.info = {}
Esempio n. 3
0
    def __init__(self):
        QStackedWidget.__init__(self)

        self.setFixedSize(800, 480)

        page0 = SignUpName()
        page1 = SignUpContact()
        page2 = SignUpID()
        page3 = SignUpNFC()
        page4 = SignUpCheck()

        self.addWidget(page0)  # index: 0
        self.addWidget(page1)  # index: 1
        self.addWidget(page2)  # index: 2
        self.addWidget(page3)  # index: 3
        self.addWidget(page4)  # index: 4

        self.name = "Unknown"
        self.contact = 0
        self.contact1 = "1234"
        self.contact2 = "5678"
        self.id = "2020123456"
        self.nfc_uid = ""
        self.db = DataBase()

        page0.ui.button_right.clicked.connect(self.save_name)
        page0.ui.button_right.clicked.connect(partial(self.switch_page, 1))
        page0.ui.edit_name.returnPressed.connect(self.save_name)
        page0.ui.edit_name.returnPressed.connect(partial(self.switch_page, 1))

        page1.ui.button_left.clicked.connect(partial(self.switch_page, 0))
        page1.ui.button_right.clicked.connect(self.save_contact)
        page1.ui.button_right.clicked.connect(partial(self.switch_page, 2))
        page1.ui.edit_contact3.returnPressed.connect(self.save_contact)
        page1.ui.edit_contact3.returnPressed.connect(partial(self.switch_page, 2))

        page2.ui.button_left.clicked.connect(partial(self.switch_page, 1))
        page2.ui.button_right.clicked.connect(self.save_id)
        page2.ui.button_right.clicked.connect(partial(self.switch_page, 3))
        page2.ui.edit_id.returnPressed.connect(self.save_id)
        page2.ui.edit_id.returnPressed.connect(partial(self.switch_page, 3))
        
        page3.ui.button_left.clicked.connect(partial(self.switch_page, 2))
        page3.ui.button_right.clicked.connect(self.save_nfc_uid)
        page3.ui.button_right.clicked.connect(partial(self.switch_page, 4))

        page4.ui.button_left.clicked.connect(partial(self.switch_page, 3))
        page4.ui.button_register.clicked.connect(self.sign_up_user)
        page4.ui.dialog_false.button_ok.clicked.connect(page4.ui.dialog_false.hide)

        self.set_page()
Esempio n. 4
0
class InUse(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.ui = UiInUse()
        self.ui.setupUi(self)

        self.db = DataBase()
        self.time = QTime(0, 0)
        self.elapsed_timer = QElapsedTimer()
        self.timer = QTimer(self)
        self.info = {}

    def update_time(self):
        # TODO: Is there more clean way to show timer...?
        self.ui.label_time.setText(
            (self.time.addMSecs(self.elapsed_timer.elapsed())).toString("hh:mm:ss")
        )

    def set_page(self, contact):
        self.info = self.db.get_info(contact)

        self.elapsed_timer.start()
        self.timer.timeout.connect(self.update_time)
        self.timer.start(500)
        self.ui.label_time.setText(self.time.toString("hh:mm:ss"))
        self.ui.label_name.setText(self.info["name"] + " 님")

    def clear_page(self):
        self.timer.stop()
        self.ui.label_time.setText("00:00:00")
        self.ui.label_name.setText("???")
Esempio n. 5
0
# -*- coding: utf-8 -*-
from flask import Flask, request, make_response, render_template, redirect, Markup
from model.password import Password
from model.db import DataBase
import base64
import os
import json
import hashlib, binascii
import time
import uuid
from functools import wraps
import uuid

app = Flask(__name__)
database = DataBase(os.environ.get('A2_DATABASE_HOST'),
                    os.environ.get('A2_DATABASE_USER'),
                    os.environ.get('A2_DATABASE_PASSWORD'),
                    os.environ.get('A2_DATABASE_NAME'))


def login_admin_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        cookie = request.cookies.get("sessionId", "")
        cookie = base64.b64decode(cookie).decode("utf-8")
        cookie_separado = cookie.split('.')
        if (len(cookie_separado) != 2):
            return "Cookie Inválido!"
        hash_cookie = hashlib.sha256(
            cookie_separado[0].encode('utf-8')).hexdigest()
        if (hash_cookie != cookie_separado[1]):
            return redirect("/login")
Esempio n. 6
0
class LogIn(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.ui = UiLogIn()
        self.ui.setupUi(self)

        self.nfc_reader = NFCReader()
        self.nfc_reader.start()
        self.nfc_reader.tagged.connect(self.check_valid_uid)

        self.db = DataBase()
        self.idx_display = 0
        self.contact = 0
        self.info = {}

        for val, button in enumerate(self.ui.button_keypad):
            button.clicked.connect(partial(self.display_number, val))

        self.ui.dialog_true.button_no.clicked.connect(self.ui.dialog_true.hide)
        self.ui.dialog_true.button_no.clicked.connect(self.clear_page)
        self.ui.dialog_false.button_ok.clicked.connect(
            self.ui.dialog_false.hide)
        self.ui.dialog_false.button_ok.clicked.connect(self.clear_page)

        self.ui.button_NFC.clicked.connect(self.ui.dialog_nfc.show)
        self.ui.dialog_nfc.button_ok.clicked.connect(self.ui.dialog_nfc.hide)

    def display_number(self, num):
        self.ui.display_number[self.idx_display].setText(str(num))
        self.contact = self.contact * 10 + num
        self.idx_display += 1

        if self.idx_display == 8:
            print(f"contact = {self.contact:08d}")
            if self.db.check_user(self.contact):
                self.info = self.db.get_info(self.contact)
                self.ui.dialog_true_name.setText(self.info["name"] + " 님")
                self.ui.dialog_true.show()
                # TODO: swich to in_use page
            else:
                self.ui.dialog_false.show()
                # TODO: error animation

    @Slot(str)
    def check_valid_uid(self, uid):
        print(uid)
        # TODO: check uid from database and switch to in_use page

    def get_contact(self):
        return self.contact

    def set_page(self):
        if not self.nfc_reader.isRunning():
            print("Thread start")
            self.nfc_reader.start()
        self.nfc_reader.tagged.connect(self.check_valid_uid)

    def clear_page(self):
        self.contact = 0
        self.idx_display = 0
        self.ui.dialog_true.hide()
        self.ui.dialog_false.hide()
        for label in self.ui.display_number:
            label.setText("")

        if not self.nfc_reader.isFinished():
            self.nfc_reader.quit()

    def __del__(self):
        self.nfc_reader.quit()
        self.nfc_reader.terminate()
        self.nfc_reader.wait()
Esempio n. 7
0

@app.route('/coupon', methods=['GET', 'POST'])
@login_required
def cupom():
    if request.method == 'POST':
        coupon = request.form.get('coupon')
        rows, success = database.get_game_coupon(coupon,
                                                 session.get('username'))
        if not success or rows == None or rows == 0:
            flash("Cupom invalido", "danger")
            return render_template('coupon.html')
        game, success = database.get_game(coupon, session.get('username'))
        if not success or game == None:
            flash("Cupom invalido", "danger")
            return render_template('coupon.html')
        flash("Voce ganhou {}".format(game[0]), "primary")
        return render_template('coupon.html')
    else:
        return render_template('coupon.html')


if __name__ == '__main__':
    dbEndpoint = os.environ.get('MYSQL_ENDPOINT')
    dbUser = os.environ.get('MYSQL_USER')
    dbPassword = os.environ.get('MYSQL_PASSWORD')
    dbName = os.environ.get('MYSQL_DB')
    database = DataBase(dbEndpoint, dbUser, dbPassword, dbName)
    init_db(database)
    app.run(host='0.0.0.0', port=10010, debug=True)
Esempio n. 8
0
import sys

from flask import (Flask, render_template, request, redirect, flash,
                   make_response, session)
from flask_bootstrap import Bootstrap
from model.password import Password
from model.db import DataBase
from util.init_db import init_db

from flask_cors import CORS, cross_origin

app = Flask(__name__)
bootstrap = Bootstrap(app)

app.config.from_pyfile('config.py')
database = DataBase(app.config['MYSQL_ENDPOINT'], app.config['MYSQL_USER'],
                    app.config['MYSQL_PASSWORD'], app.config['MYSQL_DB'])


def generate_csrf_token():
    '''
        Generate csrf token and store it in session
    '''
    if '_csrf_token' not in session:
        session['_csrf_token'] = str(uuid.uuid4())
    return session.get('_csrf_token')


app.jinja_env.globals['csrf_token'] = generate_csrf_token


@app.before_request
Esempio n. 9
0
class SignUp(QStackedWidget):
    def __init__(self):
        QStackedWidget.__init__(self)

        self.setFixedSize(800, 480)

        page0 = SignUpName()
        page1 = SignUpContact()
        page2 = SignUpID()
        page3 = SignUpNFC()
        page4 = SignUpCheck()

        self.addWidget(page0)  # index: 0
        self.addWidget(page1)  # index: 1
        self.addWidget(page2)  # index: 2
        self.addWidget(page3)  # index: 3
        self.addWidget(page4)  # index: 4

        self.name = "Unknown"
        self.contact = 0
        self.contact1 = "1234"
        self.contact2 = "5678"
        self.id = "2020123456"
        self.nfc_uid = ""
        self.db = DataBase()

        page0.ui.button_right.clicked.connect(self.save_name)
        page0.ui.button_right.clicked.connect(partial(self.switch_page, 1))
        page0.ui.edit_name.returnPressed.connect(self.save_name)
        page0.ui.edit_name.returnPressed.connect(partial(self.switch_page, 1))

        page1.ui.button_left.clicked.connect(partial(self.switch_page, 0))
        page1.ui.button_right.clicked.connect(self.save_contact)
        page1.ui.button_right.clicked.connect(partial(self.switch_page, 2))
        page1.ui.edit_contact3.returnPressed.connect(self.save_contact)
        page1.ui.edit_contact3.returnPressed.connect(partial(self.switch_page, 2))

        page2.ui.button_left.clicked.connect(partial(self.switch_page, 1))
        page2.ui.button_right.clicked.connect(self.save_id)
        page2.ui.button_right.clicked.connect(partial(self.switch_page, 3))
        page2.ui.edit_id.returnPressed.connect(self.save_id)
        page2.ui.edit_id.returnPressed.connect(partial(self.switch_page, 3))
        
        page3.ui.button_left.clicked.connect(partial(self.switch_page, 2))
        page3.ui.button_right.clicked.connect(self.save_nfc_uid)
        page3.ui.button_right.clicked.connect(partial(self.switch_page, 4))

        page4.ui.button_left.clicked.connect(partial(self.switch_page, 3))
        page4.ui.button_register.clicked.connect(self.sign_up_user)
        page4.ui.dialog_false.button_ok.clicked.connect(page4.ui.dialog_false.hide)

        self.set_page()

    def save_name(self):
        self.name = self.widget(0).ui.edit_name.text()

    def save_contact(self):
        self.contact1 = self.widget(1).ui.edit_contact2.text()
        self.contact2 = self.widget(1).ui.edit_contact3.text()

    def save_id(self):
        self.id = self.widget(2).ui.edit_id.text()

    def save_nfc_uid(self):
        self.nfc_uid = self.widget(3).nfc_uid

    def switch_page(self, idx):
        self.currentWidget().clear_page()
        self.setCurrentIndex(idx)
        if idx == 4:
            self.currentWidget().set_page(
                self.name, self.contact1, self.contact2, self.id
            )
        else:
            self.currentWidget().set_page()

    def sign_up_user(self):
        self.contact = int(self.contact1) * 10000 + int(self.contact2)
        print(self.contact)
        # TODO: Add an user to DB with nfc uid
        if self.db.add_user(self.name, self.id, self.contact):
            self.currentWidget().ui.dialog_true_name.setText(self.name + " 님")
            self.currentWidget().ui.dialog_true.show()
        else:
            self.currentWidget().ui.dialog_false.show()

    def set_page(self):
        self.setCurrentIndex(0)
        self.currentWidget().set_page()

    def clear_page(self):
        self.widget(0).ui.edit_name.setText("")
        self.widget(1).ui.edit_contact1.setText("")
        self.widget(1).ui.edit_contact2.setText("")
        self.widget(1).ui.edit_contact3.setText("")
        self.widget(2).ui.edit_id.setText("")
        self.widget(3).nfc_uid = ""
Esempio n. 10
0
import uuid
import datetime

from flask import (Flask, render_template, request, redirect, flash,
                   make_response, session)
from flask_bootstrap import Bootstrap
from model.password import Password
from model.db import DataBase

from flask_cors import CORS, cross_origin

app = Flask(__name__)
bootstrap = Bootstrap(app)

app.config.from_pyfile('config.py')
database = DataBase(app.config['MYSQL_ENDPOINT'], app.config['MYSQL_USER'],
                    app.config['MYSQL_PASSWORD'], app.config['MYSQL_DB'])


def generate_csrf_token():
    '''
        Generate csrf token and store it in session
    '''
    if '_csrf_token' not in session:
        session['_csrf_token'] = str(uuid.uuid4())
    return session.get('_csrf_token')


app.jinja_env.globals['csrf_token'] = generate_csrf_token


@app.before_request
Esempio n. 11
0
@login_required
def home():
    return render_template('index.html')

@app.route('/coupon', methods=['GET', 'POST'])
@login_required
def cupom():
    if request.method == 'POST':
        coupon = request.form.get('coupon')
        rows, success = database.get_game_coupon(coupon, session.get('username'))
        if not success or rows == None or rows == 0:
            flash("Cupom invalido", "danger")
            return render_template('coupon.html')
        game, success = database.get_game(coupon, session.get('username'))
        if not success or game == None:
            flash("Cupom invalido", "danger")
            return render_template('coupon.html')
        flash("Voce ganhou {}".format(game[0].encode('utf-8')), "primary")
        return render_template('coupon.html')
    else:
        return render_template('coupon.html')

if __name__ == '__main__':
    database = DataBase("127.0.0.1", "user", "pass", "A10")
    # init_db(database)
    app.logger.removeHandler(default_handler)
    log = logging.getLogger('werkzeug')
    log.disabled = True
    app.logger.disabled = True
    app.run(port=8081, debug=False)