Skip to content

Commit

Permalink
Merge branch 'suspicious'
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Sep 8, 2023
2 parents da96312 + df15d64 commit 6b9e345
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 6 deletions.
20 changes: 20 additions & 0 deletions frontend/templates/admin_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ <h2 v-else>正在创建</h2>
<label for="form-aff">了解比赛的渠道:</label>
<input class="vTextField" type="text" id="form-aff" name="aff" v-model="opened.aff">
</div>
<div class="form-row">
<label for="form-suspicious">是否标记为第一阶段封禁:</label>
<input class="vCheckboxField" type="checkbox" id="form-suspicious" name="suspicious" v-model="opened.suspicious">
</div>
<div class="form-row">
<label for="form-suspicious-reason">第一阶段封禁原因:</label>
<input class="vTextField" type="text" id="form-suspicious-reason" name="suspicious-reason" v-model="opened.suspicious_reason">
</div>
<div class="form-row">
<label for="form-suspicious-ddl">显示的第一阶段封禁联系截止时间:</label>
<input class="vTextField" type="text" id="form-suspicious-ddl" name="suspicious-ddl" v-model="opened.suspicious_ddl">
<div class="help" v-if="isNaN(new Date(opened.suspicious_ddl).valueOf())"><strong>格式错误!</strong></div>
<div class="help" v-else>本地时间: {{ new Date(opened.suspicious_ddl).toLocaleString() }}<br>UTC 时间: {{ new Date(opened.suspicious_ddl).toJSON() }}</div>
</div>
</fieldset>
<div class="submit-row" v-show="!opened_disabled">
<input type="submit" class="default" value="保存">
Expand Down Expand Up @@ -103,6 +117,9 @@ <h2 v-else>正在创建</h2>
<th scope="col"><div class="text"><span>专业</span></div><div class="clear"></div></th>
<th scope="col"><div class="text"><span>校区</span></div><div class="clear"></div></th>
<th scope="col"><div class="text"><span>了解比赛的渠道</span></div><div class="clear"></div></th>
<th scope="col"><div class="text"><span>标记为第一阶段封禁</span></div><div class="clear"></div></th>
<th scope="col"><div class="text"><span>第一阶段封禁原因</span></div><div class="clear"></div></th>
<th scope="col"><div class="text"><span>第一阶段封禁联系截止时间</span></div><div class="clear"></div></th>
</tr>
</thead>
<tbody v-if="objs">
Expand All @@ -123,6 +140,9 @@ <h2 v-else>正在创建</h2>
<td>{{ obj.major }}</td>
<td>{{ obj.campus }}</td>
<td>{{ obj.aff }}</td>
<td><img v-if="obj.suspicious" src="/static/admin/img/icon-yes.svg" alt="True"><img v-else src="/static/admin/img/icon-no.svg" alt="False"></td>
<td>{{ obj.suspicious_reason }}</td>
<td>{{ obj.suspicious_ddl }}</td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions frontend/templates/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<small>{{ new Date(announcement.time).toLocaleString() }}</small>
<a href="/announcements/">查看所有公告</a>
</div>
<div v-if="user.suspicious" class="msg-error">
经裁判组检查,你的账号有以下疑似违规行为:{{ user.suspicious_reason }}。
你的账号将会在 {{ new Date(user.suspicious_ddl).toLocaleString() }} 之后被封禁。
如果你有异议,请尽快联系 <a href="mailto:[email protected]">[email protected]</a>
提供你的 Token 以及申诉理由。在封禁之前,你仍可正常参加比赛。
</div>
<div v-if="user" class="msg-info">
<label for="token">Token:</label>
<button @click="token_show=!token_show">{{ token_show?'隐藏':'显示' }}</button>
Expand Down
37 changes: 31 additions & 6 deletions server/user/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class User:
json_fields = ('pk', 'is_staff', 'group', 'profile_ok',
'display_name', 'nickname', 'name', 'sno', 'tel',
'email', 'gender', 'qq', 'website', 'school',
'grade', 'major', 'campus', 'aff', 'token', 'token_short', 'code')
'grade', 'major', 'campus', 'aff', 'token', 'token_short', 'code',
'suspicious', 'suspicious_reason', 'suspicious_ddl')
update_fields = ('group', 'nickname', 'name', 'sno', 'tel', 'email',
'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff')
'aff', 'suspicious', 'suspicious_reason', 'suspicious_ddl')
groups = {
'noscore': '不计分',
'ustc': '中国科学技术大学',
Expand Down Expand Up @@ -103,6 +104,9 @@ class User:
'major': RegexValidator(r'^.{1,15}$', '专业格式错误'),
'campus': RegexValidator(r'^.{1,15}$', '校区格式错误'),
'aff': RegexValidator(r'^.{1,100}$', '了解比赛的渠道格式错误'),
'suspicious': lambda x: isinstance(x, bool),
'suspicious_reason': None,
'suspicious_ddl': None,
}
_private_key = OpenSSL.crypto.load_privatekey(
OpenSSL.crypto.FILETYPE_PEM, settings.PRIVATE_KEY)
Expand Down Expand Up @@ -197,7 +201,10 @@ def update(self, **kwargs):
server.trigger.interface.Trigger.test_can_update_profile(self._context)
except server.trigger.interface.TriggerIsOff:
User.test_permission(self._context, 'user.full')
if 'group' in kwargs and kwargs['group'] != self.group:
if ('group' in kwargs and kwargs['group'] != self.group) or \
('suspicious' in kwargs and kwargs['suspicious'] != self.suspicious) or \
('suspicious_reason' in kwargs and kwargs['suspicious_reason'] != self.suspicious_reason) or \
('suspicious_ddl' in kwargs and kwargs['suspicious_ddl'] != self.suspicious_ddl):
User.test_permission(self._context, 'user.full')
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full')
Expand All @@ -211,10 +218,10 @@ def _update(self, **kwargs):
for k, v in kwargs.items():
if k in {'group', 'nickname', 'name', 'sno', 'tel', 'email',
'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff'}:
'aff', 'suspicious', 'suspicious_reason', 'suspicious_ddl'}:
v = v or None
try:
v is None or self._validators[k](v)
v is None or (self._validators[k] and self._validators[k](v))
except ValidationError as e:
raise WrongFormat(e.message)
setattr(self._obj, k, v)
Expand All @@ -229,7 +236,7 @@ def _update(self, **kwargs):
**{k: getattr(self._obj, k) for k in {
'user', 'group', 'nickname', 'name', 'sno', 'tel',
'email', 'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff', 'token',
'aff', 'token', 'suspicious', 'suspicious_reason', 'suspicious_ddl'
}},
)

