CREATE TABLE IF NOT EXISTS admin (admin_id INTEGER PRIMARY KEY, username TEXT, password TEXT)'
CREATE TABLE IF NOT EXISTS student (student_id INTEGER PRIMARY KEY, surname TEXT, other_name TEXT, location_address TEXT, email TEXT, password TEXT)
from flask import Blueprint, render_template, request, url_for, redirect, session import re import sqlite3 from database import connect_db conn = connect_db() auth_bp=Blueprint("authentication_blueprint", __name__, static_folder="static", template_folder="templates") @auth_bp.route('/register', methods =['GET', 'POST']) def register(): msg = '' if request.method == 'POST': surname = request.form['surname'] other_name = request.form['othernames'] address = request.form['address'] email = request.form['email'] password = request.form['password'] cursor = conn.cursor() cursor.execute(f"SELECT * FROM student WHERE email = '{email}' OR password = '{password}' ") record = cursor.fetchone() if record: msg = 'Email or password already registered try again!' elif not re.match(r'[^@]+@[^@]+\.[^@]+', email): msg = 'Invalid email address !' elif not surname or not other_name or not email or not password: msg = 'Please fill out the * form fields !' else: conn.execute(f"INSERT INTO student (surname, other_name, location_address, email, password) VALUES ('{surname}', '{other_name}', '{address}', '{email}', '{password}')") conn.commit() msg = 'You have successfully registered !' return render_template('register.html', msg = msg) else: return render_template('register.html') @auth_bp.route('/login', methods =['GET', 'POST']) def login(): msg = '' if request.method == 'POST': email = request.form['email'] password = request.form['password'] cursor = conn.cursor() cursor.execute(f"SELECT * FROM student WHERE email = '{email}' AND password = '{password}' ") record = cursor.fetchone() if record: session['loggedin'] = True session['id'] = record[0] session['login_sname'] = record[1] session['login_id'] = record[4] #student email session['login_pw'] = record[5] #student pw #check if login id is email if re.match(r'[^@]+@[^@]+\.[^@]+', session['login_id'] ): #use is student session['level'] = "student" else: #user is an admin session['level'] = "admin" #redirect to success login URL return redirect(url_for('auth')) else: msg = 'Incorrect username / password !' return render_template('login.html', msg = msg) else: return render_template('login.html') @auth_bp.route('/logout') def logout(): msg = '' session.pop('loggedin', None) session.pop('login_id', None) session.pop('login_pw', None) session.pop('level', None) msg = 'You have logout now' #return redirect(url_for('login')) return render_template('login.html', msg = msg)
from flask import Flask, render_template, request, session, url_for, redirect import re from database import connect_db conn = connect_db() from student_blueprint import student_bp from table_create_blueprint import tables_bp from authentication_blueprint import auth_bp app = Flask(__name__) app.secret_key = 'your secret key' #register blueprints app.register_blueprint(student_bp) app.register_blueprint(tables_bp) app.register_blueprint(auth_bp) #load the home or index page @app.route('/home') @app.route('/') def home(): return render_template('index.html') #user loggedin URL @app.route('/auth') def auth(): if 'loggedin' in session: value=session['login_sname'] return render_template('auth.html', logname = value) else: return redirect(url_for('home')) if __name__ == '__main__': app.run(debug=True)
School Grading System - {% block title %}{% endblock title %} School Grading System
{% block subheading %}{% endblock subheading %}
{% block content %}No messages.
{% endblock content %}
School Grading System - {% block title %}{% endblock title %} School Grading System
{% block subheading %}{% endblock subheading %}
{% block content %}No messages.
{% endblock content %}
{% endblock content %}{% extends 'layout.html' %} {% block title %}Login{% endblock title %} {% block subheading %} Login {% endblock subheading %}
{% block content %} {% if msg %}{{ msg }}
{% endif %}
{% endblock content %}{% extends 'layout.html' %} {% block title %}Register{% endblock title %} {% block subheading %} Student Register Form {% endblock subheading %}
{% block content %} {% if msg %}{{ msg }}
{% endif %}
{% extends 'layout.html' %} {% block title %}Welcome{% endblock title %} {% block subheading %}Home{% endblock subheading %}
{% block content %}Welcome to my web app
{% endblock content %}
{% extends 'auth_layout.html' %} {% block title %}Welcome{% endblock title %} {% block subheading %}Hello:{{logname}} {% endblock subheading %}
{% block content %}Login was successfull
{% endblock content %}
{% extends 'auth_layout.html' %} {% block title %}See Students{% endblock title %} {% block subheading %}See Students{% endblock subheading %}
{% block content %}
Id | Surname | Othernames | Address | Edit | Delete |
---|---|---|---|---|---|
{{rec[0]}} | {{rec[1]}} | {{rec[2]}} | {{rec[3]}} | Delete | Edit |
No Comment yet!