Exemplo n.º 1
0
    during_ctf_time_only,
    require_verified_emails,
)
from CTFd.utils.decorators.visibility import (
    check_challenge_visibility,
    check_score_visibility,
)
from CTFd.utils.logging import log
from CTFd.utils.modes import generate_account_url, get_model
from CTFd.utils.security.signing import serialize
from CTFd.utils.user import authed, get_current_team, get_current_user, is_admin

challenges_namespace = Namespace("challenges",
                                 description="Endpoint to retrieve Challenges")

ChallengeModel = sqlalchemy_to_pydantic(Challenges)
TransientChallengeModel = sqlalchemy_to_pydantic(Challenges, exclude=["id"])


class ChallengeDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: ChallengeModel


class ChallengeListSuccessResponse(APIListSuccessResponse):
    data: List[ChallengeModel]


challenges_namespace.schema_model("ChallengeDetailedSuccessResponse",
                                  ChallengeDetailedSuccessResponse.apidoc())

challenges_namespace.schema_model("ChallengeListSuccessResponse",
Exemplo n.º 2
0
from CTFd.utils.security.signing import serialize
from CTFd.utils.user import (
    authed,
    get_current_team,
    get_current_team_attrs,
    get_current_user,
    get_current_user_attrs,
    is_admin,
)

challenges_namespace = Namespace("challenges",
                                 description="Endpoint to retrieve Challenges")

ChallengeModel = sqlalchemy_to_pydantic(Challenges,
                                        include={
                                            "solves": int,
                                            "solved_by_me": bool
                                        })
TransientChallengeModel = sqlalchemy_to_pydantic(Challenges, exclude=["id"])


class ChallengeDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: ChallengeModel


class ChallengeListSuccessResponse(APIListSuccessResponse):
    data: List[ChallengeModel]


challenges_namespace.schema_model("ChallengeDetailedSuccessResponse",
                                  ChallengeDetailedSuccessResponse.apidoc())
Exemplo n.º 3
0
from flask import request
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.models import build_model_filters
from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.constants import RawEnum
from CTFd.models import Files, db
from CTFd.schemas.files import FileSchema
from CTFd.utils import uploads
from CTFd.utils.decorators import admins_only

files_namespace = Namespace("files", description="Endpoint to retrieve Files")

FileModel = sqlalchemy_to_pydantic(Files)


class FileDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: FileModel


class FileListSuccessResponse(APIListSuccessResponse):
    data: List[FileModel]


files_namespace.schema_model("FileDetailedSuccessResponse",
                             FileDetailedSuccessResponse.apidoc())

files_namespace.schema_model("FileListSuccessResponse",
                             FileListSuccessResponse.apidoc())
Exemplo n.º 4
0
from CTFd.models import Unlocks, db, get_class_by_tablename
from CTFd.schemas.awards import AwardSchema
from CTFd.schemas.unlocks import UnlockSchema
from CTFd.utils.decorators import (
    admins_only,
    authed_only,
    during_ctf_time_only,
    require_verified_emails,
)
from CTFd.utils.helpers.models import build_model_filters
from CTFd.utils.user import get_current_user

unlocks_namespace = Namespace("unlocks",
                              description="Endpoint to retrieve Unlocks")

UnlockModel = sqlalchemy_to_pydantic(Unlocks)
TransientUnlockModel = sqlalchemy_to_pydantic(Unlocks, exclude=["id"])


class UnlockDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: UnlockModel


class UnlockListSuccessResponse(APIListSuccessResponse):
    data: List[UnlockModel]


unlocks_namespace.schema_model("UnlockDetailedSuccessResponse",
                               UnlockDetailedSuccessResponse.apidoc())

unlocks_namespace.schema_model("UnlockListSuccessResponse",
Exemplo n.º 5
0
from flask import current_app, request
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.constants import RawEnum
from CTFd.models import Notifications, db
from CTFd.schemas.notifications import NotificationSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

notifications_namespace = Namespace(
    "notifications", description="Endpoint to retrieve Notifications")

NotificationModel = sqlalchemy_to_pydantic(Notifications)
TransientNotificationModel = sqlalchemy_to_pydantic(Notifications,
                                                    exclude=["id"])


class NotificationDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: NotificationModel


class NotificationListSuccessResponse(APIListSuccessResponse):
    data: List[NotificationModel]


notifications_namespace.schema_model(
    "NotificationDetailedSuccessResponse",
    NotificationDetailedSuccessResponse.apidoc())
Exemplo n.º 6
0
from CTFd.cache import clear_standings, clear_team_session, clear_user_session
from CTFd.constants import RawEnum
from CTFd.models import Awards, Submissions, Teams, Unlocks, Users, db
from CTFd.schemas.awards import AwardSchema
from CTFd.schemas.submissions import SubmissionSchema
from CTFd.schemas.teams import TeamSchema
from CTFd.utils.decorators import admins_only, authed_only, require_team
from CTFd.utils.decorators.visibility import (
    check_account_visibility,
    check_score_visibility,
)
from CTFd.utils.user import get_current_team, get_current_user_type, is_admin

teams_namespace = Namespace("teams", description="Endpoint to retrieve Teams")

TeamModel = sqlalchemy_to_pydantic(Teams)
TransientTeamModel = sqlalchemy_to_pydantic(Teams, exclude=["id"])


class TeamDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: TeamModel


class TeamListSuccessResponse(PaginatedAPIListSuccessResponse):
    data: List[TeamModel]


teams_namespace.schema_model(
    "TeamDetailedSuccessResponse", TeamDetailedSuccessResponse.apidoc()
)
Exemplo n.º 7
0
from CTFd.schemas.submissions import SubmissionSchema
from CTFd.schemas.users import UserSchema
from CTFd.utils.config import get_mail_provider
from CTFd.utils.decorators import admins_only, authed_only, ratelimit
from CTFd.utils.decorators.visibility import (
    check_account_visibility,
    check_score_visibility,
)
from CTFd.utils.email import sendmail, user_created_notification
from CTFd.utils.helpers.models import build_model_filters
from CTFd.utils.security.auth import update_user
from CTFd.utils.user import get_current_user, get_current_user_type, is_admin

users_namespace = Namespace("users", description="Endpoint to retrieve Users")

UserModel = sqlalchemy_to_pydantic(Users)
TransientUserModel = sqlalchemy_to_pydantic(Users, exclude=["id"])


class UserDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: UserModel


class UserListSuccessResponse(PaginatedAPIListSuccessResponse):
    data: List[UserModel]


users_namespace.schema_model("UserDetailedSuccessResponse",
                             UserDetailedSuccessResponse.apidoc())

users_namespace.schema_model("UserListSuccessResponse",
Exemplo n.º 8
0
from flask import request
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.constants import RawEnum
from CTFd.models import Flags, db
from CTFd.plugins.flags import FLAG_CLASSES, get_flag_class
from CTFd.schemas.flags import FlagSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

flags_namespace = Namespace("flags", description="Endpoint to retrieve Flags")

FlagModel = sqlalchemy_to_pydantic(Flags)


class FlagDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: FlagModel


class FlagListSuccessResponse(APIListSuccessResponse):
    data: List[FlagModel]


flags_namespace.schema_model(
    "FlagDetailedSuccessResponse", FlagDetailedSuccessResponse.apidoc()
)

flags_namespace.schema_model(
Exemplo n.º 9
0
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import (
    APIDetailedSuccessResponse,
    PaginatedAPIListSuccessResponse,
)
from CTFd.cache import clear_standings
from CTFd.constants import RawEnum
from CTFd.models import Submissions, db
from CTFd.schemas.submissions import SubmissionSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

submissions_namespace = Namespace(
    "submissions", description="Endpoint to retrieve Submission")

SubmissionModel = sqlalchemy_to_pydantic(Submissions)
TransientSubmissionModel = sqlalchemy_to_pydantic(Submissions, exclude=["id"])


class SubmissionDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: SubmissionModel


class SubmissionListSuccessResponse(PaginatedAPIListSuccessResponse):
    data: List[SubmissionModel]


submissions_namespace.schema_model("SubmissionDetailedSuccessResponse",
                                   SubmissionDetailedSuccessResponse.apidoc())

submissions_namespace.schema_model("SubmissionListSuccessResponse",
Exemplo n.º 10
0
from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.cache import clear_standings
from CTFd.constants import RawEnum
from CTFd.models import Awards, Users, db
from CTFd.schemas.awards import AwardSchema
from CTFd.utils.config import is_teams_mode
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

awards_namespace = Namespace("awards",
                             description="Endpoint to retrieve Awards")

AwardModel = sqlalchemy_to_pydantic(Awards)


class AwardDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: AwardModel


class AwardListSuccessResponse(APIListSuccessResponse):
    data: List[AwardModel]


awards_namespace.schema_model("AwardDetailedSuccessResponse",
                              AwardDetailedSuccessResponse.apidoc())

awards_namespace.schema_model("AwardListSuccessResponse",
                              AwardListSuccessResponse.apidoc())
Exemplo n.º 11
0
from flask import request
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.cache import clear_pages
from CTFd.constants import RawEnum
from CTFd.models import Pages, db
from CTFd.schemas.pages import PageSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

pages_namespace = Namespace("pages", description="Endpoint to retrieve Pages")

PageModel = sqlalchemy_to_pydantic(Pages)
TransientPageModel = sqlalchemy_to_pydantic(Pages, exclude=["id"])


class PageDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: PageModel


class PageListSuccessResponse(APIListSuccessResponse):
    data: List[PageModel]


pages_namespace.schema_model("PageDetailedSuccessResponse",
                             PageDetailedSuccessResponse.apidoc())

pages_namespace.schema_model("PageListSuccessResponse",
Exemplo n.º 12
0
from flask import request, session
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.models import Tokens, db
from CTFd.schemas.tokens import TokenSchema
from CTFd.utils.decorators import authed_only, require_verified_emails
from CTFd.utils.security.auth import generate_user_token
from CTFd.utils.user import get_current_user, get_current_user_type, is_admin

tokens_namespace = Namespace("tokens",
                             description="Endpoint to retrieve Tokens")

TokenModel = sqlalchemy_to_pydantic(Tokens)
ValuelessTokenModel = sqlalchemy_to_pydantic(Tokens, exclude=["value"])


class TokenDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: TokenModel


class ValuelessTokenDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: ValuelessTokenModel


class TokenListSuccessResponse(APIListSuccessResponse):
    data: List[TokenModel]

Exemplo n.º 13
0
from CTFd.models import (
    ChallengeComments,
    Comments,
    PageComments,
    TeamComments,
    UserComments,
    db,
)
from CTFd.schemas.comments import CommentSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

comments_namespace = Namespace("comments",
                               description="Endpoint to retrieve Comments")

CommentModel = sqlalchemy_to_pydantic(Comments)


class CommentDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: CommentModel


class CommentListSuccessResponse(APIListSuccessResponse):
    data: List[CommentModel]


comments_namespace.schema_model("CommentDetailedSuccessResponse",
                                CommentDetailedSuccessResponse.apidoc())

comments_namespace.schema_model("CommentListSuccessResponse",
                                CommentListSuccessResponse.apidoc())
Exemplo n.º 14
0
from flask import request
from flask_restx import Namespace, Resource

from CTFd.api.v1.helpers.request import validate_args
from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
from CTFd.constants import RawEnum
from CTFd.models import ChallengeTopics, Topics, db
from CTFd.schemas.topics import ChallengeTopicSchema, TopicSchema
from CTFd.utils.decorators import admins_only
from CTFd.utils.helpers.models import build_model_filters

topics_namespace = Namespace("topics",
                             description="Endpoint to retrieve Topics")

TopicModel = sqlalchemy_to_pydantic(Topics)


class TopicDetailedSuccessResponse(APIDetailedSuccessResponse):
    data: TopicModel


class TopicListSuccessResponse(APIListSuccessResponse):
    data: List[TopicModel]


topics_namespace.schema_model("TopicDetailedSuccessResponse",
                              TopicDetailedSuccessResponse.apidoc())

topics_namespace.schema_model("TopicListSuccessResponse",
                              TopicListSuccessResponse.apidoc())