refactor: use ajax to get expiry_date
parent
0ce1c6eb6e
commit
1f150fc847
|
@ -126,3 +126,20 @@ def user():
|
||||||
update_expiry_time_by_username(username, "".join(expiry_time.split("-")))
|
update_expiry_time_by_username(username, "".join(expiry_time.split("-")))
|
||||||
flash(f'Expiry date updated to {expiry_time}.')
|
flash(f'Expiry date updated to {expiry_time}.')
|
||||||
return render_template("admin_manage_user.html", **context)
|
return render_template("admin_manage_user.html", **context)
|
||||||
|
|
||||||
|
|
||||||
|
@adminService.route("/admin/expiry", methods=["GET"])
|
||||||
|
def user_expiry_time():
|
||||||
|
is_admin = check_is_admin()
|
||||||
|
if is_admin != "pass":
|
||||||
|
return is_admin
|
||||||
|
|
||||||
|
username = request.args.get("username", "")
|
||||||
|
if not username:
|
||||||
|
return "Username can't empty"
|
||||||
|
|
||||||
|
user = get_user_by_username(username)
|
||||||
|
if not user:
|
||||||
|
return "User not exist"
|
||||||
|
|
||||||
|
return user.expiry_date
|
|
@ -5,6 +5,11 @@ def get_users():
|
||||||
with db_session:
|
with db_session:
|
||||||
return User.select().order_by(User.name)[:]
|
return User.select().order_by(User.name)[:]
|
||||||
|
|
||||||
|
def get_user_by_username(username):
|
||||||
|
with db_session:
|
||||||
|
user = User.select(name=username)
|
||||||
|
if user:
|
||||||
|
return user.first()
|
||||||
|
|
||||||
def update_password_by_username(username, password="123456"):
|
def update_password_by_username(username, password="123456"):
|
||||||
with db_session:
|
with db_session:
|
||||||
|
|
|
@ -82,16 +82,17 @@
|
||||||
})
|
})
|
||||||
// 选择用户后更新其过期时间
|
// 选择用户后更新其过期时间
|
||||||
function loadUserExpiryDate() {
|
function loadUserExpiryDate() {
|
||||||
let cur_user = $('#username').val();
|
const cur_user = $('#username').val();
|
||||||
{% for user in user_list %}
|
$.ajax({
|
||||||
if (cur_user == "{{ user.name }}") {
|
type: "GET",
|
||||||
const dateString = "{{ user.expiry_date }}"
|
url: `/admin/expiry?username=${cur_user}`,
|
||||||
const year = dateString.substr(0,4);
|
success: function(resp) {
|
||||||
const month = dateString.substr(4,2);
|
const year = resp.substr(0,4);
|
||||||
const day = dateString.substr(6,2);
|
const month = resp.substr(4,2);
|
||||||
|
const day = resp.substr(6,2);
|
||||||
document.getElementById("expiry_date").value = year + '-' + month + '-' + day
|
document.getElementById("expiry_date").value = year + '-' + month + '-' + day
|
||||||
}
|
}
|
||||||
{% endfor %}
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue