Ejemplo n.º 1
0
def main():
    with open('data.pkl', 'rb') as f:
        global users
        users = pickle.load(f)

    updater = Updater(TOKEN)  # TOKEN is not available in this code. (you need to put your own)

    dispatcher = updater.dispatcher

    # connect command 'start' to c_start function
    dispatcher.add_handler(CommandHandler('start', c_start))
    dispatcher.add_handler(MessageHandler(Filters.text, answer_question))
    dispatcher.add_handler(CallbackQueryHandler(answer_question_2))

    # conversation_handler = ConversationHandler(
    #     entry_points=[CommandHandler('question', c_question)],
    #
    #     states={
    #         REPLY: [MessageHandler(Filters.text, answer_question)]
    #     },
    #
    #     fallbacks=[CommandHandler('cancel', c_cancel)]
    # )
    #
    # dispatcher.add_handler(conversation_handler)

    admin.init(dispatcher)

    dispatcher.add_error_handler(error_handler)

    # start the bot
    updater.start_polling()
    updater.idle()
Ejemplo n.º 2
0
def init_app(loop, name):
    db = loop.run_until_complete(
        SADataBase.connect(config.DB_CONFIG, config.DB_CHARSET, loop))
    app = web.Application()
    app['db'] = db
    app.cleanup_ctx.append(context)
    cr_app = web.Application()
    shift_start_time = datetime.now() - timedelta(minutes=5)
    commands_app = commands.init(
        db,
        cr_config=config.CR_CONFIG,
        connection_timeout=config.COMMANDS_CONFIG['EXECUTION_WAITING_TIMEOUT'],
        test_without_hardware=True,
        shift_start_time=shift_start_time,
        loop=loop)

    cr_app.add_subapp('/cr_proccessing/', commands_app)
    app_admin = admin.init()
    cr_app.add_subapp('/admin/', app_admin)
    cr_app.cleanup_ctx.append(cr_app_context)
    # орпределяем корневой url до приложения кассы и его имя, они будут использоваться при фиксировании разрешений
    # на доступ к ресурсам в базе данных (чтобы не было зависимости от корневого url, который может меняться)
    cr_app['cr_app_name'] = 'cr2'
    cr_app['cr_app_prefix'] = '/cr2/'
    app.add_subapp(cr_app['cr_app_prefix'], cr_app)
    return app
Ejemplo n.º 3
0
def create(extra_config=None, load_mongo=True, load_admin=True,
           load_rest_api=True, load_service_api=True):
    """Create a new Flask application object.

    The default configuration is loaded from authz.default_settings. You can
    override any of the settings by setting the AUTHZ_SETTINGS_OVERRIDE env var
    to point to the configuration file.

    You can also specify the extra_config argument to override the already
    loaded settings.

    Befire returning the app instance, all the necessary blueprints are
    registered.
    """
    app = Flask("authz")

    app.config.from_object('authz.default_settings')
    app.config.from_envvar('AUTHZ_SETTINGS_OVERRIDE', silent=True)

    if extra_config:
        app.config.from_object(extra_config)

    if load_mongo or load_admin or load_rest_api or load_service_api:
        mongo.init_app(app)

    if load_admin:
        openid.init_app(app)

        import admin
        admin.init(app)

    if load_rest_api:
        from api import rest_endpoints
        app.register_blueprint(rest_endpoints, url_prefix='/api/1.0')

    if load_service_api:
        from api import authorize_endpoints, authenticate_endpoints
        app.register_blueprint(authorize_endpoints, url_prefix='/authorize')
        app.register_blueprint(
            authenticate_endpoints,
            url_prefix='/authenticate')

    return app
Ejemplo n.º 4
0
from flask import request, url_for, redirect
from wtforms import form, fields, validators
from wtforms.widgets import TextArea
from wtforms.fields import TextAreaField
from flask_admin.contrib import sqla
from flask_admin import helpers, expose, BaseView
from flask_admin.form.upload import FileUploadField
import flask_admin as flask_admin
import flask_login as login
from werkzeug.security import check_password_hash

app = Flask(__name__.split('.')[0], static_url_path='/static')
app.config.from_object('config')
db = SQLAlchemy(app)
babel = Babel(app)

#test ajout db
db.create_all()

