Skip to content

Commit

Permalink
Merge pull request #102 from BITNP/YDX-2147483647/issue101
Browse files Browse the repository at this point in the history
fix: 网页右上角最好显示姓名
  • Loading branch information
YDX-2147483647 authored Aug 1, 2024
2 parents 315c2ed + 80fdb4f commit 408cd83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion contest/quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@


class User(AbstractUser):
pass
def get_full_name(self) -> str:
"""获取全名
与`username`不同,全名不能保证唯一。
"""
if self.first_name:
# the first_name plus the last_name, with a space in between.
return super().get_full_name()
else:
return self.last_name or self.username


class Question(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions contest/quiz/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{% if user.is_authenticated %}
<a class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium"
href="{% url 'logout' %}">登出</a>
<div class="px-3 text-base font-medium text-white">{{ user }}</div>
<div class="px-3 text-base font-medium text-white">{{ user.get_full_name }}</div>
{% else %}
<a class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium"
href="{% url 'login' %}">登录</a>
Expand Down Expand Up @@ -122,7 +122,7 @@
</div>
<div class="border-t border-gray-700 pb-3 pt-4 px-2 sm:px-3">
{% if user.is_authenticated %}
<div class="px-3 text-base font-medium text-white">{{ user }}</div>
<div class="px-3 text-base font-medium text-white">{{ user.get_full_name }}</div>
<a class="text-gray-300 hover:bg-gray-700 hover:text-white block rounded-md px-3 py-2 text-base font-medium"
href="{% url 'logout' %}">登出</a>
{% else %}
Expand Down
8 changes: 8 additions & 0 deletions doc/cas.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
3. Django 服务器验证信息。若未见过,则在数据库中新建`User``Student`
4. Django 服务器向使用者展示后续页面。

## 个人信息

学校的正式 CAS 服务器会将姓名存储到`userName`

经过`settings.py``CAS_RENAME_ATTRIBUTES`规定的重命名,Django 中`User``username`是学号,`last_name`是姓名(不保证唯一),`first_name`空。

`Student``name`目前仍是学号,原本设计的是姓名。

## 版本问题

学校的 CAS 服务器可能是 2.0。Django 侧若用 3.0,会从 CAS 服务器接收到不合法的 HTML,导致无法正常登录。
Expand Down

0 comments on commit 408cd83

Please sign in to comment.