Skip to content

Commit

Permalink
registrace
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Vybíhal committed Dec 1, 2022
1 parent a451e8b commit 816cc8e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
Binary file modified data.db
Binary file not shown.
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<li><a href="{{ url_for('malina') }}">Malina</a></li>
<li><a href="{{ url_for('login') }}">Login</a></li>
<li><a href="{{ url_for('logout') }}">logout</a></li>
<li><a href="{{ url_for('registrace') }}">registrace</a></li>
</ul></nav>


Expand Down
24 changes: 24 additions & 0 deletions templates/registrace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'base.html' %}

{%block title%}registrace{%endblock%}

{% block obsah %}

<h1>registrace</h1>

<p>zde se můžete registrovat</p>

<form action="" method="post">
jméno: <br>
<input type="text" name="jmeno"> <br>
heslo: <br>
<input type="password" name="heslo"> <br>
<br>
heslo znovu: <br>
<input type="password" name="heslo2"> <br>
<br>
<input type="submit" value="registracione">

</form>

{% endblock obsah %}
36 changes: 34 additions & 2 deletions webface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from flask import Flask, render_template, request, redirect, url_for, session, flash
import functools
from mysqlite import SQLite
# from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.security import generate_password_hash, check_password_hash
import sqlite3

app = Flask(__name__)
app.secret_key = b"totoj e zceLa n@@@hodny retezec nejlep os.urandom(24)"
Expand Down Expand Up @@ -86,7 +87,7 @@ def login_post():
ans = cur.fetchall()


if ans and ans[0][0]== heslo:
if ans and check_password_hash(ans[0][0], heslo):
flash("jsi přihlašen", "message")
session["uzivatel"] = jmeno
if page:
Expand All @@ -103,3 +104,34 @@ def logout():
session.pop("uzivatel", None)
return redirect(url_for('index'))

@app.route("/registrace/", methods=['GET'])
def registrace():
return render_template('registrace.html')

@app.route("/registrace/", methods=['POST'])
def registrace_post():
jmeno = request.form.get('jmeno')
heslo = request.form.get('heslo')
heslo2 = request.form.get('heslo2')

if not (jmeno and heslo and heslo2):
flash('Je nutné vyplnit všechna políčka',"error")

if heslo != heslo2:
flash('Hesla nejsou stejná',"error")

heslohash = generate_password_hash(heslo)
try:
with SQLite("data.db") as cur:
cur.execute( " INSERT INTO user (login,passwd) VALUES (?,?) ", [jmeno,heslohash] )
ans = cur.fetchall()
flash("přihlášen")
flash("Zaregistrováno")
session["uzivatel"] = jmeno
return redirect(url_for('index'))
except sqlite3.IntegrityError:
flash(f"Jméno {jmeno} je již zabrané ")


return redirect(url_for('registrace'))

0 comments on commit 816cc8e

Please sign in to comment.