def __init__(self, db_name: str, configuration: dict, uri: str = 'mongodb://127.0.0.0:27017') -> None: self.db_name = db_name self.uri = uri self.client = pymongo.MongoClient(self.uri) self.database = self.client[self.db_name] self.logger = Logging.create_rotating_log(module_name=__name__, logging_directory=configuration['logging_directory']) self.logger.debug('Create DB instance: {}'.format(self))
from flask import Blueprint, request, session, url_for, redirect, render_template from pricing.src.models.users.user import User import pricing from pricing.src.common.logging_base import Logging import pricing.src.models.users.errors as user_errors logger = Logging.create_rotating_log( module_name=__name__, logging_directory=pricing.configuration['logging_directory']) user_blueprint = Blueprint(name='users', import_name=__name__) @user_blueprint.route('/login', methods=['GET', 'POST']) def login_user(): logger.debug( 'Received HTTP request to user login endpoint with method "{}"'.format( request.method)) if request.method == 'POST': email = request.form['email'] password_hashed = request.form['password'] logger.debug('Login attempt by user "{}"'.format(email)) try: if User.is_login_valid(email=email, password_hashed=password_hashed, configuration=pricing.configuration): session['email'] = email return render_template( 'show_message.html', message='Welcome, {}. Use the pane above to navigate'. format(email)) except user_errors.UserError as e: