Пример #1
0
def login():
    """
    Landing page.
    Launches and handles login form if needed.
    """
    # Database access + loads basic info
    Database.on()
    params = models.Params()
    lang = utils.Lang(params.lang)
    Database.off()

    # Prepare template data
    data = {'lang': lang.__dict__, 'body_class': 'login', 'error': False}

    # If the user is already logged : go to "grocery_list"
    if 'is_logged' in session and session['is_logged']:
        return redirect(url_for('groceries'))

    # Handle post data
    if request.form and 'password' in request.form:
        password = request.form['password']
        password = bytearray(password, encoding='utf-8')
        password = hashlib.sha1(password).hexdigest()

        # Right password
        if password == params.user_password:
            session['is_logged'] = True
            return redirect(url_for('groceries'))
        # Wrong password
        else:
            data['error'] = True

    return render_template('login.html', **data)
Пример #2
0
def api_lang():
    """
    Returns JSON of the lang file
    """
    # Database access + loads basic info
    Database.on()
    lang = utils.Lang(models.Params().lang)
    lang = lang.__dict__
    Database.off()

    # Return template
    return render_template('json.html', json=json.dumps(lang))
Пример #3
0
    def test_lang(self):
        """
        Tests access to the "lang" JSON content
        Success conditions :
        - Returns HTTP 200 with associated JSON data
        """
        with webapp.test_client() as app:
            response = app.get('/api/lang')

            expected_data = utils.Lang('en').__dict__
            given_data = str(response.data, encoding='utf-8')
            given_data = json.loads(given_data)
            given_data = given_data.keys()

            assert response.status_code == 200
            assert set(expected_data) == set(given_data)
Пример #4
0
def products():
    """
    Shows PRODUCTS template if the user is logged.
    """
    # Auth check
    if 'is_logged' not in session or not session['is_logged']:
        return redirect(url_for('login'))

    # Database access + loads basic info
    Database.on()
    lang = utils.Lang(models.Params().lang)
    Database.off()

    # Prepare template data
    data = {'lang': lang.__dict__, 'body_class': 'products'}

    # Return template
    return render_template('products.html', **data)
Пример #5
0
def groceries():
    """
    Shows GROCERIES template if the user is logged.
    """
    # Auth check
    if 'is_logged' not in session or not session['is_logged']:
        return redirect(url_for('login'))

    # Database access + loads basic info
    Database.on()
    lang = utils.Lang(models.Params().lang)
    items = models.Products().get_list()
    Database.off()

    # Prepare template data
    data = {
        'lang': lang.__dict__,
        'body_class': 'groceries',
        'products_list': items
    }

    # Return template
    return render_template('groceries.html', **data)
Пример #6
0
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import logging
import argparse
import os

import controllers
from controllers.web import webapp  # Gunicorn hook for Flask
import utils

#-----------------------------------------------------------------------------
# Version
#-----------------------------------------------------------------------------
JEANPIERRE_VERSION = utils.Lang('en').jp_version


#-----------------------------------------------------------------------------
# Main : routing
#-----------------------------------------------------------------------------
def main():
    """
    Routing from the console line arguments to the appropriate controller.
    Options :
    --do config/scanner/web
    Examples :
    - ./jeanpierre.py --do scanner
    - ./jeanpierre.py --do config -l fr
    - ./jeanpierre.py -v
    """