#controllers/index.py import config, copy from flask import render_template, request, session, redirect from flask_classful import FlaskView, route from models.userdb import Userdb class Index(FlaskView): def __init__(self): self.vdict = copy.deepcopy(config.vdict) self.userdb = Userdb() @route('/') def index(self): return render_template('index.html', data=self.vdict) @route('/login/', methods=['GET', 'POST']) def login(self): if request.method == 'POST': email = request.form['femail'] password = request.form['fpassword'] if(self.userdb.check_user(email, password)): if True: session['email'] = email return render_template('dashboard.html', data=self.vdict) else: if 'email' in session: return render_template('dashboard.html', data=self.vdict) return render_template('login.html', data=self.vdict) @route('/logout/') def logout(self): session.pop('email', None) return redirect('/')
<!--templates/dashboard.html--> <!DOCTYPE html> <html> <head> {% block head %} <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="description" content="This blog engine is built for e-learning"> <meta name="robots" content="index, follow"> <meta name='keywords' content='e-learning, learning, school, math, programming'> <title>{{data['blog_title']}}</title> <script src="/static/scripts/jQuery.js"></script> <script src='/static/scripts/base_dashboard.js'></script> <link href="/static/styles/base.css" rel="stylesheet" > <link href="/static/styles/base_dashboard.css" rel="stylesheet"> <link href="/static/styles/menu_dashboard.css" rel="stylesheet"> <link href="/static/fonts/setup.css" rel='stylesheet'> <link href="/static/images/site_logo.png" rel="icon"> {% endblock %} </head> <body> <div id="header"> {% block header %} <header id="inner" class="inner region"> <div id="title"> <a href="/"><img src="/static/images/site_logo.png" /></a> <a href="/login/">{{data['blog_title']}}</a> </div> <div id="blog-search"> <form class="search" action="/search/backend/" method="post"> <input type="text" placeholder="Search.." name="fquery" required> <button type="submit">ស្វែងរក</button> </form> </div> <div id="logout"><a href="/logout/">ចេញក្រៅ</a></div> </header> {% endblock %} </div> <div id="main" class="main region"> {% block main %} <div id="sidebar"> {% block sidebar %} <div><a href="/posting"><img src="/static/images/posting.png" /></a><a href="/posting">ចុះផ្សាយមេរៀន</a></div> <div><a href="/categorizing"><img src="/static/images/categorizing.png" /></a><a href="/categorizing">បង្កើតប្រភេទមេរៀន</a></div> <div><a href="/paging"><img src="/static/images/paging.png" /></a><a href="/paging">បង្កើតទំព័រមាតិកា</a></div> <div><a href="/uploading"><img src="/static/images/multimedia.png" /></a><a href="/uploading">ចំលងឯកសារ</a></div> <div><a href="/addinguser"><img src="/static/images/user.png" /></a><a href="/addinguser">បន្ថែមសមាជិក</a></div> <div><a href="/setting"><img src="/static/images/setting.png" /></a><a href="/setting">កំណត់ទំរង់លក្ខណៈ</a></div> {% endblock %} </div> <div id="content">{% block content %}{% endblock %}</div> {% endblock %} </div> <div id="item-listing" class="item-listing region"></div> <div id="footer" class="footer region"> {% block footer %} © Copyright 2020 by <a href="https://www.khmerweb.app/">Khmer Web</a>. <script>var base = new Base();</script> {% endblock %} </div> </body> </html>
/*static/styles/base_dashboard.css*/ #header{ background: lightgrey; border-bottom: 15px solid rgb(172, 170, 170); } #header #inner{ display: grid; grid-template-columns: 30% auto 25%; align-items: center; grid-gap: 10px; padding: 10px; } #header #inner #logout{ text-align: right; } #header #title{ display: grid; grid-template-columns: 35px auto; grid-gap:5px; align-items: center; font: 27px/1.5 Moul; } #header #title img{ width: 100%; } #main{ margin-top: 10px; display: grid; grid-template-columns: 25% auto; grid-gap: 10px; } #main #sidebar{ background: lightgrey; padding: 20px; min-height: 300px; } #main #sidebar div{ display: grid; grid-template-columns: 15% auto; grid-gap: 10px; align-items: center; font: 18px/1.5 Koulen; } #main #sidebar img{ width: 100%; } #main #content{ background: lightgrey; } #item-listing{ background: lightgrey; margin-top:10px; min-height: 200px; }
GitHub: "https://github.com/Sokhavuth/E-Learning
Heroku: https://khmerweb-elearning.herokuapp.com/