write query profile
This commit is contained in:
34
UI/main.py
34
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)
|
Reference in New Issue
Block a user