Beispiel #1
0
def login():
    '''
    새로운 토큰을 발급해 줍니다.
    '''
    user_session = afr(UserSession(g.pr_result.get('user')))
    Session().commit()
    return {'token': user_session.token, 'expiry': DateTimeHelper.full_datetime(user_session.expiry)}, Status.HTTP_200_OK
Beispiel #2
0
def user_session_or_none():
    token = request.headers.get('Authorization', None)
    if token is not None and (len(token.split()) >= 2):
        token = token.split()[1]
        user_session = UserSession.get_session(token)
        return user_session
    return None
Beispiel #3
0
def login_required(token):
    user_session = UserSession.get_session(token)
    if user_session is None:
        raise Unauthorized()

    g.user_session = user_session
    g.user_session.user.last_access = datetime.now()
    return {'active': True}
Beispiel #4
0
def sign_up():
    '''
    auth_key, auth_value, phone, password 로 계정 하나를 생성합니다.
    '''
    user = afr(User(request.json.get('password'), phone=request.json.get('phone')))
    user_session = afr(UserSession(user))
    Session().commit()

    return {'user_id': user.id, 'token': user_session.token, 'expiry': DateTimeHelper.full_datetime(user_session.expiry)}, Status.HTTP_200_OK
Beispiel #5
0
def user_session_or_none():
    '''
    세션의 만료, 동결 여부를 묻지 않고 세션을 리턴하는 헬퍼함수입니다.
    :return:
    '''
    token = request.headers.get('Authorization', None)
    if token is not None and (len(token.split()) >= 2):
        token = token.split()[1]
        user_session = UserSession.get_session(token)
        return user_session
    return None
Beispiel #6
0
def get_or_create_admin_session(admin):
    user_session = Session().query(UserSession).filter(
        (UserSession.admin == True)
        & (UserSession.expiry >= datetime.now())
        & (UserSession.user_id == admin.user_id)).first()

    if user_session is None:
        user_session = UserSession(admin.user, admin=True)
        Session().add(user_session)
        Session().flush()

    return user_session
Beispiel #7
0
def login_google():
    oauth = Session().query(OauthGoogle).filter(OauthGoogle.party_id == g.info.get('id')).first()
    is_new = True if oauth is None else False

    if is_new:

        # TODO 여기서 블랙리스트 조회에서 에러 리턴.

        user = afr(User(email=g.info.get('email')))
        oauth = afr(OauthGoogle(user, g.info))
        user.oauth_google_id = oauth.id

    user_session = UserSession(oauth.user, third_party_token=request.json.get('token'))
    Session(changed=True).add(user_session)

    return {'okay':True, 'user_id':oauth.user.id, 'token': user_session.token, 'is_new': is_new, 'expiry': DateTimeHelper.full_datetime(user_session.expiry)}, Status.HTTP_200_OK
Beispiel #8
0
def login_kakao():
    oauth = Session().query(OauthKakao).filter(
        OauthKakao.party_id == g.info.get('id')).first()
    is_new = True if oauth is None else False

    if is_new:
        user = afr(User(email=g.info['kakao_account'].get('email')))
        oauth = afr(OauthKakao(user, g.info))
        afr(UserPoint(user_id=user.id))

    user_session = UserSession(oauth.user,
                               third_party_token=request.json.get('token'))
    Session(changed=True).add(user_session)

    return {
        'user_id': oauth.user.id,
        'token': user_session.token,
        'is_new': is_new,
        'expiry': DateTimeHelper.full_datetime(user_session.expiry)
    }, Status.HTTP_200_OK
Beispiel #9
0
def login_required(token):
    user_session = UserSession.get_session(token)
    if user_session is None:
        raise ClientError('Unauthorized', Status.HTTP_401_UNAUTHORIZED)
    g.user_session = user_session
    return {'active': True}