mirror of https://github.com/jumpserver/jumpserver
[Fixture] 完成用户向导页
parent
87eb1914fb
commit
067426d5e0
|
@ -108,6 +108,7 @@ class TerminalConnectView(LoginRequiredMixin, DetailView):
|
|||
'messages': _('You should use your ssh client tools '
|
||||
'connect terminal: {} <br /> <br />'
|
||||
'{}'.format(self.object.name, self.object.url)),
|
||||
'redirect_url': reverse('applications:terminal-list')
|
||||
}
|
||||
|
||||
kwargs.update(context)
|
||||
|
|
|
@ -252,7 +252,7 @@ def validate_ssh_public_key(text):
|
|||
ssh = sshpubkeys.SSHKey(text)
|
||||
try:
|
||||
ssh.parse()
|
||||
except sshpubkeys.InvalidKeyException:
|
||||
except (sshpubkeys.InvalidKeyException, UnicodeDecodeError):
|
||||
return False
|
||||
except NotImplementedError as e:
|
||||
return False
|
||||
|
|
|
@ -91,7 +91,10 @@ class UserPublicKeyForm(forms.Form):
|
|||
help_text=_('Paste your id_rsa.pub here.'))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.instance = kwargs.pop('instance')
|
||||
if 'instance' in kwargs:
|
||||
self.instance = kwargs.pop('instance')
|
||||
else:
|
||||
self.instance = None
|
||||
super(UserPublicKeyForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean_public_key(self):
|
||||
|
@ -128,15 +131,12 @@ class UserGroupForm(forms.ModelForm):
|
|||
}
|
||||
|
||||
|
||||
class UserInfoForm(forms.Form):
|
||||
name = forms.CharField(max_length=20, label=_('name'))
|
||||
avatar = forms.ImageField(label=_('avatar'), required=False)
|
||||
wechat = forms.CharField(max_length=30, label=_('wechat'), required=False)
|
||||
phone = forms.CharField(max_length=20, label=_('phone'), required=False)
|
||||
enable_otp = forms.BooleanField(required=False, label=_('enable otp'))
|
||||
|
||||
|
||||
|
||||
# class UserInfoForm(forms.Form):
|
||||
# name = forms.CharField(max_length=20, label=_('name'))
|
||||
# avatar = forms.ImageField(label=_('avatar'), required=False)
|
||||
# wechat = forms.CharField(max_length=30, label=_('wechat'), required=False)
|
||||
# phone = forms.CharField(max_length=20, label=_('phone'), required=False)
|
||||
# enable_otp = forms.BooleanField(required=False, label=_('enable otp'))
|
||||
|
||||
|
||||
class UserPrivateAssetPermissionForm(forms.ModelForm):
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
aria-disabled="false" aria-selected="true">
|
||||
<a href="javascript:void(0)"><span class="number">{% trans 'Step' %} {{ step }}</span></a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endfor >%}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="content clearfix">
|
||||
|
@ -54,10 +54,10 @@
|
|||
<div class="actions clearfix">
|
||||
<ul>
|
||||
{% if wizard.steps.prev %}
|
||||
<li><a class="fl_goto" data-goto="{{ wizard.steps.first }}">{% trans "first step" %}</a></li>
|
||||
<li><a class="fl_goto" name="wizard_goto_step" data-goto="{{ wizard.steps.prev }}">{% trans "prev step" %}</a></li>
|
||||
<li><a class="fl_goto" data-goto="{{ wizard.steps.first }}">{% trans "First step" %}</a></li>
|
||||
<li><a class="fl_goto" name="wizard_goto_step" data-goto="{{ wizard.steps.prev }}">{% trans "Prev step" %}</a></li>
|
||||
{% endif %}
|
||||
<li><a id="fl_submit">{% trans "submit" %}</a></li>
|
||||
<li><a id="fl_submit">{% trans "Submit" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap %}
|
||||
|
||||
|
||||
{% block custom_head_css_js %}
|
||||
{{ wizard.form.media }}
|
||||
<link href="{% static 'css/plugins/steps/jquery.steps.css' %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
{% block first_login_message %}{% endblock %}
|
||||
{% block content %}
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="ibox">
|
||||
<div class="ibox-title">
|
||||
<h5>{% trans 'First Login' %}</h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
</a>
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="fa fa-wrench"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div class="alert alert-success" id="messages">
|
||||
{% trans 'Welcome to use jumpserver, visit ' %}
|
||||
<a href="{{ user_guide_url }}">{% trans 'Use guide' %}</a> {% trans ' for more information' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block custom_foot_js %}
|
||||
<script>
|
||||
$(document).on('click', ".fl_goto", function(){
|
||||
var $form = $('#fl_form');
|
||||
$('<input />', {'name': 'wizard_goto_step', 'value': $(this).data('goto'), 'type': 'hidden'}).appendTo($form);
|
||||
$form.submit();
|
||||
return false;
|
||||
}).on('click', '#fl_submit', function(){
|
||||
$('#fl_form').submit();
|
||||
return false;
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
from django import forms
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth import login as auth_login, logout as auth_logout
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.files.storage import default_storage
|
||||
|
@ -15,6 +16,7 @@ from django.views.decorators.debug import sensitive_post_parameters
|
|||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import FormView
|
||||
from formtools.wizard.views import SessionWizardView
|
||||
from django.conf import settings
|
||||
|
||||
from common.utils import get_object_or_none
|
||||
from ..models import User
|
||||
|
@ -154,7 +156,7 @@ class UserResetPasswordView(TemplateView):
|
|||
|
||||
class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
|
||||
template_name = 'users/first_login.html'
|
||||
form_list = [forms.UserInfoForm, forms.UserPublicKeyForm]
|
||||
form_list = [forms.UserProfileForm, forms.UserPublicKeyForm]
|
||||
file_storage = default_storage
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
|
@ -162,7 +164,7 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
|
|||
return redirect(reverse('index'))
|
||||
return super(UserFirstLoginView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def done(self, form_list, form_dict, **kwargs):
|
||||
def done(self, form_list, **kwargs):
|
||||
user = self.request.user
|
||||
for form in form_list:
|
||||
for field in form:
|
||||
|
@ -173,19 +175,23 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
|
|||
user.is_first_login = False
|
||||
user.is_public_key_valid = True
|
||||
user.save()
|
||||
return redirect(reverse('index'))
|
||||
context = {
|
||||
'user_guide_url': settings.CONFIG.USER_GUIDE_URL
|
||||
}
|
||||
return render(self.request, 'users/first_login_done.html', context)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UserFirstLoginView, self).get_context_data(**kwargs)
|
||||
context.update({'app': _('Users'), 'action': _('First Login')})
|
||||
context.update({'app': _('Users'), 'action': _('First login')})
|
||||
return context
|
||||
|
||||
def get_form_initial(self, step):
|
||||
user = self.request.user
|
||||
if step == '0':
|
||||
return {
|
||||
'username': user.username or '',
|
||||
'name': user.name or user.username,
|
||||
'enable_otp': user.enable_otp or True,
|
||||
'email': user.email or '',
|
||||
'wechat': user.wechat or '',
|
||||
'phone': user.phone or ''
|
||||
}
|
||||
|
@ -194,9 +200,10 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
|
|||
def get_form(self, step=None, data=None, files=None):
|
||||
form = super(UserFirstLoginView, self).get_form(step, data, files)
|
||||
|
||||
form.instance = self.request.user
|
||||
if step is None:
|
||||
step = self.steps.current
|
||||
|
||||
if step == '1':
|
||||
form.user = self.request.user
|
||||
# if step == '1':
|
||||
# form.instance = self.request.user
|
||||
return form
|
||||
|
|
|
@ -83,6 +83,9 @@ class Config:
|
|||
|
||||
CAPTCHA_TEST_MODE = False
|
||||
|
||||
# You can set jumpserver usage url here, that when user submit wizard redirect to
|
||||
USER_GUIDE_URL = ''
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue