mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-10 11:49:10 +00:00
[Feature] 添加功能,密码过期间隔时间配置,检测用户密码过期 (#2043)
* [Update] user model 添加date_password_last_updated字段, 并在用户详情/个人信息页进行展示、重置密码/修改密码时进行更新;安全设置添加密码过期时间配置项; * [Update] 修改依赖,deb_requirements 删除 gcc automake * [Update] 添加定时任务: 检测用户密码是否过期 * [Update] 登录页面添加检测用户密码是否过期,并给出过期提示,拒绝登录 * [update] 用户密码过期时间5天以内,每天发送重置密码邮件 * [Update] api 登录认证,添加密码过期检测 * [Update] 添加提示用户密码即将过期信息 * [Update] 修改小细节 * [Update] User model 添加密码即将过期/已过期 property属性 * [Update] 修改用户api auth检测用户密码过期逻辑 * [Update] 添加翻译,用户密码过期 * [Update] 用户密码即将过期,发送密码过期提醒邮件 * [Update] 修改检测用户密码过期任务,修改interval为crontab * [Update] 修改翻译小细节 * [Update] 修改翻译小细节 * [Bugfix] 修复在用户更新页面修改密码时, 不更新最后密码修改时间的bug * [Update] 修复小细节 * [Update] 修改系统设置成功提示翻译信息
This commit is contained in:
@@ -96,6 +96,10 @@ class User(AbstractUser):
|
||||
max_length=30, default=SOURCE_LOCAL, choices=SOURCE_CHOICES,
|
||||
verbose_name=_('Source')
|
||||
)
|
||||
date_password_last_updated = models.DateTimeField(
|
||||
auto_now_add=True, blank=True, null=True,
|
||||
verbose_name=_('Date password last updated')
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '{0.name}({0.username})'.format(self)
|
||||
@@ -220,6 +224,34 @@ class User(AbstractUser):
|
||||
def is_staff(self, value):
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_local(self):
|
||||
return self.source == self.SOURCE_LOCAL
|
||||
|
||||
@property
|
||||
def date_password_expired(self):
|
||||
interval = settings.SECURITY_PASSWORD_EXPIRATION_TIME
|
||||
date_expired = self.date_password_last_updated + timezone.timedelta(
|
||||
days=int(interval))
|
||||
return date_expired
|
||||
|
||||
@property
|
||||
def password_expired_remain_days(self):
|
||||
date_remain = self.date_password_expired - timezone.now()
|
||||
return date_remain.days
|
||||
|
||||
@property
|
||||
def password_has_expired(self):
|
||||
if self.is_local and self.password_expired_remain_days < 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def password_will_expired(self):
|
||||
if self.is_local and self.password_expired_remain_days < 5:
|
||||
return True
|
||||
return False
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.name:
|
||||
self.name = self.username
|
||||
@@ -258,7 +290,7 @@ class User(AbstractUser):
|
||||
return False
|
||||
|
||||
def check_public_key(self, public_key):
|
||||
if self.ssH_public_key == public_key:
|
||||
if self.ssh_public_key == public_key:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -340,6 +372,7 @@ class User(AbstractUser):
|
||||
|
||||
def reset_password(self, new_password):
|
||||
self.set_password(new_password)
|
||||
self.date_password_last_updated = timezone.now()
|
||||
self.save()
|
||||
|
||||
def delete(self, using=None, keep_parents=False):
|
||||
|
Reference in New Issue
Block a user