# Florin - patch : Flask-babelex
babel.domain = 'flask_user'
babel.translation_directories = 'translations'
application = app

#import views
import models
import views
import admin

admin.init()
Ejemplo n.º 5
0
        size = int(input())
        if size > 0:
            break
        else:
            print("try again")
else:
    size = 0

# run the simulation 200 times
for n in range(200):

    # Indicate the number of the iteration
    print("#", n, " iteration")

    # Initialize the user list and intimacy map coordinates
    init()
    init_graph()
    init_stat()

    # Initialize users
    beginning(init_S, init_T, alloc, cred, size)

    # Plot the initial snapshot of the system
    visualization('Begin.pdf')

    # Schedule interactions for all active users
    makeComb()
    # Run the simulation
    Runsim(sim_time)  # The time of simulation can be adjusted

    # Derive the statistics of the network (to be extended after the checkpoint)
Ejemplo n.º 6
0
from flask import *
import flask_login

from models.mlab import *
from models.portfolio import *
from models.users import User
from models.projects import Project
import admin
import tempfile
import base64

app = Flask(__name__)
app.secret_key = "fE226QUKwZ5yta8yzFhpnmEdIfsbvmXjTc2qwkOn"
login_manager = flask_login.LoginManager()
login_manager.init_app(app)
admin.init(app)
mlab_connect()


@app.route('/')
def index():
    return render_template("index.html", projects=Project.objects)


@app.route('/login', methods=["GET", "POST"])
def login():
    if request.method == 'GET':
        return render_template("login.html")
    elif request.method == 'POST':
        form = request.form
        email = form["email"]
Ejemplo n.º 7
0
    def check(self):
        """
        check login function
        """
        # fetch login type
        tmp_login_type = self.login_type_content.get()

        # fetch id
        tmp_id = self.id_content.get()

        # fetch password
        tmp_passwd = self.passwd_content.get()

        # strip id and password
        tmp_id = tmp_id.strip()
        tmp_passwd = tmp_passwd.strip()

        # check if id or passwd is empty
        if '' in [tmp_id, tmp_passwd, tmp_login_type]:
            tkinter.messagebox.showinfo('Error', 'Please input your info!')
            return

        # try to connect to bookdb
        try:
            self.db_connect = pymysql.connect('localhost', 'common_user',\
                'common_just','bookdb')
            self.cursor = self.db_connect.cursor()
        # unable to connect the database
        except pymysql.OperationalError:
            tkinter.messagebox.showinfo('Error', 'Database connect error!')
            return
        
        # two login types
        if tmp_login_type == 'admin':
            sql = "select a_passwd from admin where a_id='%s'" % tmp_id
        elif tmp_login_type == 'reader':
            sql = "select r_passwd from reader where r_id='%s'" % tmp_id
        else:
            self.db_connect.close()
            tkinter.messagebox.showinfo('Error','Invalid login type')
            return

        # execute the sql and fetch the result
        try:
            self.cursor.execute(sql)
            data = self.cursor.fetchall()
        # deal with sql operations error
        except (pymysql.InternalError, pymysql.ProgrammingError):
            self.db_connect.close()
            tkinter.messagebox.showinfo('Error', 'sql query error')
            return
            
        # check if the password is right(password should be encrypted in practice)
        if len(data) == 0:
            self.db_connect.close()
            tkinter.messagebox.showinfo('Error', 'User doesn\'t exists!')
            return
        elif data[0][0] == tmp_passwd:
            self.db_connect.close()
            # go to according GUI
            if tmp_login_type == 'admin':
                # destory login GUI
                self.root.destroy()

                # enter admin GUI
                admin.init(tmp_id)
            else:
                # destory login GUI
                self.root.destroy()

                # enter reader GUI
                reader.init(tmp_id)
        # password is wrong  
        else:
            self.db_connect.close()
            tkinter.messagebox.showinfo('Error','Wrong password!')
            return
Ejemplo n.º 8
0
def main():
    global engine
    engine = global_init('D:\\Projects\\SlipperBot\\Server\\develop.sqlite3')
    admin.init()
    resources.init_all()
    app.run(host='localhost', port=5000, debug=True)
Ejemplo n.º 9
0
def adminUser(conn, c):
    admin.init(conn, c)
    return 0