def auth_register(): if request.method == "GET": return render_template("auth/registerform.html", form=RegisterForm()) form = RegisterForm(request.form) if not form.validate(): return render_template("auth/registerform.html", form=form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template("auth/registerform.html", form=form, error="Username already taken!") user = User(form.name.data, form.username.data, form.password.data) db.session().add(user) db.session().commit() role = Role() role.account_id = user.id db.session().add(role) db.session().commit() login_user(user) return redirect(url_for("index"))
def auth_register(): if request.method == "GET": return render_template("auth/registerform.html", form=RegisterForm()) register_form = RegisterForm(request.form) if not register_form.validate(): return render_template("auth/registerform.html", form=register_form) user = User.query.filter_by(username=register_form.username.data).first() if user: return render_template("auth/registerform.html", form=register_form, error="Username already taken!") # Everything ok, create new user u = User(register_form.name.data, register_form.username.data, register_form.password.data) db.session().add(u) db.session().commit() # Create a role aswell r = Role() r.account_id = u.id db.session().add(r) db.session().commit() # Login straight away login_user(u) return redirect(url_for("categories_index"))
def roles_create(): form = RoleForm(request.form) if not form.validate(): return render_template("roles/new.html", form = RoleForm) n = form.rolename.data r = Role(n) r.account_id = current_user.id db.session().add(r) db.session().commit() return redirect(url_for("roles_index"))