Ejemplo n.º 1
0
def make_signup_controller():
    salt = b"$2b$12$9ITqN6psxZRjP8hN04j8Be"
    account_collection = get_collection("accounts")
    bcrypt_adapter = BcryptAdapter(salt)
    account_mongo_repo = AccountMongoRepo(account_collection)
    db_add_account = DbAddAccount(bcrypt_adapter, account_mongo_repo)
    return SignUpController(db_add_account, make_signup_validation())
Ejemplo n.º 2
0
def make_signup_validation():
    signup_schema = Schema(
        dict(
            name=And(str, len, error="Invalid key: 'name'"),
            email=And(str, len, error="Invalid key: 'email'"),
            password=And(
                And(str, len, error="Invalid key: 'password'"),
                And(
                    lambda s: len(s) > 5,
                    error="Invalid key: 'password minimum 6 characters'",
                ),
            ),
            password_confirmation=And(
                And(str, len, error="Invalid key: 'password_confirmation'"),
            ),
        )
    )
    return ValidationComposite(
        [
            RequiredFieldsValidation(signup_schema, "signup"),
            CompareFieldsValidation("password", "password_confirmation"),
            EmailValidation(
                "email", EmailValidatorAdapter(check_mx=False, skip_smtp=True)
            ),
            UniqueFieldValidation("email", MongoDbAdapter(get_collection("accounts"))),
        ]
    )
Ejemplo n.º 3
0
    def wrapper_handler(*args, **kwargs):
        response = func(*args, **kwargs)
        if response.status_code == 500:
            log_mongo_repo = LogMongoRepo(get_collection("logs"))
            log_mongo_repo.log(response.body["traceback"])
            del response.body["traceback"]

        return response
def make_auth_middleware(role: str = None):
    account_collection = get_collection("accounts")
    load_account_by_id_repo = AccountMongoRepo(account_collection)
    decrypter = JwtAdapter(
        secret=env.JWT_SECRET_KEY,
        expiration_time=datetime.utcnow() + timedelta(hours=env.JWT_EXPIRATION_TIME),
        algorithm="HS256",
    )
    db_load_account_by_token = DbLoadAccountById(decrypter, load_account_by_id_repo)

    return AuthMiddleware(load_account_by_id=db_load_account_by_token, role=role)
Ejemplo n.º 5
0
def make_login_controller():
    salt = b"$2b$12$9ITqN6psxZRjP8hN04j8Be"
    bcrypt_adapter = BcryptAdapter(salt)
    jwt_adapter = JwtAdapter(
        secret=env.JWT_SECRET_KEY,
        expiration_time=datetime.utcnow() +
        timedelta(hours=env.JWT_EXPIRATION_TIME),
        algorithm="HS256",
    )
    account_mongo_repo = AccountMongoRepo(get_collection("accounts"))
    db_authentication = DbAuthentication(
        load_account_by_email_repo=account_mongo_repo,
        hash_comparer=bcrypt_adapter,
        encrypter=jwt_adapter,
    )
    return LoginController(db_authentication, make_login_validation())
Ejemplo n.º 6
0
def test_should_return_a_mongodb_collection():
    collection = get_collection("test")
    assert collection
def make_load_surveys_controller():
    survey_collection = get_collection("surveys")
    load_surveys_repo = SurveyMongoRepo(survey_collection)
    db_load_surveys = DbLoadSurveys(load_surveys_repo)
    return LoadSurveysController(db_load_surveys)
def make_add_survey_controller():
    survey_collection = get_collection("surveys")
    survey_mongo_repo = SurveyMongoRepo(survey_collection)
    db_add_survey = DbAddSurvey(survey_mongo_repo)
    return AddSurveyController(make_add_survey_validation(), db_add_survey)