def create_app(): app = Flask(__name__) app.config.from_object('app.config') register_blueprint(app) db.init_app(app) mail.init_app(app) login_manager.init_app(app) login_manager.login_view = 'web.login' login_manager.login_message = '请先登录或注册' # 第一次运行成功之后可以把34-45行注释掉 with app.app_context(): db.create_all(app=app) if not Admin.query.filter_by(nickname='admin').first(): ad = Admin() ad.nickname = 'admin' ad.role = 'super' ad.password = generate_password_hash('123456') with db.auto_commit(): db.session.add(ad) return app
def post(self): login_id = self.get_argument('login_id') pwd = self.get_argument('pwd') name = self.get_argument('name') admin = Admin() admin.name = name admin.login_id = login_id admin.password = hashlib.md5(pwd.encode('utf-8')).hexdigest() admin.purview = 0 admin.deleted = 0 session.add(admin) session.commit()
def create_admin(account, pwd, repwd): """ 创建初始 admin :return: """ if pwd == repwd: with db.auto_commit(): admin = Admin() admin.account = account admin.password = pwd db.session.add(admin) click.echo(account + ' 已成功创建') else: click.echo('两次密码不同,请重新输入') return
def create_admin(name, password, email): """ 设置管理员 :param name: :param password: :param email: :return: """ with db.auto_commit(): admin = Admin() admin.name = name admin.password = password admin.email = email admin.avatar = '/static/admin/images/guest.png' admin.role = Role.query.get(1) db.session.add(admin) print("成功添加管理员,用户名:%s 密码:%s 邮箱:%s" % (name, password, email))
# -*- coding: utf-8 -*- """ @description: @copyright: (c) 2019/3/28 18:17 by Henry. """ from datetime import datetime __author__ = 'Henry' from app import create_app from app.models.base import db from app.models.admin import Admin app = create_app() with app.app_context(): with db.auto_commit(): # 创建一个超级管理员 user = Admin() user.nickname = 'Admin' user.username = '******' user.password = '******' user.email = '*****@*****.**' db.session.add(user)