update user
This commit is contained in:
parent
810e6a6e60
commit
7fb945217f
45
src/admin.py
45
src/admin.py
@ -99,3 +99,48 @@ def removeuser():
|
|||||||
else:
|
else:
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("admin.index"))
|
||||||
return render_template("admin/result.html", opname="删除用户出现意外", opresult=error, cur_time=datetime.now())
|
return render_template("admin/result.html", opname="删除用户出现意外", opresult=error, cur_time=datetime.now())
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/updateuser/<int:uid>/', methods=("POST",))
|
||||||
|
@admin_login_required
|
||||||
|
def updateuser(uid):
|
||||||
|
error = None
|
||||||
|
db = get_db()
|
||||||
|
cur = db.cursor()
|
||||||
|
cur.execute("select * from user where user_id=%s", (uid))
|
||||||
|
userinfo = cur.fetchone()
|
||||||
|
usermail = request.form['usermail']
|
||||||
|
username = request.form['username']
|
||||||
|
if userinfo is None:
|
||||||
|
error = "%s号用户不存在!" % (uid)
|
||||||
|
if username is None or len(username) == 0:
|
||||||
|
username = None
|
||||||
|
if usermail is None or len(usermail) == 0:
|
||||||
|
usermail = None
|
||||||
|
elif not validateEmail(usermail):
|
||||||
|
error = "邮箱不合法"
|
||||||
|
|
||||||
|
if error is None:
|
||||||
|
if usermail is not None:
|
||||||
|
try:
|
||||||
|
cur.execute("update user set user_mail=%s where user_id=%s", (usermail, uid))
|
||||||
|
db.commit()
|
||||||
|
except pymysql.IntegrityError as _e:
|
||||||
|
error = "邮箱重复! %s" % (_e)
|
||||||
|
db.rollback()
|
||||||
|
except pymysql.Error as _e:
|
||||||
|
error = "未知错误: %s" % (_e)
|
||||||
|
db.rollback()
|
||||||
|
if username is not None and error is None:
|
||||||
|
try:
|
||||||
|
cur.execute("update user set user_name=%s where user_id=%s", (username, uid))
|
||||||
|
db.commit()
|
||||||
|
except pymysql.IntegrityError as _e:
|
||||||
|
error = "用户名重复! %s" % (_e)
|
||||||
|
db.rollback()
|
||||||
|
except pymysql.Error as _e:
|
||||||
|
error = "未知错误: %s" % (_e)
|
||||||
|
db.rollback()
|
||||||
|
if error is None:
|
||||||
|
return redirect(url_for("admin.index"))
|
||||||
|
return render_template("admin/result.html", opname="更新用户信息失败", opresult=error, cur_time=datetime.now())
|
||||||
|
|||||||
@ -2,9 +2,42 @@
|
|||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<h2 class="text-center">{% block title %}管理主页{% endblock %}</h2>
|
<h2 class="text-center">{% block title %}管理主页{% endblock %}</h2>
|
||||||
|
<script>
|
||||||
|
function control_modal(op, modal_id, uid='1'){
|
||||||
|
modal_elm = document.getElementById(modal_id);
|
||||||
|
if (op == 'active') {
|
||||||
|
modal_elm.classList.add('active');
|
||||||
|
model_form = document.getElementById("modal-form");
|
||||||
|
model_form.attributes['action'].nodeValue = '/admin/updateuser/' + uid + '/';
|
||||||
|
} else {
|
||||||
|
modal_elm.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="modal" id="modal-updateuser">
|
||||||
|
<a onclick="control_modal('diactiate', 'modal-updateuser')" class="modal-overlay" aria-label="Close"></a>
|
||||||
|
<div class="modal-container">
|
||||||
|
<div class="modal-header">
|
||||||
|
<a onclick="control_modal('diactiate', 'modal-updateuser')" class="btn btn-clear float-right" aria-label="Close"></a>
|
||||||
|
<div class="modal-title h5">修改用户信息</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="modal-form" method="post" class="form-group" action="/admin/updateuser/1/">
|
||||||
|
<label class="form-label" for="username">用户名</label>
|
||||||
|
<input class="form-input" name="username" id="username">
|
||||||
|
<label class="form-label" for="usermail">邮箱</label>
|
||||||
|
<input class="form-input" name="usermail" id="usermail">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<input form="modal-form" class="btn btn-primary" type="submit" value="提交">
|
||||||
|
<a href="" class="btn">取消</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>
|
<span>
|
||||||
<h3 class="px-2">用户列表</h3>
|
<h3 class="px-2">用户列表</h3>
|
||||||
@ -24,7 +57,10 @@
|
|||||||
<td>{{ user['user_name'] }}</td>
|
<td>{{ user['user_name'] }}</td>
|
||||||
<td>{{ user['user_mail'] }}</td>
|
<td>{{ user['user_mail'] }}</td>
|
||||||
<td>{{ user['user_limit'] / 1024 / 1024 }}GB</td>
|
<td>{{ user['user_limit'] / 1024 / 1024 }}GB</td>
|
||||||
<td><a href="/admin/removeuser?uid={{user['user_id']}}" >删除</a></td>
|
<td>
|
||||||
|
<a class="btn" href="/admin/removeuser?uid={{user['user_id']}}" >删除</a>
|
||||||
|
<a class="btn" onclick="control_modal('active', 'modal-updateuser', '{{user['user_id']}}')">修改</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user