def reg_UNX() -> 'html':
    user_name = request.form['user_name']
    password_1 = request.form['password_1']
    password_2 = request.form['password_2']
    email = request.form['email']
    flag = True
    ''' SPRAWDZANIE POPRAWNOŚCI WPISANYCH DANYCH W FORMULARZU REJESTRACYJNYM '''
    ''' Sprawdzanie user_name '''
    if (len(user_name) < 4 or len(user_name) > 32):
        flag = False
    with DBco(dbconfig) as cursor:
        _SQL = """SELECT user_name FROM user WHERE user_name = (%s) """
        cursor.execute(_SQL, (user_name, ))
        res = cursor.fetchall()
    lenght_res = len(res)
    if lenght_res != 0:
        flag = False
    ''' Sprawdzanie password '''
    if password_1 != password_2:
        flag = False
    if (len(password_1) < 5 or len(password_1) > 16):
        flag = False
    ''' Sprawdzanie email '''
    buf_x = email.count("@")
    if buf_x != 1:
        flag = False
    else:
        if "." not in email:
            flag = False
        else:
            buf_l = email.index("@")
            after = email[buf_l:]
            if "." not in after:
                flag = False
    with DBco(dbconfig) as cursor:
        _SQL = """ SELECT email FROM user WHERE email = (%s) """
        cursor.execute(_SQL, (email, ))
        res = cursor.fetchall()
    lenght_res = len(res)
    if lenght_res != 0:
        flag = False
    ''' WYNIK SPRAWDZANIA '''
    '''	Rejestracja nowego urzytkownika lub powrót do formlarza '''
    if flag == True:
        with DBco(dbconfig) as cursor:
            _SQL = """ INSERT INTO user (user_name, password, email, cash) VALUES (%s, %s, %s, %s) """
            cursor.execute(_SQL, (user_name, password_1, email, '0'))
        return render_template('login.html',
                               the_script='sucess_regist.js',
                               the_title="Logowanie")
    else:
        return render_template('registration.html', the_title="Rejestracja")