Expand Down Expand Up @@ -423,3 +430,21 @@ def code(self):
return None
token = self._obj.token
return f'{self.pk}-{int(sha256(token.encode()).hexdigest(), 16)%10000:04}'

@property
def suspicious(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full')
return self._obj.suspicious

@property
def suspicious_reason(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full')
return self._obj.suspicious_reason

@property
def suspicious_ddl(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full')
return self._obj.suspicious_ddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.4 on 2023-09-07 18:43

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("user", "0012_add_groups"),
]

operations = [
migrations.AddField(
model_name="user",
name="suspicious",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="user",
name="suspicious_reason",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="userlog",
name="suspicious",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="userlog",
name="suspicious_reason",
field=models.TextField(null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.4 on 2023-09-08 08:20

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("user", "0013_user_suspicious_user_suspicious_reason_and_more"),
]

operations = [
migrations.AddField(
model_name="user",
name="suspicious_ddl",
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name="userlog",
name="suspicious_ddl",
field=models.DateTimeField(null=True),
),
]
6 changes: 6 additions & 0 deletions server/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class User(models.Model):
campus = models.TextField(null=True)
aff = models.TextField(null=True)
token = models.TextField()
suspicious = models.BooleanField(default=False)
suspicious_reason = models.TextField(null=True)
suspicious_ddl = models.DateTimeField(null=True)

class Meta:
default_permissions = ()
Expand Down Expand Up @@ -59,6 +62,9 @@ class UserLog(models.Model):
campus = models.TextField(null=True)
aff = models.TextField(null=True)
token = models.TextField()
suspicious = models.BooleanField(default=False)
suspicious_reason = models.TextField(null=True)
suspicious_ddl = models.DateTimeField(null=True)

class Meta:
default_permissions = ()

0 comments on commit 6b9e345

Please sign in to comment.