Example #1
0
def get_userdb_p(user, passw):
    Session = sessionmaker(bind=engine)
    s = Session()
    query = s.query(User).filter_by(username=user, password=passw)
    result = None
    if query:
        result = query.first()
    return result
Example #2
0
def get_userdb(usern):
    Session = sessionmaker(bind=engine)
    s = Session()
    r = s.query(User).filter_by(username=usern)
    result = None
    if r:
        result = r.first()
    return result
Example #3
0
def action():
    result = request.form.get("result")
    id = int(request.form.get("id"))
    rw = ''
    if check_answer(id, result):
        rw = "Correct"
        Session = sessionmaker(bind=engine)
        s = Session()
        our_user = s.query(User).filter_by(username=session['user']).first()
        our_user.answers += 1
        s.commit()
    else:
        rw = "Incorrect"
    return render_template('answer.html', rw=rw, answer=data[id]['answer'])
Example #4
0
def home():
    if not session.get('logged_in'):
        Session = sessionmaker(bind=engine)
        s = Session()
        query = s.query(User)
        return render_template('login.html', query=query)
    else:
        size = len(data)
        randomq = random.randint(0, size - 1)
        result = get_userdb(session['user'])
        return render_template('riddle.html',
                               data=data[randomq],
                               id=randomq,
                               correct=result.answers)
Example #5
0
def create_app():
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    templates_dir = os.path.join(BASE_DIR, 'templates')
    static_dir = os.path.join(BASE_DIR, 'static')

    app = Flask(__name__,
                template_folder=templates_dir,
                static_folder=static_dir)
    app.register_blueprint(blueprint=bp, url_prefix='/app')
    # 127.0.0.1:8000/app/login/

    # 设置密钥
    app.config['SECRET_KEY'] = 'secret_key'
    # 使用redis存储信息
    app.config['SESSION_TYPE'] = 'redis'

    # 访问redis,不写下句则默认访问本地redis,即127.0.0.1:6379
    app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1',
                                              port='6379',
                                              password='')

    # 定义前缀
    app.config['SESSION_KEY_PREFIX'] = 'flask'

    # 初始化Session
    # 方式1
    Session(app)
    # 方式2
    # se = Session()
    # se.init_app(app)
    return app
Example #6
0
def drop_userdb(user):
    Session = sessionmaker(bind=engine)
    s = Session()
    r = s.query(User).filter_by(username=user)
    if r:
        result = r.first()
        if result:
            s.delete(result)
    s.commit()
Example #7
0
def getHours():
    session = Session()
    try:
        start = date_parse(request.args.get("start","1979-04-01T07:00:00.000Z"))
    except:
        start = date_parse("1979-04-01T07:00:00.000Z")
    end = request.args.get("stop",None)
    try:
        if end:end = date_parse(end)
    except:
        end = None
    print start
    user_id = current_user.id
    return HoursDict(TimeLogged.times_between(start,end,user_id=user_id))
Example #8
0
def create_app(config_name):
    # 模块文件夹 用户模块profile : new: 登陆注册模块:admin
    app = Flask(__name__)
    config_class = config_dict["config_name"]
    app.config.from_object(config_class)

    db = SQLAlchemy(app)

    redis_store = StrictRedis(host=config_class.REDIS_HOST, port=config_class.REDIS_PORT)
    # 给项目添加防护机制
    CSRFProtect(app)

    Session(app)

    return app
Example #9
0
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__, instance_relative_config=True)
    app.secret_key = 'learning'
    app.config['SESSION_TYPE'] = 'filesystem'
    sess = Session()

    # app.config.from_mapping(
    #     # a default secret that should be overridden by instance config
    #     SECRET_KEY='dev',
    #     # store the database in the instance folder
    #     DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    # )

    # if test_config is None:
    #     # load the instance config, if it exists, when not testing
    #     app.config.from_pyfile('config.py', silent=True)
    # else:
    #     # load the test config if passed in
    #     app.config.update(test_config)

    # # ensure the instance folder exists
    # try:
    #     os.makedirs(app.instance_path)
    # except OSError:
    #     pass

    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    # register the database commands
    from project import db
    db.init_app(app)

    # # apply the blueprints to the app
    from project import routes
    app.register_blueprint(routes.bp)
    # app.register_blueprint(blog.bp)

    # make url_for('index') == url_for('blog.index')
    # in another app, you might define a separate main index here with
    # app.route, while giving the blog blueprint a url_prefix, but for
    # the tutorial the blog will be the main index
    app.add_url_rule('/', endpoint='index')

    return app
Example #10
0
import os
from time import sleep
from multiprocessing import Process
import configparser
from spotify_background_color import SpotifyBackgroundColor
from current_spotify_playback import CurrentSpotifyPlayback, NoArtworkException
from led_controller import LEDController

app = Flask(__name__)

CLIENT_ID = os.environ.get('SPOTIPY_CLIENT_ID')
CLIENT_SECRET = os.environ.get('SPOTIPY_CLIENT_SECRET')
REDIRECT_URI = os.environ.get('SPOTIPY_REDIRECT_URI')
REFRESH_TOKEN = os.environ.get('SPOTIPY_REFRESH_TOKEN')

Session(app)


