Commit 067426d5 authored by ibuler's avatar ibuler

[Fixture] 完成用户向导页

parent 87eb1914
...@@ -108,6 +108,7 @@ class TerminalConnectView(LoginRequiredMixin, DetailView): ...@@ -108,6 +108,7 @@ class TerminalConnectView(LoginRequiredMixin, DetailView):
'messages': _('You should use your ssh client tools ' 'messages': _('You should use your ssh client tools '
'connect terminal: {} <br /> <br />' 'connect terminal: {} <br /> <br />'
'{}'.format(self.object.name, self.object.url)), '{}'.format(self.object.name, self.object.url)),
'redirect_url': reverse('applications:terminal-list')
} }
kwargs.update(context) kwargs.update(context)
......
...@@ -252,7 +252,7 @@ def validate_ssh_public_key(text): ...@@ -252,7 +252,7 @@ def validate_ssh_public_key(text):
ssh = sshpubkeys.SSHKey(text) ssh = sshpubkeys.SSHKey(text)
try: try:
ssh.parse() ssh.parse()
except sshpubkeys.InvalidKeyException: except (sshpubkeys.InvalidKeyException, UnicodeDecodeError):
return False return False
except NotImplementedError as e: except NotImplementedError as e:
return False return False
......
...@@ -91,7 +91,10 @@ class UserPublicKeyForm(forms.Form): ...@@ -91,7 +91,10 @@ class UserPublicKeyForm(forms.Form):
help_text=_('Paste your id_rsa.pub here.')) help_text=_('Paste your id_rsa.pub here.'))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if 'instance' in kwargs:
self.instance = kwargs.pop('instance') self.instance = kwargs.pop('instance')
else:
self.instance = None
super(UserPublicKeyForm, self).__init__(*args, **kwargs) super(UserPublicKeyForm, self).__init__(*args, **kwargs)
def clean_public_key(self): def clean_public_key(self):
...@@ -128,15 +131,12 @@ class UserGroupForm(forms.ModelForm): ...@@ -128,15 +131,12 @@ class UserGroupForm(forms.ModelForm):
} }
class UserInfoForm(forms.Form): # class UserInfoForm(forms.Form):
name = forms.CharField(max_length=20, label=_('name')) # name = forms.CharField(max_length=20, label=_('name'))
avatar = forms.ImageField(label=_('avatar'), required=False) # avatar = forms.ImageField(label=_('avatar'), required=False)
wechat = forms.CharField(max_length=30, label=_('wechat'), required=False) # wechat = forms.CharField(max_length=30, label=_('wechat'), required=False)
phone = forms.CharField(max_length=20, label=_('phone'), required=False) # phone = forms.CharField(max_length=20, label=_('phone'), required=False)
enable_otp = forms.BooleanField(required=False, label=_('enable otp')) # enable_otp = forms.BooleanField(required=False, label=_('enable otp'))
class UserPrivateAssetPermissionForm(forms.ModelForm): class UserPrivateAssetPermissionForm(forms.ModelForm):
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
aria-disabled="false" aria-selected="true"> aria-disabled="false" aria-selected="true">
<a href="javascript:void(0)"><span class="number">{% trans 'Step' %} {{ step }}</span></a> <a href="javascript:void(0)"><span class="number">{% trans 'Step' %} {{ step }}</span></a>
</li> </li>
{% endfor %} {% endfor >%}
</ul> </ul>
</div> </div>
<div class="content clearfix"> <div class="content clearfix">
...@@ -54,10 +54,10 @@ ...@@ -54,10 +54,10 @@
<div class="actions clearfix"> <div class="actions clearfix">
<ul> <ul>
{% if wizard.steps.prev %} {% if wizard.steps.prev %}
<li><a class="fl_goto" data-goto="{{ wizard.steps.first }}">{% trans "first 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> <li><a class="fl_goto" name="wizard_goto_step" data-goto="{{ wizard.steps.prev }}">{% trans "Prev step" %}</a></li>
{% endif %} {% endif %}
<li><a id="fl_submit">{% trans "submit" %}</a></li> <li><a id="fl_submit">{% trans "Submit" %}</a></li>
</ul> </ul>
</div> </div>
</div> </div>
......
{% 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 @@ ...@@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django import forms 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 import login as auth_login, logout as auth_logout
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
...@@ -15,6 +16,7 @@ from django.views.decorators.debug import sensitive_post_parameters ...@@ -15,6 +16,7 @@ from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from formtools.wizard.views import SessionWizardView from formtools.wizard.views import SessionWizardView
from django.conf import settings
from common.utils import get_object_or_none from common.utils import get_object_or_none
from ..models import User from ..models import User
...@@ -154,7 +156,7 @@ class UserResetPasswordView(TemplateView): ...@@ -154,7 +156,7 @@ class UserResetPasswordView(TemplateView):
class UserFirstLoginView(LoginRequiredMixin, SessionWizardView): class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
template_name = 'users/first_login.html' template_name = 'users/first_login.html'
form_list = [forms.UserInfoForm, forms.UserPublicKeyForm] form_list = [forms.UserProfileForm, forms.UserPublicKeyForm]
file_storage = default_storage file_storage = default_storage
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
...@@ -162,7 +164,7 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView): ...@@ -162,7 +164,7 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
return redirect(reverse('index')) return redirect(reverse('index'))
return super(UserFirstLoginView, self).dispatch(request, *args, **kwargs) 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 user = self.request.user
for form in form_list: for form in form_list:
for field in form: for field in form:
...@@ -173,19 +175,23 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView): ...@@ -173,19 +175,23 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
user.is_first_login = False user.is_first_login = False
user.is_public_key_valid = True user.is_public_key_valid = True
user.save() 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): def get_context_data(self, **kwargs):
context = super(UserFirstLoginView, self).get_context_data(**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 return context
def get_form_initial(self, step): def get_form_initial(self, step):
user = self.request.user user = self.request.user
if step == '0': if step == '0':
return { return {
'username': user.username or '',
'name': user.name or user.username, 'name': user.name or user.username,
'enable_otp': user.enable_otp or True, 'email': user.email or '',
'wechat': user.wechat or '', 'wechat': user.wechat or '',
'phone': user.phone or '' 'phone': user.phone or ''
} }
...@@ -194,9 +200,10 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView): ...@@ -194,9 +200,10 @@ class UserFirstLoginView(LoginRequiredMixin, SessionWizardView):
def get_form(self, step=None, data=None, files=None): def get_form(self, step=None, data=None, files=None):
form = super(UserFirstLoginView, self).get_form(step, data, files) form = super(UserFirstLoginView, self).get_form(step, data, files)
form.instance = self.request.user
if step is None: if step is None:
step = self.steps.current step = self.steps.current
if step == '1': # if step == '1':
form.user = self.request.user # form.instance = self.request.user
return form return form
...@@ -83,6 +83,9 @@ class Config: ...@@ -83,6 +83,9 @@ class Config:
CAPTCHA_TEST_MODE = False CAPTCHA_TEST_MODE = False
# You can set jumpserver usage url here, that when user submit wizard redirect to
USER_GUIDE_URL = ''
def __init__(self): def __init__(self):
pass pass
......
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