def create_group(): ep_infos = get_ep_infos() if request.method == 'POST': form = NewGroup() if form.validate_on_submit(): exists = Group.query.filter_by(name=form.name.data).first() if exists: flash('分组已存在,不可创建同名分组', 2) return common_render('page/manage_group/create/index.html', ep_infos=ep_infos) with db.auto_commit(): group = Group(name=form.name.data, info=form.info.data) db.session.add(group) db.session.flush() for auth in form.auths.data: meta = find_auth_module(auth) if meta: auth = Auth(auth=meta.auth, module=meta.module, group_id=group.id) db.session.add(auth) flash('创建成功', 1) else: flash(form.errors_info) return common_render('page/manage_group/create/index.html', ep_infos=ep_infos)
def handler(e): if isinstance(e, WebException): return common_render('page/error/index.html', msg=e.msg, code=e.code, url=redirect_back_url()), e.code if isinstance(e, APIException): return e if isinstance(e, HTTPException): e.code = e.code e.msg = e.description return common_render('page/error/index.html', msg=e.msg, code=e.code, url=redirect_back_url()), e.code # error_code = 20000 # return APIException(msg, code, error_code) else: if not app.config['DEBUG']: import traceback app.logger.error(traceback.format_exc()) return UnknownException() else: raise e
def create_user(): groups = Group.query.all() if request.method == 'POST': form = RegisterForm() if form.validate_on_submit(): exists = User.query.filter_by(username=form.username.data).first() if exists: flash('该用户已被使用,请输入其他的用户名!', 2) return common_render('page/manage_user/create/index.html') new_user = User(username=form.username.data, email=form.email.data, group_id=form.group_id.data) new_user.set_password(form.password.data) db.session.add(new_user) db.session.commit() flash('添加成功!', 1) else: flash(form.errors_info) return common_render('page/manage_user/create/index.html', groups=groups)
def get_users(): ep_infos = get_ep_infos() groups = Group.query.all() group_id = request.args.get('group_id') users = User.query.filter_by( group_id=group_id).all() if group_id else User.query.all() return common_render('page/manage_user/list/index.html', users=users, groups=groups, ep_infos=ep_infos)
def links_add(): if request.method == 'POST': req = request.form.to_dict() f = FriendLinks(title=req['title'], url=req['url'], email=req['email'], create_time=req['create-time']) db.session.add(f) db.session.commit() flash('添加成功!') return common_render('page/links/create/index.html')
def reset_password(): if request.method == 'POST': form = ResetPasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.oldPassword.data): current_user.password = form.newPassword.data db.session.commit() flash('修改成功!', 1) else: flash(form.errors_info) return common_render('page/user/reset_password/index.html')
def info(): res = { "框架名称": "kamm后台管理框架", "框架版本": "v0.0.1", "作者": "Shimada666", "主页位置": "/", "服务器版本": f"{platform.platform()}", "数据库版本": "mysql5.7", "上传限制": "2M", "用户角色": "总管理员", "框架描述": "一套flask+layui的开发框架", "技术支持": "copyright @2019 Shimada666", } return common_render('page/system_info/index.html', info=res)
def information(): if request.method == 'POST': form = UserInfoForm() if form.validate_on_submit(): current_user.real_name = form.real_name.data current_user.gender = form.gender.data current_user.phone = form.phone.data current_user.birthday = form.birthday.data current_user.email = form.email.data current_user.about = form.about.data db.session.commit() flash('修改成功!', 1) else: flash(form.errors_info) return common_render('page/user/information/index.html')
def login(): if current_user.is_authenticated: flash('已登录!') return redirect(url_for('home.index')) if request.method == 'POST': form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data.lower()).first() if user is not None and user.validate_password(form.password.data): flash('登录成功!', 1) login_user(user, True) return redirect(url_for('home.index')) else: flash('用户名或密码错误!', 2) else: flash(form.errors_info) return common_render('page/login/index.html')
def page_not_found(e): return common_render('page/error/index.html', msg='页面不存在!', code=e.code, url=redirect_back_url()), 404
def links_list(): links = FriendLinks.query.all() return common_render('page/links/list/index.html', links=links)
def get_groups(): ep_infos = get_ep_infos() groups = Group.query.all() return common_render('page/manage_group/list/index.html', groups=groups, ep_infos=ep_infos)
def not_found3(): return common_render('page/error/index.html', msg='测试', code=123)
def index(): return common_render('page/index/index.html')