예제 #2
0
def test() -> str:
    """ REJESTRACJA """
    flag = True
    bed_letter = ['ą', 'ę', 'ó', 'ł', 'ć', 'ż', 'ź', '/', ',', '.', ';', ':']
    user_name = request.form['user_name']
    passwd = request.form['password']
    email = request.form['email']
    """Sprawdzanie user_name """
    if (len(user_name) < 3) or (len(user_name) > 24):
        flag = False
    for i in user_name:
        if i in bed_letter:
            flag = False
    with DBco(dbconfig) as cursor:
        _SQL = """SELECT user_ID FROM user_game WHERE user_name = (%s) """
        cursor.execute(_SQL, (user_name, ))
        res = cursor.fetchall()
    res_len = len(res)
    if res_len > 0:
        flag = False

    if flag == True:
        """ TWORZENIE NOWEGO UŻYTKOWNIKA W BAZIE I IMPLEMENTACJA ZASOBÓW """
        with DBco(dbconfig) as cursor:
            _SQL = """INSERT INTO user_game (user_name, user_password, email, action_punkts, lvl, experience, silver_coins, gold_coins, premium_day) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
            cursor.execute(
                _SQL,
                (user_name, passwd, email, '15', '1', '0', '1', '1', '7'))
        with DBco(dbconfig) as cursor:
            _SQL1 = """SELECT user_ID FROM user_game WHERE user_name = (%s) and user_password = (%s)"""
            cursor.execute(_SQL1, (user_name, passwd))
            kont = cursor.fetchall()
            user_ID = kont[0][0]

            maps = []
            for i in range(81):
                maps.append('2')
            for i in range(20):
                rand = randint(0, 80)
                maps[rand] = '3'
            for i in range(15):
                rand = randint(0, 80)
                maps[rand] = '4'
            for i in range(10):
                rand = randint(0, 80)
                maps[rand] = '1'
            for rote in range(0, 80, 1):
                _SQLX = """INSERT INTO fields_user (user_ID, krotka_ID, content_ID, counter) VALUES (%s, %s, %s, %s);"""
                cursor.execute(_SQLX, (user_ID, rote, maps[rote], '1'))
        return "succces"
    else:
        return "failed"
def info(id_book: str) -> 'html':
    with DBco(dbconfig) as cursor:
        _SQL = """SELECT * FROM ksiazki AS k, ksiazki_information AS i WHERE k.id_ksiazki = i.id_ksiazki AND k.id_ksiazki = (%s) """
        cursor.execute(_SQL, (id_book, ))
        res = cursor.fetchall()

    return render_template('book_info.html', the_info=res, the_title=res[0][1])
    def add_book() -> 'html':
        res = select_data_book(id_book)
        for r in res:
            book_title = res[0]
            book_price = res[1]

        user_cash = show_cash()

        if user_cash >= book_price:
            new_user_cash = user_cash - book_price
            with DBco(dbconfig) as cursor:
                _SQL1 = """ UPDATE user SET cash = %s WHERE id_user = %s """
                cursor.execute(_SQL1, (new_user_cash, session['id_user']))
                _SQL2 = """ INSERT INTO transactions (id_ksiazki, id_user, name, cost) VALUES (%s, %s, %s, %s) """
                cursor.execute(
                    _SQL2,
                    (id_book, session['id_user'], book_title, book_price))

            return render_template(
                'alert.html',
                the_res=
                "Gratujacje pomyślnego dokonania zakupu. Możesz teraz z niego korzystać.",
                the_title="Potwierdzenie")
        else:
            return render_template(
                'alert.html',
                the_res=
                "Niestety nie posiadasz wystarczającej illości środków w swoim portfelu. Doładuj konto.",
                the_title="Niepowodzenie")
예제 #5
0
def login() -> 'html':
    """ LOGOWANIE """
    user = request.form['user_name']
    passwd = request.form['password']

    with DBco(dbconfig) as cursor:
        _SQL1 = """SELECT user_ID FROM user_game WHERE user_name = (%s) AND user_password = (%s) """

        cursor.execute(_SQL1, (user, passwd))
        res = cursor.fetchall()

    flag = len(res)
    this_date = datetime.today()
    if flag > 0:
        """ Poprawne logowanie """
        saveName(request.form['user_name'], 'Witaj!!!', this_date)
        session['loged_in'] = True
        session['user_name'] = user
        session['user_id'] = res[0][0]

        return render_template('log_ok.html',
                               the_title='Tak',
                               the_log='Logout',
                               the_user_name=request.form['user_name'])
    else:
        """ Jeżeli urzytkownika nie ma w bazie """
        saveName(request.form['user_name'], "Błąd", this_date)
        error_log = "niepoprawny nick lub hasło"
        return render_template('login.html',
                               the_title='Błąd wprowadzanych danych',
                               the_log='Login',
                               the_alert_user_name=error_log)
def check_book_list(id_book: 'int') -> 'True or False':
    with DBco(dbconfig) as cursor:
        _SQL = """ SELECT id_order FROM transactions WHERE id_ksiazki = %s AND id_user = %s """
        cursor.execute(_SQL, (id_book, session['id_user']))
        res = cursor.fetchall()
    if len(res) > 0:
        return True
    return False
 def wallet() -> 'html':
     with DBco(dbconfig) as cursor:
         _SQL = """ SELECT * FROM transactions WHERE id_user = (%s) ORDER BY data_order DESC"""
         cursor.execute(_SQL, (session['id_user'], ))
         res = cursor.fetchall()
     return render_template('wallet.html',
                            the_res=res,
                            the_cash=show_cash(),
                            the_title="Portfel")
def show_cash() -> str:
    with DBco(dbconfig) as cursor:
        _SQL = """ SELECT cash FROM user WHERE id_user = (%s) """
        cursor.execute(_SQL, (session['id_user'], ))
        res = cursor.fetchall()
        for i in res:
            for j in i:
                res = j
    return res
 def show_collection() -> 'html':
     with DBco(dbconfig) as cursor:
         _SQL = """ SELECT i.img_src, k.tytul, k.gatunek, k.ocena, k.id_ksiazki"""
         _SQL += """ FROM ksiazki AS k, ksiazki_information AS i, transactions AS t """
         _SQL += """	WHERE t.id_user = %s AND k.id_ksiazki = t.id_ksiazki AND k.id_ksiazki = i.id_ksiazki; """
         cursor.execute(_SQL, (session['id_user'], ))
         res = cursor.fetchall()
     return render_template('user_collection.html',
                            the_collection=res,
                            the_title="Kolekcja książek")
예제 #10
0
def hello() -> 'html':
    """ STRONA GŁÓWNA """
    if 'loged_in' in session:
        """ Jeśli jesteś zalogowany  """
        with DBco(dbconfig) as cursor:
            _SQL = """SELECT * FROM (fields_user, content_krotka) WHERE user_ID = (%s) AND fields_user.content_ID = content_krotka.content_ID ORDER BY krotka_ID; """
            cursor.execute(_SQL, (session['user_id'], ))
            res = cursor.fetchall()
        return render_template('my_home.html',
                               the_title='My home',
                               the_log='Logout',
                               the_src_base=res)
    else:
        """ Jeśli nie jesteś zalogowany  """
        return render_template('home.html', the_title='Home', the_log='Login')
def login_up() -> 'html':
    user_name = request.form['user_name']
    password = request.form['password']
    with DBco(dbconfig) as cursor:
        _SQL = """SELECT id_user FROM user WHERE user_name = (%s) AND password = (%s) """
        cursor.execute(_SQL, (
            user_name,
            password,
        ))
        res = cursor.fetchall()
    if len(res) > 0:
        session['loged_in'] = True
        session['user_name'] = user_name
        session['id_user'] = res[0][0]
        text = "Jesteś zalogowany jako " + user_name
        return render_template('alert.html', the_res=text, the_title='Witam')
    else:
        return render_template('login.html', the_title='Logowanie')
def login() -> 'html':
    if 'loged_in' in session:
        with DBco(dbconfig) as cursor:
            _SQL = """ SELECT id_user, email, data_registration FROM user WHERE id_user = (%s) """
            cursor.execute(_SQL, (session['id_user'], ))
            res = cursor.fetchone()
        res_date = datetime.date(res[2])
        temp_res = {
            'user_name': session['user_name'],
            'id_user': res[0],
            'email': res[1],
            'date': res_date
        }
        return render_template('settings.html',
                               the_res=temp_res,
                               the_title="Dane użytkownika")
    else:
        return render_template('login.html', the_title='Logowanie')
def hello() -> 'html':
    with DBco(dbconfig) as cursor:
        _SQL = """SELECT k.id_ksiazki, k.tytul, k.gatunek, k.ocena, i.img_src FROM ksiazki AS k, ksiazki_information AS i WhERE k.id_ksiazki = i.id_ksiazki"""
        cursor.execute(_SQL)
        res = cursor.fetchall()
    return render_template('home.html', the_books=res, the_title="Książki")
def select_data_book(id_book) -> tuple:
    with DBco(dbconfig) as cursor:
        _SQL = """ SELECT tytul, cena FROM ksiazki WHERE id_ksiazki = (%s) """
        cursor.execute(_SQL, (id_book, ))
        rex = cursor.fetchone()
    return rex