Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Insert admin script #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions insert_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
from myblt import init_db, init_engine, new_user, app

if __name__ == "__main__":
app.config.from_pyfile('config/default_config.py')

if len(sys.argv) == 2:
conf = sys.argv[1]
print('Loading additional config %s...', conf)
app.config.from_pyfile('config/' + conf + '_config.py')

init_engine(app.config['DATABASE_URI'])
init_db()

# Insert admin user with default credentials
new_user('admin', 'admin', True)
3 changes: 2 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ def __repr__(self):
class User():
query = db_session.query_property()

def __init__(self, username, password, salt):
def __init__(self, username, password, salt, is_admin=False):
self.username = username
self.password = password
self.salt = salt
self.is_admin = is_admin

def __repr__(self):
return '<User %r>' % (self.username)
Expand Down
4 changes: 2 additions & 2 deletions myblt.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def get_user_invite_codes(user):
return Invite.query.filter(Invite.creator_id == user.id).all()


def new_user(username, password):
def new_user(username, password, is_admin=False):
salt = app.config['SALT']
hashpass = get_hash(password, salt)

user = User(username, hashpass, salt)
user = User(username, hashpass, salt, is_admin)
db_session.add(user)
db_session.commit()

Expand Down