Commit 21ac3eaf authored by BaiJiangJie's avatar BaiJiangJie Committed by 老广

[Update] 用户创建添加密码设置策略 (#2731)

* [Update] 优化创建用户的密码策略功能

* [Update] 优化用户初始密码设置以及清除初始密码

* [Update] 优化创建用户的密码策略功能

* [Update]统一变量名前缀

* [Update] 用户密码策略去掉自定义策略

* [Update] 修改小问题

* [Update] 优化创建用户密码策略

* [Update] 翻译

* [Update] 优化mfa按钮排布和间距

* [Update] 优化mfa按钮样式由前端控制

* [Update] 优化前端密码策略按钮的显示与隐藏

* [Update] 用户创建设置密码添加密码校验弹窗
parent b237cbb2
This diff is collapsed.
...@@ -221,6 +221,3 @@ class DjangoSettingsAPI(APIView): ...@@ -221,6 +221,3 @@ class DjangoSettingsAPI(APIView):
except (json.JSONDecodeError, TypeError): except (json.JSONDecodeError, TypeError):
data[k] = str(v) data[k] = str(v)
return Response(data) return Response(data)
...@@ -22,6 +22,12 @@ class UserCheckOtpCodeForm(forms.Form): ...@@ -22,6 +22,12 @@ class UserCheckOtpCodeForm(forms.Form):
class UserCreateUpdateForm(OrgModelForm): class UserCreateUpdateForm(OrgModelForm):
EMAIL_SET_PASSWORD = _('Reset link will be generated and sent to the user')
CUSTOM_PASSWORD = _('Set password')
PASSWORD_STRATEGY_CHOICES = (
(0, EMAIL_SET_PASSWORD),
(1, CUSTOM_PASSWORD)
)
role_choices = ((i, n) for i, n in User.ROLE_CHOICES if i != User.ROLE_APP) role_choices = ((i, n) for i, n in User.ROLE_CHOICES if i != User.ROLE_APP)
password = forms.CharField( password = forms.CharField(
label=_('Password'), widget=forms.PasswordInput, label=_('Password'), widget=forms.PasswordInput,
...@@ -36,6 +42,10 @@ class UserCreateUpdateForm(OrgModelForm): ...@@ -36,6 +42,10 @@ class UserCreateUpdateForm(OrgModelForm):
widget=forms.Textarea(attrs={'placeholder': _('ssh-rsa AAAA...')}), widget=forms.Textarea(attrs={'placeholder': _('ssh-rsa AAAA...')}),
help_text=_('Paste user id_rsa.pub here.') help_text=_('Paste user id_rsa.pub here.')
) )
password_strategy = forms.ChoiceField(
choices=PASSWORD_STRATEGY_CHOICES, required=True, initial=0,
widget=forms.RadioSelect(), label=_('Password strategy')
)
class Meta: class Meta:
model = User model = User
......
...@@ -74,6 +74,9 @@ ...@@ -74,6 +74,9 @@
$(document).ready(function () { $(document).ready(function () {
$('.select2').select2(); $('.select2').select2();
$('#id_date_expired').daterangepicker(dateOptions); $('#id_date_expired').daterangepicker(dateOptions);
var mfa_radio = $('#id_otp_level');
mfa_radio.addClass("form-inline");
mfa_radio.children().css("margin-right","15px")
}) })
</script> </script>
{% endblock %} {% endblock %}
...@@ -2,15 +2,83 @@ ...@@ -2,15 +2,83 @@
{% load i18n %} {% load i18n %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% block user_template_title %}{% trans "Create user" %}{% endblock %} {% block user_template_title %}{% trans "Create user" %}{% endblock %}
{#{% block username %}#}
{# {% bootstrap_field form.username layout="horizontal" %}#}
{#{% endblock %}#}
{% block password %} {% block password %}
<div class="form-group"> {% bootstrap_field form.password_strategy layout="horizontal" %}
<label class="col-sm-2 control-label">{% trans 'Password' %}</label> <div class="form-group" id="custom_password">
<div class="col-sm-8 controls" style="margin-top: 8px;"> {% bootstrap_field form.password layout="horizontal" %}
{% trans 'Reset link will be generated and sent to the user. ' %}
</div> </div>
{# 密码popover #}
<div id="container">
<div class="popover fade bottom in" role="tooltip" id="popover777" style=" display: none; width:260px;">
<div class="arrow" style="left: 50%;"></div>
<h3 class="popover-title" style="display: none;"></h3>
<h4>{% trans 'Your password must satisfy' %}</h4><div id="id_password_rules" style="color: #908a8a; margin-left:20px; font-size:15px;"></div>
<h4 style="margin-top: 10px;">{% trans 'Password strength' %}</h4><div id="id_progress"></div>
<div class="popover-content"></div>
</div> </div>
</div>
<script>
function passwordCheck() {
if ($('#id_password').length != 1) {
return
}
var el = $('#id_password_rules'),
idPassword = $('#id_password'),
idPopover = $('#popover777'),
container = $('#container'),
progress = $('#id_progress'),
password_check_rules = {{ password_check_rules|safe }},
minLength = 6,
top = idPassword.offset().top - $('.navbar').outerHeight(true) - $('.page-heading').outerHeight(true) - 10 + 34,
left = 377,
i18n_fallback = {
"veryWeak": "{% trans 'Very weak' %}",
"weak": "{% trans 'Weak' %}",
"normal": "{% trans 'Normal' %}",
"medium": "{% trans 'Medium' %}",
"strong": "{% trans 'Strong' %}",
"veryStrong": "{% trans 'Very strong' %}"
};
$.each(password_check_rules, function (idx, rules) {
if(rules.key === 'id_security_password_min_length'){
minLength = rules.value
}
});
// 初始化popover
initPopover(container, progress, idPassword, el, password_check_rules, i18n_fallback);
// 监听事件
idPassword.on('focus', function () {
idPopover.css('top', top);
idPopover.css('left', left);
idPopover.css('display', 'block');
});
idPassword.on('blur', function () {
idPopover.css('display', 'none');
});
idPassword.on('keyup', function(){
var password = idPassword.val();
checkPasswordRules(password, minLength);
});
}
var password_strategy_radio_input = 'input[type=radio][name=password_strategy]';
function passwordStrategyFieldsDisplay(){
var val = $('input:radio[name="password_strategy"]:checked').val();
if(val === '0'){
$('#custom_password').addClass('hidden')
}else {
$('#custom_password').removeClass('hidden')
}
}
$(document).ready(function () {
passwordCheck();
passwordStrategyFieldsDisplay()
}).on('change', password_strategy_radio_input, function(){
passwordStrategyFieldsDisplay()
})
</script>
{% endblock %} {% endblock %}
...@@ -81,9 +81,14 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView): ...@@ -81,9 +81,14 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
success_message = create_success_msg success_message = create_success_msg
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) check_rules = get_password_check_rules()
context.update({'app': _('Users'), 'action': _('Create user')}) context = {
return context 'app': _('Users'),
'action': _('Create user'),
'password_check_rules': check_rules,
}
kwargs.update(context)
return super().get_context_data(**kwargs)
def form_valid(self, form): def form_valid(self, form):
user = form.save(commit=False) user = form.save(commit=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment