def create_user(): username = prompt('用户名').strip() password = prompt_pass('密码').strip() repassword = prompt_pass('重复密码').strip() is_super = prompt_bool('超级用户') is_staff = prompt_bool('后台用户') if not all([username, password, repassword]): print('请输入完整数据') return if password != repassword: print('两次输入密码不同') return connect_db() user = User() user.username = username user.password = password user.is_super = is_super user.is_staff = is_staff db_session.add(user) db_session.commit() print('创建用户成功!')
def register(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] repassword = request.form['repassword'] if password != repassword: flash('两次输入密码不一致') elif check_exists(username): flash('用户已存在') else: user = User(username=username) user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') if password != repassword or not password: flash('两次密码不一致') elif User.query.filter_by(username=username).first(): flash('用户名已注册') else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def create_user(): connect_db() username = prompt('username') password = prompt_pass('password') repassword = prompt_pass('repassword') is_super = prompt_bool('is super(default: True)', default='y') is_staff = prompt_bool('is staff(default: True)', default='y') if password != repassword: print('the two password is not same!') return user = User() user.username = username user.password = password user.is_super = is_super user.is_staff = is_staff db_session.add(user) db_session.commit() print('create user success')
def register(): if request.method == 'POST': form = request.form username = form['username'] password = form['password'] repassword = form['repassword'] if not all([username, password, repassword]): flash('请填写完整信息!') elif password != repassword: flash('两次输入密码不一致!') else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def register(): if request.method == 'POST': form = request.form username = form.get('username') password = form.get('password') repassword = form.get('repassword') if not all([username, password, repassword]): flash('请填写完整信息') elif password != repassword: flash('两次输入密码不一致') elif User.query.filter(User.username==username).first(): flash('用户已存在') else: user = User() user.username=username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def register(): if request.method == "POST": username = request.form.get("username").strip() password = request.form.get("password").strip() repassword = request.form.get("repassword").strip() if not all([username, repassword, password]): flash("请输入完整信息") elif User.query.filter_by(username=username).first(): flash("用户名已被使用") elif password != repassword: flash("两次输入密码不同") else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for(".login")) return render_template("register.html")