-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
54 lines (42 loc) · 1.39 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from .usertoken import (
register,
settings,
)
from flask import Blueprint
from flask import abort, request
from CTFd.models import (
Awards,
Notifications,
Solves,
Submissions,
Tracking,
Unlocks,
Users,
db,
)
from CTFd.schemas.users import UserSchema
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.user import get_current_user, get_current_user_type, is_admin
def load(app):
blueprint = Blueprint("usertoken", __name__, template_folder="templates")
@blueprint.route("/api/v1/users/verify/<secret>")
@admins_only
@check_account_visibility
def verify(secret):
user = Users.query.filter_by(secret=secret).first()
if user is None:
return {"success": False}
if (user.banned or user.hidden) and is_admin() is False:
return {"success": False}
user_type = get_current_user_type(fallback="user")
response = UserSchema(view=user_type).dump(user)
if response.errors:
return {"success": False, "errors": response.errors}
return {"success": True, "username": response.data["name"]}
app.register_blueprint(blueprint)
app.view_functions["auth.register"] = register
app.view_functions["views.settings"] = settings