Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create super user as part of Azure deployment
- Loading branch information
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.contrib.auth.management.commands import createsuperuser | ||
from django.core.management import CommandError | ||
|
||
|
||
class Command(createsuperuser.Command): | ||
help = 'Non-interactively create an admin user' | ||
|
||
def add_arguments(self, parser): | ||
super(Command, self).add_arguments(parser) | ||
parser.add_argument('--password', default=None, | ||
help='The password for the admin.') | ||
|
||
def handle(self, *args, **options): | ||
password = options.get('password') | ||
username = options.get('username') | ||
|
||
if password and not username: | ||
raise CommandError('--username is required if specifying --password') | ||
|
||
super(Command, self).handle(*args, **options) | ||
|
||
if password: | ||
database = options.get('database') | ||
db = self.UserModel._default_manager.db_manager(database) | ||
user = db.get(username=username) | ||
user.set_password(password) | ||
user.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ "$#" -ne 3 ]]; then echo "Usage: $0 <username> <email> <password>" >&2; exit 1; fi | ||
|
||
set -o errexit | ||
|
||
python app/manage.py wait_for_db | ||
python app/manage.py migrate | ||
python app/manage.py create_admin --noinput --username="$1" --email="$2" --password="$3" |