diff --git a/bank/Pax/routes.py b/bank/Pax/routes.py new file mode 100644 index 0000000..de887d3 --- /dev/null +++ b/bank/Pax/routes.py @@ -0,0 +1,26 @@ +from flask import render_template, url_for, flash, redirect, request, Blueprint +from bank import app, conn, bcrypt +from bank.forms import AddEmployeeForm +from flask_login import login_user, current_user, logout_user, login_required +from bank.models import select_all_Employees, insert_Employees + +Pax = Blueprint('Pax', __name__) + +posts = [{}] + + +@Pax.route("/test", methods=['GET', 'POST']) +def test(): + form = AddEmployeeForm() + # Nedenstånde kode køres kun ved POST-forespørgsler: + if form.validate_on_submit(): + hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') + id=form.id.data + name=form.username.data + password=hashed_password + insert_Employees(id, name, password) + flash('Employee has been created! The employee is now able to log in', 'success') + return redirect(url_for('Login.home')) + # Og denne køres GET-forespørgsler: + employees = select_all_Employees() + return render_template('test.html', title='Hej med dig', emp=employees, form=form) diff --git a/bank/__init__.py b/bank/__init__.py index aa728bf..c1c5faf 100644 --- a/bank/__init__.py +++ b/bank/__init__.py @@ -17,8 +17,10 @@ login_manager.login_message_category = 'info' from bank.Login.routes import Login from bank.Customer.routes import Customer from bank.Employee.routes import Employee +from bank.Pax.routes import Pax app.register_blueprint(Login) app.register_blueprint(Customer) app.register_blueprint(Employee) +app.register_blueprint(Pax) #from bank import routes diff --git a/bank/forms.py b/bank/forms.py index 8ed6b41..90216d1 100644 --- a/bank/forms.py +++ b/bank/forms.py @@ -9,6 +9,13 @@ class AddCustomerForm(FlaskForm): password = PasswordField('Password', validators=[DataRequired()]) submit = SubmitField('Add') +class AddEmployeeForm(FlaskForm): + id = IntegerField('Id', + validators=[DataRequired()]) + username = StringField('Username', + validators=[DataRequired(), Length(min=2, max=20)]) + password = PasswordField('Password', validators=[DataRequired()]) + submit = SubmitField('Add') class CustomerLoginForm(FlaskForm): id = IntegerField('CPR_number', validators=[DataRequired()]) @@ -36,4 +43,4 @@ class DepositForm(FlaskForm): submit = SubmitField('Confirm') class InvestForm(FlaskForm): - submit = SubmitField('Confirm') \ No newline at end of file + submit = SubmitField('Confirm') diff --git a/bank/models.py b/bank/models.py index b5822b9..df8d852 100644 --- a/bank/models.py +++ b/bank/models.py @@ -83,6 +83,17 @@ def insert_Customers(name, CPR_number, password): conn.commit() cur.close() +def insert_Employees(id, name, password): + cur = conn.cursor() + sql = """ + INSERT INTO Employees(id, name, password) + VALUES (%s, %s, %s) + """ + cur.execute(sql, (id, name, password)) + # Husk commit() for INSERT og UPDATE, men ikke til SELECT! + conn.commit() + cur.close() + def select_Customers(CPR_number): cur = conn.cursor() sql = """ @@ -105,6 +116,16 @@ def select_Employees(id): cur.close() return user +def select_all_Employees(): + cur = conn.cursor() + sql = """ + SELECT * FROM Employees + """ + cur.execute(sql) + tuple_resultset = cur.fetchall() + cur.close() + return tuple_resultset + def update_CheckingAccount(amount, CPR_number): cur = conn.cursor() sql = """ diff --git a/bank/static/main.css b/bank/static/main.css index 7be6de0..44e1df8 100644 --- a/bank/static/main.css +++ b/bank/static/main.css @@ -1,88 +1,84 @@ body { - background: #fafafa; - color: #333333; - margin-top: 5rem; + background: #fafafa; + color: #333333; + margin-top: 5rem; } h1, h2, h3, h4, h5, h6 { - color: #444444; + color: #444444; } .bg-steel { - background-color: #5f788a; + background-color: #5f788a; } .site-header .navbar-nav .nav-link { - color: #cbd5db; + color: #cbd5db; +} + +.site-header li > .nav-item.nav-link { + color: #495057; } .site-header .navbar-nav .nav-link:hover { - color: #ffffff; + color: #ffffff; } .site-header .navbar-nav .nav-link.active { - font-weight: 500; -} - -.site-header .dropdown-menu > li > .nav-item.nav-link { - color: #495057; -} - -.site-header .dropdown-menu > li > .nav-item.nav-link:hover { - color: #798592; + font-weight: 500; } .content-section { - background: #ffffff; - padding: 10px 20px; - border: 1px solid #dddddd; - border-radius: 3px; - margin-bottom: 20px; + background: #ffffff; + padding: 10px 20px; + border: 1px solid #dddddd; + border-radius: 3px; + margin-bottom: 20px; } .article-title { - color: #444444; + color: #444444; } a.article-title:hover { - color: #428bca; - text-decoration: none; + color: #428bca; + text-decoration: none; } .article-content { - white-space: pre-line; + white-space: pre-line; } .article-img { - height: 65px; - width: 65px; - margin-right: 16px; + height: 65px; + width: 65px; + margin-right: 16px; } .article-metadata { - padding-bottom: 1px; - margin-bottom: 4px; - border-bottom: 1px solid #e3e3e3 + padding-bottom: 1px; + margin-bottom: 4px; + border-bottom: 1px solid #e3e3e3 } .article-metadata a:hover { - color: #333; - text-decoration: none; + color: #333; + text-decoration: none; } .article-svg { - width: 25px; - height: 25px; - vertical-align: middle; + width: 25px; + height: 25px; + vertical-align: middle; } .account-img { - height: 125px; - width: 125px; - margin-right: 20px; - margin-bottom: 16px; + height: 125px; + width: 125px; + margin-right: 20px; + margin-bottom: 16px; } .account-heading { - font-size: 2.5rem; + font-size: 2.5rem; } diff --git a/bank/templates/layout.html b/bank/templates/layout.html index baa719e..bc79dbf 100644 --- a/bank/templates/layout.html +++ b/bank/templates/layout.html @@ -47,6 +47,7 @@