diff --git a/UI/datacheck.py b/UI/datacheck.py index 2253fcc..dd4c4fb 100644 --- a/UI/datacheck.py +++ b/UI/datacheck.py @@ -33,3 +33,9 @@ class AddUserForm(FlaskForm): InputRequired(message='Privilege is required.'), Regexp(r'^[0-9]$|^10$', message='Privilege must be an integer between 0 and 10.') ]) + +class QueryProfileForm(FlaskForm): + username = StringField('Username', validators=[ + InputRequired(message='Username is required.'), + Regexp(r'^[a-zA-Z][a-zA-Z0-9_]{0,19}$', message='Username must start with a letter and can only contain letters, numbers, and underscores (max 20 characters).') + ]) \ No newline at end of file diff --git a/UI/main.py b/UI/main.py index a9ab537..886fb02 100644 --- a/UI/main.py +++ b/UI/main.py @@ -156,3 +156,37 @@ def add_user(): flash(error, 'danger') return render_template('adduser.html', form=form) + +@app.route('/admin/queryprofile', methods=['GET', 'POST']) +def query_profile(): + if 'username' not in session or utils.GetPrivilege(session['username'], ExecCommand) < 10: + return redirect(url_for('login')) + + form = QueryProfileForm() + if form.validate_on_submit(): + cur_username = session['username'] + query_username = form.username.data + + # 调用 ExecCommand 执行查询命令 + query_response = ExecCommand(f'query_profile -c {cur_username} -u {query_username}') + + if query_response.strip() == '-1': + error = 'Failed to retrieve profile.' + flash(error, 'danger') + return redirect(url_for('query_profile')) + else: + profile_data = query_response.split(' ') + if len(profile_data) >= 4: + user_info = { + 'username': profile_data[0], + 'name': profile_data[1], + 'email': profile_data[2], + 'privilege': profile_data[3] + } + return render_template('queryprofile.html', user_info=user_info, form=form) + else: + error = "Profile data is incomplete or incorrect." + flash(error, 'danger') + return redirect(url_for('query_profile')) + + return render_template('queryprofile.html', form=form) \ No newline at end of file diff --git a/UI/templates/adduser.html b/UI/templates/adduser.html index a286537..226737c 100644 --- a/UI/templates/adduser.html +++ b/UI/templates/adduser.html @@ -25,7 +25,7 @@ {{ form.hidden_tag() }}
- +
Username must start with a letter and can only contain letters, numbers, and underscores (max 20 characters).
diff --git a/UI/templates/base.html b/UI/templates/base.html index 0ea0d6e..c80a300 100644 --- a/UI/templates/base.html +++ b/UI/templates/base.html @@ -29,6 +29,7 @@