def chats_add_user(chat_id): if not _admin_of(current_user.id, chat_id): abort(403) form = AddUserForm(request.form) if form.validate(): user_id = User.get(form.name.data).id if ChatUser.find(user_id, chat_id) is None: ChatUser.create(user_id, chat_id) return redirect(url_for('chats_management', chat_id=chat_id))
def users_login(): if request.method == "GET": return render_template("users/login.html", form=UserLoginForm()) form = UserLoginForm(request.form) user = User.get(form.username.data, form.password.data) if not user: return render_template("users/login.html", form=form, error="No such username or password") login_user(user) return redirect(url_for("index"))
# Application functionality from application import views from application.users import models, views from application.chats import models, views from application.messages import models, views from application.chatusers import models # User authentication from application.users.models import User from os import urandom app.config["SECRET_KEY"] = urandom(32) @login_manager.user_loader def load_user(user_id): return User.query.get(user_id) try: db.create_all() except Exception: pass if User.get('admin') is None: user = User('admin', 'admin', True) db.session.add(user) db.session.commit()