Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
662 additions
and
65 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "2.0.0.dev1" | ||
__version__ = "2.0.0.dev2" |
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
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,39 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import LabelCommand | ||
|
||
from account.conf import settings | ||
from account.models import PasswordExpiry | ||
|
||
|
||
class Command(LabelCommand): | ||
|
||
help = "Create user-specific password expiration period." | ||
label = "username" | ||
|
||
def add_arguments(self, parser): | ||
super(Command, self).add_arguments(parser) | ||
parser.add_argument( | ||
"-e", "--expire", | ||
type=int, | ||
nargs="?", | ||
default=settings.ACCOUNT_PASSWORD_EXPIRY, | ||
help="number of seconds until password expires" | ||
) | ||
|
||
def handle_label(self, username, **options): | ||
User = get_user_model() | ||
try: | ||
user = User.objects.get(username=username) | ||
except User.DoesNotExist: | ||
return "User \"{}\" not found".format(username) | ||
|
||
expire = options["expire"] | ||
|
||
# Modify existing PasswordExpiry or create new if needed. | ||
if not hasattr(user, "password_expiry"): | ||
PasswordExpiry.objects.create(user=user, expiry=expire) | ||
else: | ||
user.password_expiry.expiry = expire | ||
user.password_expiry.save() | ||
|
||
return "User \"{}\" password expiration set to {} seconds".format(username, expire) |
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,45 @@ | ||
import datetime | ||
import pytz | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import BaseCommand | ||
|
||
from account.models import PasswordHistory | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = "Create password history for all users without existing history." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"-d", "--days", | ||
type=int, | ||
nargs="?", | ||
default=10, | ||
help="age of current password (in days)" | ||
) | ||
parser.add_argument( | ||
"-f", "--force", | ||
action="store_true", | ||
help="create new password history for all users, regardless of existing history" | ||
) | ||
|
||
def handle(self, *args, **options): | ||
User = get_user_model() | ||
users = User.objects.all() | ||
if not options["force"]: | ||
users = users.filter(password_history=None) | ||
|
||
if not users: | ||
return "No users found without password history" | ||
|
||
days = options["days"] | ||
timestamp = datetime.datetime.now(tz=pytz.UTC) - datetime.timedelta(days=days) | ||
|
||
# Create new PasswordHistory on `timestamp` | ||
PasswordHistory.objects.bulk_create( | ||
[PasswordHistory(user=user, timestamp=timestamp) for user in users] | ||
) | ||
|
||
return "Password history set to {} for {} users".format(timestamp, len(users)) |
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
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
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 @@ | ||
# empty for now |
Oops, something went wrong.