Пример #1
0
def token_POST():
    errors = email_password_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = sign_up_schema.dump(request.json)

    user = get_user_by_email(parsed_schema["email"])

    if not user:
        abort(404)

    if not verify_password(user.password, parsed_schema["password"]):
        return build_400_error_response({
            "password": [
                "Incorrect password.",
            ],
        })

    if not user.active:
        return build_400_error_response({
            "email": [
                "This email has not been verified.",
            ],
        })

    return jsonify(
        access_token=create_fresh_user_access_token(user),
        refresh_token=create_user_refresh_token(user),
        user_id=str(user.id),
    ), 200
Пример #2
0
 def test_EmailPasswordSchema_trims_email(self):
     email = fake.email()
     body = get_mock_email_password_body(email=f"  {email}  ")
     errors = email_password_schema.validate(body)
     assert not errors
     dumped = email_password_schema.dump(body)
     assert dumped["email"] == email
Пример #3
0
 def test_EmailPasswordSchema_blank_email(self):
     body = get_mock_email_password_body(email=" ")
     errors = email_password_schema.validate(body)
     assert errors == {
         "email": [
             "Missing data for required field.",
         ],
     }
Пример #4
0
 def test_EmailPasswordSchema_no_password(self):
     body = get_mock_email_password_body()
     del body["password"]
     errors = email_password_schema.validate(body)
     assert errors == {
         "password": [
             "Missing data for required field.",
         ],
     }
Пример #5
0
 def test_EmailPasswordSchema_invalid_email(self):
     email = fake.sentence()
     body = get_mock_email_password_body(email=email)
     errors = email_password_schema.validate(body)
     assert errors == {
         "email": [
             "Not a valid email address.",
         ],
     }
Пример #6
0
 def test_EmailPasswordSchema_unrecognised_field(self):
     body = get_mock_email_password_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not email_password_schema.validate(body)
     assert key not in email_password_schema.dump(body)