コード例 #1
0
    def retrieve_user(self):
        session_cookie = self.cookies.get("session", None)
        if session_cookie is None:
            self.session_token = None
        else:
            self.session_token = session_cookie.value

        if self.endpoint in [
            "create-checkout-session",
            "get-publishable-key",
            "customer-portal",
            "manage-billing",
            "create-comment",
            "checkout-session",
            "logout",
        ]:
            print("Logged In Method Invoked")
            self.username = get_session_username(self.session_token)
            print(self.username)
            if not self.username:
                raise WebException(
                    status_code=HTTPStatus.UNAUTHORIZED, message="Unauthenticated User"
                )
            user_info = get_user_info(self.username)
            if user_info is None:
                self.paiduser = False
            else:
                self.paiduser = (
                    True if user_info["subscription_type"] == "Paid" else False
                )
            print(self.paiduser)

        return self
コード例 #2
0
def get_comments(request, response):
    data = request.data

    username = get_session_username(data["session"])

    commentList = []

    try:

        createdBy = ""
        createdByCurrentUser = True

        getUserDetails = f"Select SubscriptionPlan from user_data where UserName = '******';"

        getCommentOfTalent = f"Select CommentId, c.UserId, Comment, ParentId, c.CreatedAt, c.UpdatedAt, UserName from talent t, comment c, user_data u where c.TalentId = {data['talentId']} and c.TalentId = t.TalentId and u.Id = c.UserId;"

        userData = getResult(getUserDetails)

        oneUserDetail = userData[0]

        allCommentsResult = getResult(getCommentOfTalent)

        for oneComment in allCommentsResult:
            if not oneComment["ParentId"] is None:
                if str(oneComment["UserName"]) in str(username):
                    createdBy = "You"
                    createdByCurrentUser = True
                else:
                    createdBy = str(oneComment["UserName"])
                    createdByCurrentUser = False

                commentDict = {
                    "id": int(oneComment["CommentId"]),
                    "createdByCurrentUser": createdByCurrentUser,
                    "content": oneComment["Comment"],
                    "fullname": createdBy,
                    "parent": oneComment["ParentId"],
                    "created": str(oneComment["CreatedAt"]),
                    "modified": str(oneComment["UpdatedAt"]),
                }

                commentList.append(commentDict)

            else:
                if str(oneComment["UserName"]) in str(username):
                    createdBy = "You"
                    createdByCurrentUser = True

                else:
                    createdBy = oneComment["UserName"]
                    createdByCurrentUser = False

                commentDict = {
                    "id": int(oneComment["CommentId"]),
                    "createdByCurrentUser": createdByCurrentUser,
                    "content": oneComment["Comment"],
                    "fullname": createdBy,
                    "parent": None,
                    "created": str(oneComment["CreatedAt"]),
                    "modified": str(oneComment["UpdatedAt"]),
                }

                commentList.append(commentDict)

        response.body = {
            "commentResult": commentList,
            "SubscriptionPlan": oneUserDetail["SubscriptionPlan"],
        }
        return response

    except Exception as e:
        raise WebException(status_code=HTTPStatus.BAD_REQUEST,
                           message=str(e)) from e
コード例 #3
0
def create_comment(request, response):
    data = request.data
    now = datetime.now()
    count = 0
    paId = ""

    username = get_session_username(data["session"])

    try:
        getUserDetails = f"Select * from user_data where UserName = '******';"
        userData = getResult(getUserDetails)

        oneUserDetail = userData[0]
        insert_comment_query = "Insert into comment (UserId, TalentId, Comment, ParentId, CreatedAt, UpdatedAt) Values (%s, %s, %s, %s, %s, %s);"
        getNewCommentId = "Select LAST_INSERT_ID();"
        userId = oneUserDetail["Id"]
        comment = data["content"]
        createdAt = now.strftime("%Y-%m-%d %H:%M:%S")
        updatedAt = now.strftime("%Y-%m-%d %H:%M:%S")
        parentId = 0
        if not data["parent"] is None:
            parentId = int(data["parent"])
        else:
            parentId = None
        talentId = int(data["talentId"])
        commentId = insertComment(
            insert_comment_query,
            getNewCommentId,
            (userId, talentId, comment, parentId, createdAt, updatedAt),
        )
        count = 1

        id = [id[0] for id in commentId]

        if count == 1:

            get_new_comment_query = f"Select CommentId, UserId, Comment, ParentId, CreatedAt, UpdatedAt, UserName from comment c, user_data u where c.TalentId = {data['talentId']} and CommentId = {id[0]} and u.Id = c.UserId;"

            comment_result = getResult(get_new_comment_query)

            oneResult = comment_result[0]
            if oneResult["ParentId"] is None:
                paId = None
            else:
                paId = int(oneResult["ParentId"])
            createdBy = ""
            createdByCurrentUser = True
            if oneResult["UserName"] == str(username):
                createdBy = "You"
                createdByCurrentUser = True
            else:
                createdBy = oneResult["UserName"]
                createdByCurrentUser = False

            commentDict = {
                "id": int(oneResult["CommentId"]),
                "parent": paId,
                "content": oneResult["Comment"],
                "fullname": createdBy,
                "created": str(oneResult["CreatedAt"]),
                "modified": str(oneResult["UpdatedAt"]),
                "createdByCurrentUser": createdByCurrentUser,
            }
            response.body = commentDict

            return response

    except Exception as e:
        raise WebException(status_code=HTTPStatus.BAD_REQUEST,
                           message=str(e)) from e