Exemplo n.º 1
0
 def test_sets_db_config_to_prod_if_in_prod_environment(self):
     os.environ['FILEZAP_ENV'] = config_manager.PROD_ENV
     config = config_manager.get_config()
     self.assertEqual(config.get('USER_DB_TABLE'),
                      config_manager._PROD_USER_DB_TABLE)
     self.assertEqual(config.get('FILE_DB_TABLE'),
                      config_manager._PROD_FILE_DB_TABLE)
     os.environ.pop('FILEZAP_ENV')
Exemplo n.º 2
0
 def test_defaults_db_config_to_dev(self):
     config = config_manager.get_config()
     self.assertEqual(config.get('USER_DB_TABLE'),
                      config_manager._DEV_USER_DB_TABLE)
     self.assertEqual(config.get('FILE_DB_TABLE'),
                      config_manager._DEV_FILE_DB_TABLE)
Exemplo n.º 3
0
 def test_max_file_size_is_configured_by_environment_variable(self):
     os.environ['FILEZAP_MAX_FILE_SIZE'] = '4000000'
     config = config_manager.get_config()
     self.assertEqual(config.get('FILEZAP_MAX_FILE_SIZE'), 4000000)
     os.environ.pop('FILEZAP_MAX_FILE_SIZE')
Exemplo n.º 4
0
 def test_max_file_size_defaults_to_zero(self):
     config = config_manager.get_config()
     self.assertEqual(config.get('FILEZAP_MAX_FILE_SIZE'), 0)
Exemplo n.º 5
0
 def test_user_registration_is_enabled_by_environment_variable(self):
     os.environ['USER_REGISTRATION_ENABLED'] = 'True'
     config = config_manager.get_config()
     self.assertEqual(config.get('USER_REGISTRATION_ENABLED'), True)
     os.environ.pop('USER_REGISTRATION_ENABLED')
Exemplo n.º 6
0
 def test_user_registration_is_disabled_by_default(self):
     config = config_manager.get_config()
     self.assertEqual(config.get('USER_REGISTRATION_ENABLED'), False)
Exemplo n.º 7
0
 def _init_user_manager(self):
     config = config_manager.get_config()
     user_data_store = user_datastore.UserDataStore(config)
     file_data_store = file_datastore.FileDataStore(config)
     self.user_manager = UserManager(user_data_store, file_data_store)
Exemplo n.º 8
0
from flask import Blueprint, render_template, request, redirect, current_app
from flask_login import login_required, logout_user, current_user

import src.config_manager as config_manager
import src.user_mgmt.controller as controller
import src.user_mgmt.model as model

blueprint = Blueprint(__name__, 'user_mgmt')
config = config_manager.get_config()


@blueprint.route('/register', methods=['GET'])
def register_view():
    if config.get('USER_REGISTRATION_ENABLED'):
        return render_template('register.html')
    return render_template('no_register.html')


@blueprint.route('/register', methods=['POST'])
def register_post():
    if config.get('USER_REGISTRATION_ENABLED'):
        username = request.form.get('username').strip().lower()
        if not username.isalpha():
            return render_template(
                'register.html',
                msg=
                f'Invalid username. Enter only letters, no numbers or symbols')
        password = request.form.get('password')
        user_mgmt_controller = _get_controller()
        try:
            user_mgmt_controller.register_user(username, password)