def delete_user(id): delForm = forms.UserDeleteForm() if delForm.validate_on_submit(): if current_user.id == id: flash("You can't delete yourself!", "danger") return redirect(url_for("admin.users")) user = User.query.filter_by(id=id).first() User.query.filter_by(id=id).delete() db.session.commit() flash(f"{user.email} deleted!", "success") else: flash("Form couldn't validate!", "danger") return redirect(url_for("admin.users"))
def deleteUser(id): delForm = forms.UserDeleteForm() if delForm.validate_on_submit(): if current_user.id == id: flash('You can\'t delete yourself!', 'danger') return redirect(url_for('admin.users')) user = User.query.filter_by(id=id).first() User.query.filter_by(id=id).delete() db.session.commit() flash('%s deleted!' % user.email, 'success') return redirect(url_for('admin.users')) else: flash("Form couldn't validate!", 'danger') return redirect(url_for('admin.users'))
def users(): users = User.query.all() inviteForm = forms.InviteUserForm() if inviteForm.validate_on_submit(): invitation = UserInvitation.new_invite(inviteForm.email.data) msg = UserInvitation.deliver_invite(invitation) flash(msg, "success") db.session.commit() return redirect(url_for("admin.users")) return render_template( "admin/users.html", users=users, delForm=forms.UserDeleteForm(), editForm=forms.UserEditForm(), inviteForm=inviteForm, )
def users(): users = User.query.all() delForm = forms.UserDeleteForm() editForm = forms.UserEditForm() inviteForm = forms.InviteUserForm() if inviteForm.validate_on_submit(): validemail = User.validate_email(inviteForm.email.data) if not validemail: flash("%s does not appear to be a valid, deliverable email address." % inviteForm.email.data, "danger") return redirect(request.referrer) newUser = User(email=validemail) db.session.add(newUser) db.session.commit() send_user_invite_email(newUser) flash('Invitation Sent!', 'success') return redirect(url_for('admin.users')) return render_template("admin/users.html", users=users, delForm=delForm, editForm=editForm, inviteForm=inviteForm)