コード例 #1
0
def login_process():
    try:
        user = UserDAO.read(request.form['email'], request.form['password'])
        session['auth_token'] = Authentication.encode_auth_token(
            current_app.config['SECRET_KEY'], user.id)
        return redirect(url_for('user_controller.index'))
    except Exception as e:
        return redirect(url_for('home_controller.index', text=['warning', e]))
コード例 #2
0
def add_file():
    file = request.files['file']
    try:
        user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token']))
        new_file = FileDAO.create(file, user)
        return jsonify({'name': new_file.name, 'added_on': new_file.added_on.__str__()}), 201
    except Exception as e:
        return jsonify({'error': e.__str__()}), 500
コード例 #3
0
def add_file():
    file = request.files['filePath']
    try:
        user = UserDAO.get(
            Authentication.decode_auth_token(current_app.config['SECRET_KEY'],
                                             session['auth_token']))
        FileDAO.create(file, user)
        return redirect(url_for('user_controller.index'))
    except Exception as e:
        return redirect(url_for('user_controller.index', error=e))
コード例 #4
0
def delete_files():
    try:
        data = json.loads(request.get_data().decode('utf-8'))
        user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token']))
        data_entities = []
        for name in data:
            data_entities.append(FileDAO.read(name, user.id))
        FileDAO.delete(data_entities, user.home_catalog)
        return jsonify({'deleted_files': data}), 200
    except Exception as e:
        return jsonify({'error': e.__str__()}), 500
コード例 #5
0
def change_file(name):
    try:
        data = json.loads(request.get_data().decode('utf-8'))
        user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token']))
        file_to_update = FileDAO.read(name, user.id)
        file_to_update.name = data[0]
        FileDAO.update(file_to_update, user, 'File name: ' + name + ' to ' + data[0] + ' updated')
        return jsonify({'old_name': name, 'new_name': data[0]}), 200
    except Exception as e:
        print(e)
        return jsonify({'error': e.__str__()}), 500
コード例 #6
0
def get_files():
    try:
        user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token']))
        files = FileDAO.get_all(user.id)
        file_list = []
        for file in files:
            file_list.append({'name': file.name, 'added_on': file.added_on.__str__()})

        return jsonify({'files': file_list}), 200
    except Exception as e:
        return jsonify({'error': e.__str__()}), 500
コード例 #7
0
def index(text=None):
    user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token']))
    try:
        login = user.login.split('@')[0]
        files = FileDAO.get_all(user.id)
        current_year = datetime.datetime.now().year.__str__()

        if text:
            text = ast.literal_eval(text)
        return render_template('userPanel.html', user=login, home_catalog=user.home_catalog, files=files,
                               year=current_year, text=text)
    except Exception as e:
        return redirect(url_for('home_controller.logout', text=['warning', e.__str__()]))
コード例 #8
0
def register_process():
    if request.form['passwordRegister'] == request.form['conf_password']:
        try:
            user = UserDAO.create(request.form['emailRegister'],
                                  request.form['passwordRegister'])
            session['auth_token'] = Authentication.encode_auth_token(
                current_app.config['SECRET_KEY'], user.id)
            return redirect(url_for('user_controller.index'))
        except Exception as e:
            return redirect(url_for('home_controller.index', error=e))
    else:
        return redirect(
            url_for('home_controller.index', error='Passwords don\'t match.'))
コード例 #9
0
ファイル: Config.py プロジェクト: kuras120/FlaskTemplateSite
def init_debug(app):
    try:
        print('Debug data initialization...')
        UserDAO.delete(UserDAO.get_all())
        # Add users
        UserDAO.create('*****@*****.**', 'admin1')
        UserDAO.create('*****@*****.**', 'user1')
        print('New data created.')

        print('Initialization completed.')
    except Exception as e:
        print('Error: ' + e.__str__())
コード例 #10
0
def delete_files():
    try:
        data = json.loads(
            urllib.parse.unquote(request.get_data('files').decode('utf-8')))
        user = UserDAO.get(
            Authentication.decode_auth_token(current_app.config['SECRET_KEY'],
                                             session['auth_token']))
        data_entities = []
        for name in data:
            data_entities.append(FileDAO.read(name, user.id))
        FileDAO.delete(data_entities, user.home_catalog)
        return redirect(url_for('user_controller.index'))
    except Exception as e:
        return redirect(url_for('user_controller.index', error=e))
コード例 #11
0
def index(error):
    user = UserDAO.get(
        Authentication.decode_auth_token(current_app.config['SECRET_KEY'],
                                         session['auth_token']))
    try:
        login = user.login.split('@')[0]
        catalog = user.home_catalog
        files = FileDAO.get_all(user.id)
        current_year = datetime.datetime.now().year.__str__()
        return render_template('userPanel.html',
                               user=login,
                               home=catalog,
                               files=files,
                               year=current_year,
                               error=error)
    except Exception as e:
        return redirect(url_for('home_controller.logout', error=e))
コード例 #12
0
def queue_task():
    try:
        user_id = Authentication.decode_auth_token(
            current_app.config['SECRET_KEY'], session['auth_token'])
        user = UserDAO.get(user_id)
        directory = os.path.join('Project/Client/static/DATA',
                                 user.home_catalog)
        task_name = secure_filename(request.form['taskName'])
        resolution = ast.literal_eval(request.form['resolutionSelect'])
        file = request.form['fileSelect']

        if not any(x in os.listdir(directory)
                   for x in [task_name, task_name + '.mp4']):
            with Connection(redis.from_url(current_app.config['REDIS_URL'])):
                q = Queue(default_timeout=3600)
                task = q.enqueue(raytracing_task,
                                 directory,
                                 resolution,
                                 file,
                                 task_name,
                                 result_ttl=86400)

                task.meta['task_name'] = task_name
                task.meta['file_name'] = file
                task.meta['token'] = Authentication.decode_auth_token(
                    current_app.config['SECRET_KEY'], session['auth_token'])
                task.save_meta()

            response_object = {
                'status': 'success',
                'data': {
                    'task_id': task.get_id(),
                    'task_name': task_name,
                    'task_file': file
                }
            }
            return jsonify(response_object), 202
        else:
            logging.getLogger('logger').warning('Filename already exists.')
            return jsonify('Filename already exists.'), 500

    except Exception as e:
        logging.getLogger('error_logger').exception(e)
        return jsonify({'error': e.__str__()}), 500
コード例 #13
0
def index(error):
    current_date = datetime.datetime.now().date().strftime('%B %d, %Y')
    likes = Format.human_format(likes_counter.value)
    current_year = datetime.datetime.now().year.__str__()
    login = None
    if 'auth_token' in session:
        error = None
        try:
            login = UserDAO.get(
                Authentication.decode_auth_token(
                    current_app.config['SECRET_KEY'],
                    session['auth_token'])).login.split('@')[0]
        except Exception as e:
            session.pop('auth_token', None)
            return redirect(url_for('home_controller.index', error=e))

    return render_template('index.html',
                           date=current_date,
                           year=current_year,
                           user=login,
                           likes=likes,
                           error=error)