完成注册功能
Posted 002邓诺斯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了完成注册功能相关的知识,希望对你有一定的参考价值。
function fnEnroll() { var zcoUname = document.getElementById("zcuname") var zcoError = document.getElementById("zcerror_box") var zcoUword1 = document.getElementById("zcuword1") var zcoUword2 = document.getElementById("zcuword2") zcoError.innerhtml = "<br>" if (zcoUname.value.length < 6 || zcoUname.value.length > 12) { zcoError.innerHTML = "用户名为6到12位"; return } else if( (zcoUname.value.charCodeAt(0) >= 48) && (zcoUname.value.charCodeAt(0) <= 57)){ zcoError.innerHTML = "用户名首位不能是数字"; return } else for (var i = 0; i < zcoUname.value.length; i++) { if ((zcoUname.value.charCodeAt(i) < 48) || (zcoUname.value.charCodeAt(i) > 57) && (zcoUname.value.charCodeAt(i) < 97) || (zcoUname.value.charCodeAt(i) > 122)) { zcoError.innerHTML = "用户名只能是字母与数字"; return } } if ((zcoUword1.value.length < 6) || (zcoUword1.value.length > 20)) { zcoError.innerHTML = "密码为6到20位"; return } if (zcoUword2.value.length ==0) { zcoError.innerHTML = "请再次输入密码"; return } if (zcoUword1.value()!=zcoUword2.value()){ zcoError.innerHTML="两次密码不一致" isError=false; return isError; } return isError; window.alert("注册成功!!") }
{% extends ‘daohang.html‘ %} {% block title %}注册{% endblock %} {% block head %} <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/zhuce.css‘) }}"> <script src="{{ url_for(‘static‘,filename=‘js/zhuce.js‘) }}"></script> {% endblock %} {% block main %} <div class="box"> <h2>注册</h2> <form action="{{ url_for(‘zhuce‘) }}" method="post"> <div class="input_box"> <input id="uname" type="text" placeholder="请输入用户名" name="username"> </div> <div class="input_box"> <input id="upass" type="password" placeholder="请输入密码" name="password"> </div> <div class="input_box"> <input id="upass1" type="password" placeholder="请再次输入密码"> </div> <div id="error_box"><br></div> <div class="input_box"> <button onclick="fnzhuce()">注册</button> </div> </form> </div> {% endblock %}
@app.route(‘/zhuce/‘, methods=[‘GET‘, ‘POST‘]) def zhuce(): if request.method == ‘GET‘: return render_template(‘zhuce.html‘) else: username = request.form.get(‘username‘) password = request.form.get(‘password‘) user = User.query.filter(User.username == username).first() if user: return ‘username existed‘ else: user = User(username=username, password=password) db.session.add(user) # 数据库操作 db.session.commit() return redirect(url_for(‘denglu‘))
以上是关于完成注册功能的主要内容,如果未能解决你的问题,请参考以下文章