#controllers/login.py import config from bottle import route, template, request, response, redirect def checkLogin(username, password): if (username == 'admin') and (password == 'password'): return True else: return False @route('/login', method="POST") def user(): username = request.forms.get('fusername') password = request.forms.get('fpassword') if checkLogin(username, password): response.set_cookie("logged-in", username, secret='some-secret-key') redirect('/login') @route('/login') def login(): username = request.get_cookie("logged-in", secret='some-secret-key') if username: return 'dashboard' else: return template('login', data=config.kargs)
<!--views/login.tpl--> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>{{data['blogTitle']}}</title> <link href="/static/styles/login.css" rel="stylesheet"></link> <link href="/static/images/site_logo.png" rel="icon" ></link> <link href="/static/fonts/setup.css" rel="stylesheet"></link> </head> <body> <form id='login' action="/login" method="POST"> <a>ឈ្មោះអ្នកប្រើប្រាស់ៈ</a> <input type="text" name='fusername' value="admin" /> <a>ពាក្យសំងាត់ៈ</a><input type="password" name="fpassword" value="password" /> <a></a><input type='submit' /> </form> </body> </html>
/*public/css/login.css*/ body{ background: lightgrey; position: relative; } #login{ width: 500px; background: lavender; margin:30px auto; padding: 10px; display: grid; grid-template-columns: 140px auto; grid-gap: 10px; font: 14px/1.5 OdorMeanChey; position: absolute; left: 50%; transform: translate(-50%,0); } #login input{ padding: 10px; } #login a{ text-align: right; padding: 10px 0; } @media only screen and (max-width: 600px){ #login{ grid-template-columns: 100%; width: 100%; } #login a{ text-align: left; padding: 0; } }
GitHub: https://github.com/Sokhavuth/kwblog
Heroku: https://khmerweb-kwblog.herokuapp.com/