#index.py
import sys
from routes import index
from routes import login
from routes import dashboard

app = index.app
app.mount('/login', login.app)
app.mount('/dashboard', dashboard.app)

if sys.platform == 'win32':
    app.run(host='localhost', port=7000, debug=True, reloader=True)

 

#routes/dashboard.py
import config
from copy import deepcopy
from bottle import Bottle, redirect, template, request
from controllers.login import checkLogged

import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024

app = Bottle()

@app.route('/')
def index():
    if checkLogged.call():
        from controllers.dashboard import index
        return index.call()
    else:
        redirect('/')

@app.route('/logout')
def logout():
    from controllers.dashboard import logout
    logout.call()

 

#controllers/login/checkLogged.py
import config
from bottle import request

def call():
    user = request.get_cookie('logged-in', secret=config.kdict['SECRET_KEY'])
    return user

 

#controllers/dashboard/logout.py
import config
from bottle import request, response, redirect

def call():
    response.delete_cookie('logged-in', path='/', secret=config.kdict['SECRET_KEY'])
    redirect('/')

 

<!--views/dashboard/index.tpl-->
% rebase('base.tpl')
<link href="/static/styles/partials/header.css" rel="stylesheet"></link>

<section class='Head'>
    <header class='region'>
        <div class='site-logo'>{{ data['siteLogo'] }}</div>

        <form action='/dashboard/search' method='post'>
            <select name="select">
                <option>ការផ្សាយ</option>
                <option>ជំពូក</option>
                <option>សៀវភៅ</option>
                <option>អ្នក​ប្រើប្រាស់</option>
            </select>
            <input type='text' name="q" placeholder="Search" required />
            <input type="submit" value='បញ្ជូន'​ />
        </form>

        <div class='logout'><a href='/dashboard/logout'>ចេញ​ក្រៅ</a></div>
    </header>
</section>

 

/*asset/css/partials/header.css*/
.Head{
    background: lightgrey;
    padding: 7px;
    border-bottom: 7px solid white;
}

.Head header{
    display: grid;
    grid-template-columns: 25% auto 25%;
    align-items: center;
}

.Head .site-logo{
    font: 22px/1.5 Limonf3;
}

.Head form{
    display: grid;
    grid-template-columns: 20% auto 15%;
}

.Head form input, .Head form select{
    font: 14px/1.5 Vidaloka, OdorMeanChey;
    padding: 0 5px;
}

.Head .logout{
    text-align: right;
    font-size: 18px;
}

 

GitHub: https://github.com/Sokhavuth/REST-API

Vercel: https://rest-api-zeta.vercel.app