@app.route('/')
def main():
    return render_template('index.html')


@app.route('/spotify')
def spotify():
    p = Session['process']
    if not p.is_alive():
        p = Process(target=main_spotify, args=())
        p.start()
    return render_template('spotify.html')
Example #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request, redirect, Session
from werkzeug.security import generate_password_hash, check_password_hash
from Client import *
from Chambre import *
from reservation import *


app = Flask(__name__)
session = Session()
session.__init__()


@app.route("/")
def index():
    return render_template('hotel.html')


@app.route("/admin", methods=['GET', 'POST'])
def admin():
    if request.method == 'POST':
        session['nom'] = request.values.get("nom")
        session['type'] = "Admin"
        return render_template('hotel.html', session = session)
    else:
        return render_template('index.html')


@app.route("/admin/stats")
def stats():
Example #12
0
import scipy
import matplotlib.pyplot as plt
from keras.preprocessing import image
from flask import Flask, request, redirect, flash, url_for, Session
from werkzeug.utils import secure_filename
from keras.applications.mobilenetv2 import preprocess_input

# Upload settings
UPLOAD_FOLDER = '/uploads'
if not os.path.exists(UPLOAD_FOLDER):
    os.mkdir(UPLOAD_FOLDER)
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
DECISION_THRESHOLD = 0.5

# Flask settings
sess = Session()
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SESSION_TYPE'] = 'filesystem'
app.secret_key = '07145d5b193b4d3b909f218bccd65be7'

# Training args
with open(os.path.join(training.MODEL_SAVE_DIR, training.CONFIG_FILE_NAME),
          'r') as f:
    model_args = json.load(f)
    image_size = int(model_args['image_size'])

# Model loading
top_model, graph = nail_model.get_top_model()
top_model.load_weights(
    os.path.join(model_args['model_save_dir'], model_args['model_filename']))
 def open_session(self, request):
     key = self.secret_key
     if key is not None:
         value = request.values.get(self.session_url_key, '')
         return Session.unserialize(value, key)
Example #14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import Flask, redirect, url_for, request, render_template, abort, flash, get_flashed_messages
from flask import Session
from flask.ext.cache import Cache

app = Flask(__name__)
cache = Cache(app, config = {"CACHE_TYPE":"simple"})
session = Session()

from decorators import login_required

from models.school import School
from models.user import Student, Teacher


@app.route("/")
def home():
	if session.get("username") is not None:
		username = session["username"]
		#values = {}
		#return render_template("task.html", **values)
		return render_template("task.html")
	else:
		return render_template("introduction.html")


@app.route("/login", methods = ["GET"])
def login_get():
	if session.get("username") is not None:
Example #15
0
import os
from flask import Flask, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from flask import flash
from flask import Session
from dominant_color import *
#from detect_dress import *
from flask import Markup

UPLOAD_FOLDER = 'flaskr/static'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app = Flask(__name__)
sess = Session()
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = '1001rs'


def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':

        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
Example #16
0
# Mongo Configuration for production
app.config['MONGO_DBNAME'] = settings.MONGO_DBNAME
app.config['MONGO_HOST'] = settings.MONGO_HOST
app.config['MONGO_PORT'] = settings.MONGO_PORT
app.config['MONGO_USERNAME'] = settings.MONGO_USERNAME
app.config['MONGO_PASSWORD'] = settings.MONGO_PASSWORD
app.config['MONGO_AUTH_MECHANISM'] = settings.MONGO_AUTH_MECHANISM

#website global variables
title = "DuckHacker"
post_questions = {}  # dictionary to contain the question asked to user
user = None
App_root = os.path.dirname(
    os.path.abspath(__file__))  # get file path for files to be uploaded
session = Session()  #handle sessions

mongo = PyMongo(app)


@app.route('/', methods=['GET', 'POST'])
def index():
    return render_template('Login.html', title=title)


@app.route('/videos', methods=['GET'])
def get_videos_containing_title():
    """Method returns videos that match the search title in the database"""
    output = []
    name = request.args.get('name')
    data = mongo.db.Videos.find({'title': name})  # Use find, not find_one
Example #17
0
 def session(self):
     if SessionViewMixin._session is None:
         SessionViewMixin._session = Session()
     return SessionViewMixin._session
Example #18
0
from flask import jsonify, render_template, Flask, Session, request
from serial import Serial
from functions import *
from secrets import *
from time import sleep, time
from gpiozero import PWMLED
import json
from collections import deque
##Rember to run sudo pigpiod##
import pigpio

session_data = Session()
session_data['last_temp'] = 0
session_data['last_flow'] = 0
session_data['last_humidity'] = 0
session_data['last_level'] = 0
session_data['chart_layout'] = {
    'width': 365,
    'height': 175,
    'margin': {
        'l': 10,
        'r': 10,
        't': 40,
        'b': 10,
        'pad': 10
    },
    'paper_bgcolor': "rgba(0,0,0,0)"
}
session_data['temp_layout'] = {
    "Title": 'Temperature',
    "Gauge_Min": 0,
Example #19
0
def add_user(user, passw):
    Session = sessionmaker(bind=engine)
    s = Session()
    new_user = User(username=user, password=passw, answers=int(0))
    s.add(new_user)
    s.commit()