Skip to content

Commit

Permalink
Fix bugs related to freshman registration
Browse files Browse the repository at this point in the history
  • Loading branch information
yppf committed Aug 11, 2024
1 parent dc4733d commit 9066a22
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
1 change: 0 additions & 1 deletion app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# path("requestLoginOrg/", views.requestLoginOrg, name="requestLoginOrg"), # 已废弃
path("welcome/", views.homepage, name="welcome"),
path("freshman/", views.freshman, name="freshman"),
path("register/", views.authRegister, name="register"),
path("agreement/", views.userAgreement, name="userAgreement"),
path("shiftAccount/", views.shiftAccount, name="shiftAccount"),
# path("org/", views.org, name="org"),
Expand Down
44 changes: 1 addition & 43 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def _create_freshman_account(sid: str, email: str = None):
current = "创建用户"
user = User.objects.create_user(
username=sid, name=name,
usertype=User.Type.PERSON,
usertype=User.Type.STUDENT,
password=password
)
current = "创建个人账号"
Expand Down Expand Up @@ -1278,48 +1278,6 @@ def userAgreement(request: UserRequest):
dict(request=request, bar_display=bar_display))


@deprecated
@logger.secure_view()
def authRegister(request: HttpRequest):
if not request.user.is_superuser:
return HttpResponseRedirect("/index/")

if request.method == "POST" and request.POST:
keys = ["name", "password", "snum", "email", "password2", "syear", "sgender"]
values = [request.POST[key] for key in keys]
name, password, sno, email, password2, stu_grade, gender = values
if password != password2:
return render(request, "index.html")

failed = False
failed |= gender not in ['男', '女']
failed |= SQ.sfilter(NaturalPerson.person_id, sno).exists()
failed |= NaturalPerson.objects.filter(email=email).exists()
if failed:
return render(request, "auth_register_boxed.html")

# OK!
try:
user = User.objects.create_user(
username=sno, name=name,
usertype=User.Type.PERSON,
password=password
)
person = NaturalPerson.objects.create(
user,
stu_id_dbonly=sno,
name=name,
email=email,
stu_grade=stu_grade,
gender=NaturalPerson.Gender.MALE if gender == '男'
else NaturalPerson.Gender.FEMALE,
)
except:
return HttpResponseRedirect("/admin/")
return HttpResponseRedirect("/index/")
return render(request, "auth_register_boxed.html")


@login_required(redirect_field_name="origin")
@utils.check_user_access(redirect_url="/logout/")
@logger.secure_view()
Expand Down
7 changes: 4 additions & 3 deletions static/assets/js/dorm_forcement.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const user_agreement_path = '/agreement'
const dorm_path = '/dormitory/agreement';
const query_path = '/dormitory/agreement-query-fixme';

function currentIsDormPage() {
function skipThisPage() {
var current_url = window.location.pathname;
return current_url.includes(dorm_path);
return current_url.includes(dorm_path) || current_url.includes(user_agreement_path);
}

function getAgreementState() {
Expand All @@ -22,7 +23,7 @@ function getAgreementState() {
}

$(function() {
if (!currentIsDormPage()) {
if (!skipThisPage()) {
getAgreementState().then(signed => {
if (!signed) {
window.location.href = dorm_path;
Expand Down

0 comments on commit 9066a22

Please sign in to comment.