def initialize_data(self) -> None:
        with transaction(commit=True) as db:
            # Active User
            active_user = Users(id=self.active_user_id,
                                password=self.password).save(db)

            # Leave User
            leave_user = Users(
                id=self.leave_user_id,
                password=self.password,
                leave=Users.LEAVE,
                leave_dt=datetime.now().strftime('%Y-%m-%d %H:%M:%S')).save(db)

        setattr(self, 'active_uid', active_user.row_id)
        setattr(self, 'leave_uid', leave_user.row_id)

        for i in range(0, 2):
            response = client.put("/v1/users/session",
                                  json={
                                      'id': self.active_user_id,
                                      'password': self.password
                                  })
            assert response.status_code == HTTPStatus.OK
            # 테스트 메소드 수 만큼 setup 호출로 테스트 완료가 조금 걸린다
            time.sleep(1)
Esempio n. 2
0
 def logout(session_key):
     try:
         with transaction(commit=True) as db:
             Sessions(session_key=session_key).update_logout(db)
         return True
     except Exception as e:
         raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                       exc_detail=str(e))
Esempio n. 3
0
 def retrieve(uid: int):
     try:
         with transaction() as db:
             user = Users(row_id=uid).find_by_row_id(db)
         return user.to_dict()
     except NotFoundUserException:
         raise
     except Exception as e:
         raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                       exc_detail=str(e))
Esempio n. 4
0
 def logout(uid):
     try:
         with transaction(commit=True) as db:
             user = Users(row_id=uid).logout(db)
         return {"uid": user.row_id}
     except NotFoundUserException:
         raise
     except Exception as e:
         raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                       exc_detail=str(e))
Esempio n. 5
0
 def login(data):
     try:
         with transaction(commit=True) as db:
             user = Users(id=data.id,
                          password=data.password).find_by_id_password(db)
             user.login(db)
         return {"uid": user.row_id}
     except NotFoundUserException:
         raise
     except Exception as e:
         raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                       exc_detail=str(e))
Esempio n. 6
0
    def unregister(uid):
        try:
            with transaction(commit=True) as db:
                user = Users(row_id=uid).find_by_row_id(db)
                if user.leave == Users.ACTIVE:
                    user.unregister(db)
            return {"uid": user.row_id, "leave_dt": user.leave_dt}

        except NotFoundUserException:
            raise
        except Exception as e:
            raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                          exc_detail=str(e))
async def verify_session_key(req: Request):
    session_key = req.headers.get("x-session-key")
    try:
        if session_key is None:
            raise BadRequestException(message="x-session-key 값이 필요합니다")

        with transaction() as db:
            session = Sessions(session_key=session_key).find_by_session_key(db)
            setattr(req, "uid", int(session.user_rowid))

        return True
    except NotFoundSessionException:
        raise
Esempio n. 8
0
 def login(uid, ip):
     try:
         with transaction(commit=True) as db:
             session = Sessions(
                 user_rowid=uid,
                 ip=ip,
                 session_key=SimpleSessionKeyMaker().make_session_key(),
             )
             session.save(db)
         return {"session_key": session.session_key}
     except Exception as e:
         raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                       exc_detail=str(e))
    def initialize_data(self) -> None:
        with transaction(commit=True) as db:
            # Active User
            active_user = Users(id=self.active_user_id, password=self.password).save(db)

            # Leave User
            leave_user = Users(
                id=self.leave_user_id,
                password=self.password,
                leave=Users.LEAVE,
                leave_dt=datetime.now().strftime('%Y-%m-%d %H:%M:%S')).save(db)

        setattr(self, 'active_uid', active_user.row_id)
        setattr(self, 'leave_uid', leave_user.row_id)
Esempio n. 10
0
    def register(data):
        try:
            with transaction(commit=True) as db:
                user = Users(id=data.id, password=data.password)
                user.save(db)

            return {
                "uid": user.row_id,
                "created_at": user.created_dt.strftime("%Y-%m-%d %H:%M:%S"),
            }
        except ConflictUserException:
            raise
        except Exception as e:
            raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                          exc_detail=str(e))
Esempio n. 11
0
    def retrieve(uid):
        try:
            with transaction() as db:
                sessions = Sessions(user_rowid=uid).find_by_user_rowid(db)

                result = []
                for session in sessions:
                    result.append({
                        name: getattr(session, name)
                        for name in session._fields
                    })

                return result
        except Exception as e:
            raise InternalServerException(message=f"서버 에러가 발생했습니다",
                                          exc_detail=str(e))
Esempio n. 12
0
    def initialize_data(self) -> None:
        with transaction(commit=True) as db:
            # Active User
            active_user = Users(id=self.active_user_id, password=self.password).save(db)

            # Leave User
            leave_user = Users(
                id=self.leave_user_id,
                password=self.password,
                leave=Users.LEAVE,
                leave_dt=datetime.now().strftime('%Y-%m-%d %H:%M:%S')).save(db)

        response = client.put("/v1/users/session", json={
            'id': self.active_user_id,
            'password': self.password
        })
        assert response.status_code == HTTPStatus.OK

        response = response.json()
        assert response.get('session') is not None

        setattr(self, 'active_uid', active_user.row_id)
        setattr(self, 'active_session_key', response.get('session'))
        setattr(self, 'leave_uid', leave_user.row_id)