密码模块修改

This commit is contained in:
qihao.gong@jikimo.com
2023-07-13 17:31:16 +08:00
parent 3544c6a957
commit 5e8e380a8e
3 changed files with 40 additions and 43 deletions

View File

@@ -10,53 +10,51 @@ class ResCompany(models.Model):
_inherit = "res.company"
password_expiration = fields.Integer(
"Days",
default=60,
help="How many days until passwords expire",
help="密码过期前多少天",
string='密码过期天数'
)
password_length = fields.Integer(
"Characters",
default=12,
help="Minimum number of characters",
help="最小字符数",
string='密码最低长度'
)
password_lower = fields.Integer(
"Lowercase",
default=1,
help="Require number of lowercase letters",
help="需要小写字母数",
string='密码中包含小写字母数(最少)'
)
password_upper = fields.Integer(
"Uppercase",
default=1,
help="Require number of uppercase letters",
string='密码中包含大写字母数(最少)'
)
password_numeric = fields.Integer(
"Numeric",
default=1,
help="Require number of numeric digits",
help="需要数字位数",
string='密码中包含数字(最少)'
)
password_special = fields.Integer(
"Special",
default=1,
help="Require number of unique special characters",
help="需要唯一特殊字符的数量",
string='密码中包含特殊字符(最少)'
)
password_estimate = fields.Integer(
"Estimation",
default=3,
help="Required score for the strength estimation. Between 0 and 4",
help="强度估计所需的分数。介于0和4之间",
string='密码强度等级'
)
password_history = fields.Integer(
"History",
default=30,
help="Disallow reuse of this many previous passwords - use negative "
"number for infinite, or 0 to disable",
help="禁止重复使用这许多以前的密码 - 使用负数字表示无限,或 0 表示禁用",
string='禁止重复使用这许多以前的密码-使用负数字表示无限或0表示禁用'
)
password_minimum = fields.Integer(
"Minimum Hours",
default=24,
help="Amount of hours until a user may change password again",
help="用户再次更改密码之前的小时数",
string='更改密码间隔时长(小时)'
)
@api.constrains("password_estimate")
def _check_password_estimate(self):
if 0 > self.password_estimate > 4:
raise ValidationError(_("The estimation must be between 0 and 4."))
raise ValidationError(_("估计值必须介于 0 和 4 之间"))

View File

@@ -87,29 +87,29 @@ class ResUsers(models.Model):
message = []
if company_id.password_lower:
message.append(
_("\n* Lowercase letter (at least %s characters)")
_("\n* 小写字母(至少%s个字符)")
% str(company_id.password_lower)
)
if company_id.password_upper:
message.append(
_("\n* Uppercase letter (at least %s characters)")
_("\n* 大写字母(至少%s个字符)")
% str(company_id.password_upper)
)
if company_id.password_numeric:
message.append(
_("\n* Numeric digit (at least %s characters)")
_("\n* 数字(至少%s字符)")
% str(company_id.password_numeric)
)
if company_id.password_special:
message.append(
_("\n* Special character (at least %s characters)")
_("\n* 特殊字符(至少%s个字符)")
% str(company_id.password_special)
)
if message:
message = [_("Must contain the following:")] + message
message = [_("必须包含以下内容:")] + message
if company_id.password_length:
message = [
_("Password must be %d characters or more.")
_("密码必须为%d个字符或更多。")
% company_id.password_length
] + message
return "\r".join(message)
@@ -173,8 +173,8 @@ class ResUsers(models.Model):
if write_date + delta > datetime.now():
raise UserError(
_(
"Passwords can only be reset every %d hour(s). "
"Please contact an administrator for assistance."
"密码只能每%d小时重置一次。 "
"请联系管理员寻求帮助。"
)
% pass_min
)
@@ -195,13 +195,12 @@ class ResUsers(models.Model):
lambda r: crypt.verify(password, r.password_crypt)
):
raise UserError(
_("Cannot use the most recent %d passwords")
_("无法使用使用过的莫玛(%d个密码内)")
% rec_id.company_id.password_history
)
def _set_encrypted_password(self, uid, pw):
"""It saves password crypt history for history rules"""
res = super(ResUsers, self)._set_encrypted_password(uid, pw)
self.write({"password_history_ids": [(0, 0, {"password_crypt": pw})]})
return res

View File

@@ -25,64 +25,64 @@
<div class="content-group">
<div class="mt16">
<span>
Password expires in
密码过期
<field
name="password_expiration"
class="oe_inline"
/>
days.
</span>
</div>
<div class="mt16">
<span>
User can change password in
用户可以更改密码在
<field name="password_minimum" class="oe_inline" />
hours again.
小时之后.
</span>
</div>
<div class="mt16">
<span>
Disallow reuse of
禁止重复使用
<field name="password_history" class="oe_inline" />
previous passwords.
以前的密码.
</span>
<div class="text-muted">
Use negative number for infinite, or 0 to disable
使用负数表示无限,或使用 0 禁用
</div>
</div>
<div class="mt16">
<span>
Minimum number of characters
最小字符数
<field name="password_length" class="oe_inline" />
</span>
</div>
<div class="mt16">
<span>
Minimum number of lowercase characters
最少小写字符数
<field name="password_lower" class="oe_inline" />
</span>
</div>
<div class="mt16">
<span>
Minimum number of uppercase characters
最少大写字符数
<field name="password_upper" class="oe_inline" />
</span>
</div>
<div class="mt16">
<span>
Minimum number of numeric characters
最小数字字符数
<field name="password_numeric" class="oe_inline" />
</span>
</div>
<div class="mt16">
<span>
Minimum number of special characters
最小特殊字符数
<field name="password_special" class="oe_inline" />
</span>
</div>
<div class="mt16">
<span>
Minimum number of strength estimation
最小强度估计数
<field name="password_estimate" class="oe_inline" />
</span>
</div>