async def get_current_user(self) -> Union[Session, None]: """ Do not use this method to get the current user session, use the property `self.current_user` instead. """ session_hash = self.session_hash ip = self.request.remote_ip if session_hash is None: return None dao = UsersDao(self.db) session = await dao.get_session_by_hash(session_hash) if session is None: # Session hash is not in the database self.clear_session_cookie() return None max_idle_days = Config.get_config().getint("Session", "max_idle_days") # Check if session is older than max configured idle days, if it is; sign out if session.last_used < datetime.now() - timedelta(days=max_idle_days): await dao.remove_session(session_hash) self.clear_session_cookie() return None new_session = await dao.update_session(session_hash, ip) return new_session
class TestConfig(unittest.TestCase): """Test Config""" def setUp(self): self.config = Config() def test_default_config(self): """Test init default config""" self.assertEqual(DEFAULT_CONFIG_SHAPE, self.config.shape) self.assertEqual(DEFAULT_CONFIG_SIZE, self.config.size) self.assertEqual(MAXIMUM_CONFIG_THICKNESS, self.config.max_thickness) self.assertEqual(MINIMUM_CONFIG_THICKNESS, self.config.min_thickness) self.assertEqual(DEFAULT_CONFIG_BORDER, self.config.use_border) self.assertEqual(DEFAULT_CONFIG_BORDER_THICKNESS, self.config.border_thickness) self.assertEqual(DEFAULT_CONFIG_CURVE, self.config.curve) self.assertEqual(DEFAULT_CONFIG_FORMAT, self.config.format) def test_get_config(self): actual_config = self.config.get_config() expected_config = Config() self.assertEqual(expected_config.size, actual_config.size) self.assertEqual(expected_config.max_thickness, actual_config.max_thickness) self.assertEqual(expected_config.min_thickness, actual_config.min_thickness) self.assertEqual(expected_config.use_border, actual_config.use_border) self.assertEqual(expected_config.border_thickness, actual_config.border_thickness) self.assertEqual(expected_config.curve, actual_config.curve) self.assertEqual(expected_config.format, actual_config.format)
def get_connection(connection): config = Config() config = config.get_config() if connection.__db is None: connection.__db = connect(config['mongodb']['db'], host=config['mongodb']['host'], port=config['mongodb']['port']) return connection.__db
async def post(self): email = self.get_argument("email") name = self.get_argument("name") password = self.get_argument("password") password2 = self.get_argument("password2") if email is None: self.render("sign-up.html", error="E-mail saknas") return elif name is None: self.render("sign-up.html", error="Namn saknas") return elif password is None or password2 is None: self.render("sign-up.html", error="Lösenord saknas") return elif password != password2: self.render("sign-up.html", error="Lösenorden matchar inte varandra") return config = Config.get_config() max_email_length = config.getint("Users", "max_email_length") max_name_length = config.getint("Users", "max_username_length") max_password_length = config.getint("Users", "max_password_length") min_password_length = config.getint("Users", "min_password_length") if len(email) > max_email_length: max = max_email_length.__str__() self.render("sign-up.html", error="E-mail adressen får inte vara längre än " + max + " tecken") return elif len(name) > max_name_length: max = max_name_length.__str__() self.render("sign-up.html", error="Namnet får inte vara längre än " + max + " tecken") return elif len(password) > max_password_length: max = max_password_length.__str__() self.render("sign-up.html", error="Lösenordet får inte vara längre än " + max + " tecken") return elif len(password) < min_password_length: min = min_password_length.__str__() self.render("sign-up.html", error="Lösenordet måste minst vara " + min + " tecken långt") return dao = UsersDao(self.db) user = await dao.create_user(name, email, password) if user is None: self.render("sign-up.html", error="E-mail: " + email + " är redan registrerad") session = await dao.new_session(user.id, self.request.remote_ip) self.set_session_cookie(session.hash) self.redirect("/")
async def send_email(to: str, subject: str, message: str, send_verification: bool = False, verify_link: str = ""): config = Config.get_config() username = config.get("Email", "username") password = config.get("Email", "password") smtp_server = config.get("Email", "smtp_server", fallback="") try: smtp_port = config.getint("Email", "smtp_port", fallback=0) except ValueError as exc: logger.debug(exc.__str__()) logger.warning( "Could not get a value for the SMTP Port, setting it to 0") smtp_port = 0 if smtp_server == "" or smtp_port == 0: return msg = EmailMessage() msg.set_content(message) msg['Subject'] = subject msg['From'] = config.get("Email", "from") msg['To'] = to if send_verification is True and verify_link != "" and verify_link is not None: msg.set_content( message + "\nClick on the following link to confirm your e-mail address: " + config.get("WebServer", "url") + verify_link) elif send_verification is True: logger.warning( '"send_verification" was set to true but no link was provided') logger.debug("SMTP Server: " + smtp_server) logger.debug("SMTP Port: " + smtp_port.__str__()) logger.debug("SMTP Username: "******"SMTP error: could not send mail, " + e.__str__())
def create_app(config_class=None): app_config = config_class or Config.get_config() app.config.from_object(app_config) from app.route import index, auth, exceptions from app.models.schedule import ScheduleModel from app.models.scenario import ScenarioModel from app.models.user import RoleModel, UserModel from app.models.action import RequestActionModel db.init_app(app) migration.init_app(app, db) return app
def start(): logger.info("Starting server...") ioloop = tornado.ioloop.IOLoop.current() config = Config.get_config() # type: ConfigParser options = WebAppOptions() options.debug = config.getboolean("WebServer", "debug", fallback=False) options.https = config.getboolean("WebServer", "https", fallback=False) options.port = config.getint("WebServer", "port") options.cookie_secret = config.get("WebServer", "cookie_secret") options.cert_file = config.get("WebServer", "certs") options.private_file = config.get("WebServer", "private") options.db_username = config.get("PostgreSQL", "username") options.db_password = config.get("PostgreSQL", "password") options.db_hostname = config.get("PostgreSQL", "hostname") options.dbname = config.get("PostgreSQL", "dbname") configure_application(options) asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) ioloop.start()
For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os from os.path import dirname from app.config import Config DEBUG = True BASE_DIR = dirname(dirname(dirname(dirname(os.path.abspath(__file__))))) CONTENT_DIR = os.path.join(BASE_DIR, 'content') config_file = Config.get_config() config_file = config_file['autotrader'] SECRET_KEY = config_file['django_secret'] ALLOWED_HOSTS = config_file['django_hosts'].split(' ') INTERNAL_IPS = config_file['django_internals'].split(' ') # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'stocks',
def main(): config = Config.get_config() debug = config.getboolean("WebServer", "debug", fallback=False) setup_logger(debug) web_server.start()
from app.requests.get_by_id_request import GetByIdRequest from mongoengine import connect, errors from app.models.pdv import Pdv from app.config import Config from wtforms.validators import ValidationError from app.utils.document_util import DocumentUtil from app.utils.point_util import PointUtil from app.utils.multi_polygon_util import MultiPolygonUtil document_util = DocumentUtil() point_util = PointUtil() multi_polygon_util = MultiPolygonUtil() config = Config() config = config.get_config() def test_convert_multi_polygon_valid(): multi_polygon = list() multi_polygon.append('30,20;45,40;10,40;30,20') multi_polygon.append('15,5;40,10;10,20;5,10;15,5') multi_polygon = multi_polygon_util.convert_multi_polygon(multi_polygon) assert multi_polygon.is_valid == True def test_convert_multi_polygon_invalid(): multi_polygon = list() multi_polygon.append('30,20;345,401231230,2120') multi_polygon.append('15as,540qw,123;10,20231;5,10;15,1235') multi_polygon.append('test') multi_polygon = multi_polygon_util.convert_multi_polygon(multi_polygon) assert multi_polygon.is_valid == False