Esempio n. 1
0
def init_admin():
    admin = Admin.query.first()
    if not admin:
        admin = Admin(name='admin')
        admin.set_password_hash('123456')
    db.session.add(admin)
    db.session.commit()
Esempio n. 2
0
def add_default_admin(credentials: list) -> None:
    """
    add default admin into database
    """

    with apps.app_context():
        admin = Admin(credentials[0], credentials[1], credentials[2])
        admin.save()
Esempio n. 3
0
def fake_admin():
    '''
    生成管理员帐号
    '''
    with db.auto_commit():

        admin = Admin(
            username='******',
            blog_title='Myblog',
            blog_sub_title="hello world",
            name='Mima Kirigoe',
            about='Um, l, Mima Kirigoe, had a fun time as a member of CHAM...')
        admin.password = '******'
        db.session.add(admin)
Esempio n. 4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        data = form.data
        admin_query = Admin.objects(admin_id=data["admin_id"]).first()
        if not admin_query.check_pwd(data["password"]):
            flash("the password is incorrect !")
            return redirect(url_for("admin.login"))
        session["admin_id"] = data["admin_id"]
        return redirect(request.args.get("next") or url_for("admin.index"))
    return render_template("admin/login.html", form=form)
Esempio n. 5
0
def admin_add():
    """
    represents admin account add processing url
    """

    real_name = request.form.get("real_name")
    user_name = request.form.get("user_name")
    pass_word = request.form.get("pass_word")

    try:
        new_admin = Admin(
            real_name,
            user_name,
            pass_word
        )
        new_admin.save()
    except IntegrityError:
        flash("error", "credentials anda duplicated")
    except Exception as Error:
        flash("error", Error.__str__())
    else:
        flash("success", "berhasil menambahkan admin")

    return redirect(url_for("dashboard.admin"))
Esempio n. 6
0
def create_user(username, password):
    if not all([username, password]):
        print('参数不足')
    admin = Admin.query.first()
    if admin:
        admin.username = username
        admin.password = password
    else:
        admin = Admin()
        admin.username = username
        admin.password = password
        admin.blog_title = '我的博客'
        admin.blog_sub_title = '博客子标题'
        admin.about = '这什么都没有'
        db.session.add(admin)
    categroy = Category.query.first()
    if categroy is None:
        print('创建初始分类')
        categroy = Category(name='默认')
        with db.auto_commit():
            db.session.add(categroy)
    db.session.commit()
Esempio n. 7
0
 def validate_admin_id(self, field):
     admin_id = field.data
     admins_count = Admin.objects(admin_id=admin_id).count()
     if admins_count == 0:
         raise ValidationError("this admin is not exist !")
Esempio n. 8
0
# coding:utf8
from app import app
from werkzeug.security import check_password_hash, generate_password_hash
from app.model import Admin
if __name__ == '__main__':
    new_admin = Admin(email="*****@*****.**",
                      admin_id="admin",
                      password=generate_password_hash(("123456")))
    new_admin.save()
    app.run()
Esempio n. 9
0
def create_admin():
    with app.app_context():
        admin_repository = AdminRepository()
        if admin_repository.count() == 0:
            admin = Admin(username="******", password=hash_password("1234"))
            admin_repository.add(admin)