Пример #1
0
from fastapi_users.db import SQLAlchemyUserDatabase

from .models import User
from .schemes import UserDB
from core.db import SessionLocal

users = User.__table__
user_db = SQLAlchemyUserDatabase(UserDB, SessionLocal, users)

SECRET = 'a;klsjipoasdg98pahgapoidsoipsadpasdghposadihg8pagpnausdioh'
Пример #2
0
from fastapi_users.db import SQLAlchemyBaseUserTable, SQLAlchemyUserDatabase
from sqlalchemy import Column, String

from core.db import Base, database
from user_auth.schemas import UserDB


class User(Base, SQLAlchemyBaseUserTable):
    """ Кортеж пользователя """

    name = Column(String, unique=True)


users = User.__table__
user_db = SQLAlchemyUserDatabase(UserDB, database, users)
Пример #3
0
    pass


class FU_UserCreate(fu_models.BaseUserCreate):
    pass


class FU_UserUpdate(FU_User, fu_models.BaseUserUpdate):
    pass


class FU_UserDB(FU_User, fu_models.BaseUserDB):
    pass


user_db = SQLAlchemyUserDatabase(FU_UserDB, fa_users_db, User.__table__)


class SITimezone(BaseModel):
    timezone: Optional[str] = None


class SIHabitica(BaseModel):
    habitica_user_id: Optional[str] = None
    habitica_api_token: Optional[str] = None


class SIProfile(SITimezone):
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    orientation: Optional[str] = None
Пример #4
0
async def get_user_db(session: AsyncSession = Depends(get_async_session)):
    yield SQLAlchemyUserDatabase(UserDB, session, UserTable, OAuthAccountTable)
Пример #5
0
class UserTable(Base, SQLAlchemyBaseUserTable):
    pass


class OAuthAccount(SQLAlchemyBaseOAuthAccountTable, Base):
    pass


engine = sqlalchemy.create_engine(DATABASE_URL,
                                  connect_args={"check_same_thread": False})
Base.metadata.create_all(engine)

users = UserTable.__table__
oauth_accounts = OAuthAccount.__table__
user_db = SQLAlchemyUserDatabase(UserDB, database, users, oauth_accounts)


def on_after_register(user: UserDB, request: Request):
    print(f"User {user.id} has registered.")


def on_after_forgot_password(user: UserDB, token: str, request: Request):
    print(f"User {user.id} has forgot their password. Reset token: {token}")


jwt_authentication = JWTAuthentication(secret=SECRET,
                                       lifetime_seconds=3600,
                                       tokenUrl="/auth/jwt/login")

app = FastAPI()
Пример #6
0
import posixpath
import urllib.parse
from typing import Union

import boto3
import minio
from botocore.client import Config
from elasticsearch import Elasticsearch
from fastapi_users import FastAPIUsers
from fastapi_users.authentication import JWTAuthentication
from fastapi_users.db import SQLAlchemyUserDatabase

from . import database, dbutils, models, schemas, settings

user_db = SQLAlchemyUserDatabase(
    schemas.UserDB, database.database, models.User.__table__
)
jwt_authentication = JWTAuthentication(
    secret=settings.SECRET, lifetime_seconds=3600, tokenUrl="/auth/jwt/login"
)
fastapi_users = FastAPIUsers(
    user_db,
    [jwt_authentication],
    schemas.UserBase,
    schemas.UserCreate,
    schemas.UserUpdate,
    schemas.UserDB,
)


class Boto3ClientCache:
Пример #7
0
from sqlalchemy.orm import relationship
from fastapi_users.db import SQLAlchemyBaseUserTable, SQLAlchemyUserDatabase
from users_app import schemas
from main_package import db


class UserTable(db.Base, SQLAlchemyBaseUserTable):
    account = relationship("Account", back_populates="owner")


users = UserTable.__table__
user_db = SQLAlchemyUserDatabase(schemas.UserDB, db.database, users)

# db.Base.metadata.create_all(db.engine)
        else:
            update_data = user.dict(exclude_unset=True)
        columns = [col.key for col in inspect(user_db).mapper.column_attrs]
        for field in update_data:
            if field in columns:
                setattr(user_db, field, update_data[field])
        await db.update(user_db)
        return user_db, domain.User.from_orm(user_db)

    async def remove(self, db: SQLAlchemyUserDatabase, *, user: domain.User) -> (models.UserDB, domain.User):
        await db.delete(cast(models.UserDB, user))
        return cast(models.UserDB, user), user

    async def remove_all(self, db: SQLAlchemyUserDatabase):
        raise NotImplemented

    async def count(self, db: Session) -> int:
        raise NotImplemented


{{ cookiecutter.aggregate_name_camel }} = GenericSqlAlchemyRepo[domain.{{ cookiecutter.aggregate_name_camel }},
                                      models.{{ cookiecutter.aggregate_name_camel }},
                                      domain.{{ cookiecutter.aggregate_name_camel }},
                                      domain.{{ cookiecutter.aggregate_name_camel }}]

{{ cookiecutter.aggregate_name_snake }} = {{ cookiecutter.aggregate_name_camel }}(models.{{ cookiecutter.aggregate_name_camel }}, domain.{{ cookiecutter.aggregate_name_camel }})

fastapi_user = SQLAlchemyUserDatabase(models.UserDB, async_db, models.User.__table__)

user = User()
Пример #9
0
import os
from fastapi import Request
from fastapi_users import FastAPIUsers
from fastapi_users.authentication import JWTAuthentication
from fastapi_users.db import SQLAlchemyUserDatabase

from db.session import database
from schemas.user import User, UserCreate, UserUpdate, UserDB
from models.user import User as UserModel

SECRET = os.getenv('SECRET')

user_db = SQLAlchemyUserDatabase(UserDB, database, UserModel.__table__)


def on_after_register(user: UserDB, request: Request):
    print(f"User {user.id} has registered.")


def on_after_forgot_password(user: UserDB, token: str, request: Request):
    print(f"User {user.id} has forgot their password. Reset token: {token}")


jwt_authentication = JWTAuthentication(
    secret=SECRET,
    lifetime_seconds=3600,
    tokenUrl="/auth/jwt/login",
)

fastapi_users = FastAPIUsers(
    user_db,
Пример #10
0
from fastapi_users.authentication import JWTAuthentication
from fastapi_users.db import SQLAlchemyUserDatabase

from .models import User
from .schemas import UserDB
from core.db import database

users = User.__table__
user_db = SQLAlchemyUserDatabase(user_db_model=UserDB, database=database, users=users)

SECRET = 'jasdiujdp9832ue3290u328dh1783d102d1uhd'

auth_backends = []

jwt_authentication = JWTAuthentication(secret=SECRET, lifetime_seconds=3600)

auth_backends.append(jwt_authentication)