#index.py
import sys
from routes import index
from routes import login
app = index.app
app.mount('/login', login.app)
if sys.platform == 'win32':
app.run(host='localhost', port=7000, debug=True, reloader=True)
#routes/login.py
from bottle import Bottle
app = Bottle()
@app.route('/', method="post")
def checkUser():
from controllers.login import checkUser
return checkUser.call()
#controllers/login/checkUser.py
import config
from copy import deepcopy
from bottle import template, request, response, redirect
from models.userdb import checkUserDB
def call():
kdict = deepcopy(config.kdict)
password = request.forms.getunicode('password')
email = request.forms.getunicode('email')
user = checkUserDB.call(email, password)
if user:
kdict["siteLogo"] = 'ទំព័រគ្រប់គ្រង'
response.set_cookie('logged-in', user, path='/', secret=kdict['SECRET_KEY'])
return redirect('/dashboard')
else:
kdict['message'] = 'អ្នកគ្មានឈ្មោះក្នុងបញ្ជីទេ'
return template('index', data=kdict)
#models/userdb/checkUserDB.py
import setConnection
def call(email, password):
cursor, connection = setConnection.call()
cursor.execute("SELECT * FROM users WHERE email=? AND password=?", (email, password))
user = cursor.fetchone()
cursor.close()
return user
#setConnection.py
import sqlite3, config
def call():
connection = sqlite3.connect(config.kdict['DATABASE_URI'])
cursor = connection.cursor()
return cursor, connection
GitHub: https://github.com/Sokhavuth/REST-API
Vercel: https://rest-api-zeta.vercel.app