示例#1
0
def test_jwt_for_invalid_user(clean_test_client, test_db):
    bad_user_jwt = create_jwt(user_id=1000)
    response = clean_test_client.delete(
        "/api/talk/1",
        headers={JWT_HEADER_KEY: bad_user_jwt},
    )
    assert response.status_code == 401
示例#2
0
def test_expired_jwt(clean_test_client, test_db):
    expired_jwt = create_jwt(user_id=1, expiration_date="2020-02-02")
    response = clean_test_client.delete(
        "/api/talk/1",
        headers={JWT_HEADER_KEY: expired_jwt},
    )
    assert response.status_code == 401
    assert response.json == {"message": "Login expired"}
示例#3
0
    def post(self):
        """Return username and userID for valid login; error for invalid."""

        try:
            args = userLoginSchema().load(request.json)
        except ValidationError as e:
            return {"message": f"incorrect arguments: {e}"}, 400

        user = UserModel.validate_user(args["username"], args["password"])

        if user is None:
            username = args["username"]
            return {"message": f"Incorrect login for user {username}"}, 400

        # if we got to here, login is legit
        token = create_jwt(user.id)

        return {
            "token": token,
            "username": user.username,
            "id": user.id,
        }, 200
示例#4
0
from flask_sqlalchemy import SQLAlchemy
from os import environ as env

from app.admin import create_admin
from app.app import create_app
from app.db import create_db
from app.jwt import create_jwt
from app.mail import create_mail
from app.models import Busket, Category, Good, User, Order

PORT = int(env.get("PORT", 5000))

app: Flask = create_app()
CORS(app)
db: SQLAlchemy = create_db(app)
jwt: JWTManager = create_jwt(app)
manager: Manager = Manager(app)
migrate: Migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
admin: Admin = create_admin(app)
mail: Mail = create_mail(app)


@manager.command
def run():
    system('python manage.py db upgrade')
    app.run(debug=True, host="0.0.0.0", port=PORT)


if __name__ == '__main__':
    manager.run()