def Home(): url_for("static", filename="style.css") cursor = mysql.connect().cursor() cursor.execute("SELECT * from posty") data = cursor.fetchall() cursor.close() return render_template("index.html", name="index", data=data)
def Post(pk): pk = pk cursor = mysql.connect().cursor() cursor.execute("SELECT * from posty") data = cursor.fetchall() cursor.close() return render_template("post.html", pk=pk, data=data)
def Add_users(): if request.method == 'POST': class ServerError(Exception): pass if request.form["action"] == "register": try: conn = mysql.connect() cur = conn.cursor() name_form = request.form['name'] username_form = request.form['user'] password_form = request.form['pass'] hash_password = md5(password_form.encode('utf-8')).hexdigest() to_db = ("", username_form, password_form, name_form) cur.execute("SELECT COUNT(1) FROM users WHERE login = '******'") if cur.fetchone()[0]: name_error = ('Nazwa uzytkownika zajęta') return render_template("add_user.html", error_register=name_error, success_register=success_register) else: cur.execute("INSERT INTO users VALUES (%s, %s, %s, %s)", to_db) conn.commit() success_register = "Zarejestrowałeś się!" except ServerError as e: error_register = str(e) return render_template("add_user.html")
def login(): error = None error_register = None success_register = None class ServerError(Exception): pass if request.method == "POST": if request.form["action"] == "login": try: conn = mysql.connect() cur = conn.cursor() username_form = request.form["username"] rezult = cur.execute("SELECT * FROM users WHERE login ='******'") password_form = request.form["password"] print(md5(password_form.encode("utf-8")).hexdigest()) password_hash = md5(password_form.encode("utf-8")).hexdigest() rezult_h = cur.execute("SELECT * FROM users WHERE pass ='******'") if rezult != 1 and rezult_h != 1: raise ServerError("Błędna nazwa użytkownika lub hasło") elif rezult == 1 and rezult_h == 1: session["username"] = request.form["username"] return redirect( url_for("logowanie_blueprint.Panel_admina")) except ServerError as e: error = str(e) return render_template("log.html", error=error)
def Add_post(): url_for('static', filename='style.css') form = ConctactForms() wszystko_ok = False if request.method == "POST": req = request.form title = req["Tytuł"] autor = req["Autor"] data = req["Data"] zajawka = req["Zajawka"] body_post = req["Treść"] img = req["IMG"] missing = list() for key, value in req.items(): if value == "": missing.append(key) if missing: feedback = f"Brakujące pola dla {', '.join(missing)}" wszystko_ok = False return render_template("kontakt.html", feedback=feedback) else: wszystko_ok = True if wszystko_ok == True: print("Dodawanie do bazy danych") conn = mysql.connect() cursor = conn.cursor() to_db = (title, autor, data, zajawka, body_post, img) print(len(to_db)) cursor.execute("INSERT INTO posty VALUES (%s, %s, %s, %s, %s, %s)", to_db) conn.commit() return redirect(request.url) return render_template("dodawanie_wpsiu.html")
def Panel_admina(): conn = mysql.connect() cursor = conn.cursor() if request.method == "POST": title = request.form["dalet_title"] cursor.execute("DELETE from posty where title='" + title + "'") cursor.execute("SELECT * from posty") data = cursor.fetchall() conn.commit() cursor.close() return render_template("userHome.html", data=data)
def database_posts(): if request.method == 'POST': name = request.form['tytul'] print(name) author = request.form['autor'] data = request.form['data'] zaj = request.form['zaj'] content = request.form['tresc'] img = request.form['img'] conn = mysql.connect() cursor = conn.cursor() to_db = (name, author, data, zaj, content, img) cursor.execute("INSERT INTO posty VALUES (%s, %s, %s, %s, %s, %s)", to_db) conn.commit() cursor.close() cursor = mysql.connect().cursor() cursor.execute("SELECT * from posty") data = cursor.fetchall() cursor.close() return render_template('dodawanie_wpsiu.html', data=data)
def Kontakt(): form = ConctactForms() wszystko_ok = False if request.method == "POST": req = request.form print(f'Values={req}') name = req["Imię"] email = req["E-mail"] sumbnit = req["Tytuł"] wiadomosc = req["Wiadomość"] missing = list() for key, value in req.items(): if value == "": print(req.items()) missing.append(key) if missing: print(bool(missing)) feedback = f"Brakujące pola dla {', '.join(missing)}" wszystko_ok = False return render_template("kontakt.html", feedback=feedback) else: wszystko_ok = True if wszystko_ok == True: print("Dodawanie do bazy danych") conn = mysql.connect() cursor = conn.cursor() to_db = (name, sumbnit, wiadomosc, email) cursor.execute("INSERT INTO forms VALUES (%s, %s, %s, %s)", to_db) conn.commit() cursor.close() cursor = mysql.connect().cursor() cursor.execute("SELECT * from posty") data = cursor.fetchall() cursor.close() return redirect(request.url) return render_template("kontakt.html", form=form)
def Forms_kontatkt(): cursor = mysql.connect().cursor() cursor.execute("SELECT * from forms") data = cursor.fetchall() return render_template("forms_kontakt.html", data=data)