예제 #1
0
def initialize_database():
    "Drop current database and initialize a new one"
    db.drop_all()
    db.create_all()
    admin = models.Admin(app.config['USERNAME'], app.config['PASSWORD'])
    db.session.add(admin)
    db.session.commit()

    print "Database initialized"
예제 #2
0
def admin_add():
    form = forms.Admin_add()
    if form.validate_on_submit():
        admin_obj = models.Admin(name=form.name.data,
                                 pwd=form.pwd.data,
                                 is_super=0,
                                 role_id=form.role.data)
        mysql_db.session.add(admin_obj)
        mysql_db.session.commit()
        return redirect(url_for('admin.admins', page=1))
    return render_template('admin/admin_add.html', form=form)
예제 #3
0
def add_admin(username, password):
    # hash the password using bcrypt
    from app import bcrypt
    password_hash = bcrypt.generate_password_hash(password)
    password_hash = password_hash.decode("utf-8")

    # add to database
    from app import models, db
    admin = models.Admin(username=username, password_hash=password_hash)
    db.session.add(admin)
    db.session.commit()
예제 #4
0
def admin_add():
    form = AdminForm()
    from werkzeug.security import generate_password_hash
    if form.validate_on_submit():
        data = form.data
        admin = app_models.Admin(name=data["name"],
                                 pwd=generate_password_hash(data["pwd"]),
                                 role_id=data["role_id"],
                                 is_super=1)
        db.session.add(admin)
        db.session.commit()
        flash("添加管理员成功!", "ok")
    return render_template("admin/admin_add.html", form=form)
예제 #5
0
파일: manage.py 프로젝트: patallen/crumble
def create_admin():
    email = prompt("Enter an email for this Administrator")
    pass1 = prompt_pass("Enter password")
    pass2 = prompt_pass("Re-enter password")

    if pass1 == pass2:
        try:
            admin = models.Admin(email=email)
            admin.password = pass1
            admin.save()
        except:
            print "Email already exists in database."
    else:
        print "Passwords do not match. Try again."
예제 #6
0
def admin_add():
    form = AdminForm()
    if form.validate_on_submit():
        data = form.data
        admin = models.Admin(
            name=data["name"],
            pwd=generate_password_hash(data["pwd"]),
            role_id=data["role_id"],
            is_super=1  # 非超级管理员均为1
        )
        db.session.add(admin)
        db.session.commit()
        db.session.remove()
        flash("管理员添加成功!", "ok")
    return render_template('admin/admin_add.html', form=form)
예제 #7
0
# 建库
def CreateDB():
    print('[create movie db OK!]')
    base_mysql = 'mysql -u' + MYSQL['USR'] + ' -p' + MYSQL['PWD'] + ' -e'
    read_mysql = base_mysql + '"create database IF NOT EXISTS %s;"' % MYSQL[
        'DB']
    os.system(read_mysql)


# 添加角色 ()
role_admin = models.Role(name='超级管理员', auths='')  # 超管 id为1 按插入顺序
role_vip_user = models.Role(name='VIP会员')  # id为 2
role_user = models.Role(name='普通会员')  # 普通会员 id为3
# 添加 管理员
admin_egan = models.Admin(name=USER_ADMIN['name'],
                          pwd=generate_password_hash(USER_ADMIN['pwd']),
                          is_super=0,
                          role_id=1)

CreateDB()  # 建库
app = create_app()  # 实例app
# 每个操作使用上下文管理进行, 不能在同一个with 中进行

with app.app_context():
    db.create_all()  # 建表
    # db.drop_all() # 删表

# 添加基础角色
with app.app_context():
    db.session.add_all([
        role_admin,
        role_user,
예제 #8
0
    if z.upload_dir:
        try:
            shutil.rmtree(z.upload_dir)
        except FileNotFoundError:
            pass
    db.session.delete(z)

for ba in bas:
    db.session.delete(ba)

db.session.commit()

#admin:

ad = models.Admin(username='******',
                  password=md5(('admin').encode('utf-8')).hexdigest(),
                  role='admin')

db.session.add(ad)
db.session.commit()

# #users:

# u=models.User(username='******',email='*****@*****.**',password='******',total=0, role='user', imgurl='images/av.jpg')

# #achievements
# a1=models.Achievement(category='Education',subcategory='Language',name='Spanish',level=1,points=10,imgurl='https://goo.gl/dqduFX',description="This achievement shows that you have basic understaning of Spanish language.",requirements="You should finish approximately 1 year of Spanish classes and be able to make a very basic conversation and read simple articles.")
# a2=models.Achievement(category='Education',subcategory='Language',name='Spanish',level=2,points=100,imgurl='https://goo.gl/dqduFX',description="This achievement shows that you are an intermediate Spanish languege user.",requirements="You should finish approximately 2 to 3 years of Spanish classes and be able to make simply express your thoughts and feelings.")
# a3=models.Achievement(category='Education',subcategory='Language',name='Spanish',level=3,points=1000,imgurl='https://goo.gl/dqduFX',description="This achievement shows that you an advanced Spanish languege user.",requirements="You should finish approximately 5 years of Spanish classes, feel comfortable when speaking Spanish and be able to read Spanish articles.")
# a4=models.Achievement(category='Education',subcategory='Language',name='Spanish',level=4,points=5000,imgurl='https://goo.gl/dqduFX',description="This achievement shows that you have mastered the Spanish languege.",requirements="Being a native speaker or being completely fluent in this language.")
예제 #9
0
from app import db, models
db.create_all()

rootAdmin = models.Admin(name="ADMIN", role=models.ROLE_FULL_ADMIN)
rootAdmin.set_password("password")
db.session.add(rootAdmin)
db.session.commit()