예제 #1
0
async def index(session: Session = Depends(db.session), ):
    """
    ELB 상태 체크용 API
    :return:
    """
    user = Users(status='active', name="HelloWorld")
    session.add(user)
    session.commit()

    Users.create(session, auto_commit=True, name="코알라")
    current_time = datetime.utcnow()
    return Response(
        f"Notification API (UTC: {current_time.strftime('%Y.%m.%d %H:%M:%S')})"
    )
예제 #2
0
async def register(sns_type: SnsType,
                   reg_info: UserRegister,
                   session: Session = Depends(db.session)):
    """
    `회원가입 API`\n
    :param sns_type:
    :param reg_info:
    :param session:
    :return:
    """

    if sns_type == SnsType.email:
        is_exist = await is_email_exist(reg_info.email)
        if not reg_info.email or not reg_info.pw:
            return JSONResponse(
                status_code=400,
                content=dict(msg="Email and PW must be provided'"))
        if is_exist:
            return JSONResponse(status_code=400,
                                content=dict(msg="EMAIL_EXISTS"))
        hash_pw = bcrypt.hashpw(reg_info.pw.encode("utf-8"), bcrypt.gensalt())
        new_user = Users.create(session,
                                auto_commit=True,
                                pw=hash_pw,
                                email=reg_info.email)
        token = dict(
            Authorization=
            f"Bearer {create_access_token(data=UserToken.from_orm(new_user).dict(exclude={'pw', 'marketing_agree'}),)}"
        )
        return token
    return JSONResponse(status_code=400, content=dict(msg="NOT_SUPPORTED"))
예제 #3
0
def login(session):
    """
    테스트전 사용자 미리 등록
    :param session:
    :return:
    """
    db_user = Users.create(session=session,
                           email="*****@*****.**",
                           pw="123")
    session.commit()
    access_token = create_access_token(data=UserToken.from_orm(db_user).dict(
        exclude={'pw', 'marketing_agree'}), )
    return dict(Authorization=f"Bearer {access_token}")
예제 #4
0
def test_registration_exist_email(client, session):
    """
    레버 로그인
    :param client:
    :param session:
    :return:
    """
    user = dict(email="*****@*****.**",
                pw="123",
                name="라이언",
                phone="01099999999")
    db_user = Users.create(session=session, **user)
    session.commit()
    res = client.post("api/auth/register/email", json=user)
    res_body = res.json()
    assert res.status_code == 400
    assert 'EMAIL_EXISTS' == res_body["msg"]