diff --git a/apps/applications/views.py b/apps/applications/views.py
index 1cd70a865..4aa8e2a4c 100644
--- a/apps/applications/views.py
+++ b/apps/applications/views.py
@@ -108,6 +108,7 @@ class TerminalConnectView(LoginRequiredMixin, DetailView):
'messages': _('You should use your ssh client tools '
'connect terminal: {}
'
'{}'.format(self.object.name, self.object.url)),
+ 'redirect_url': reverse('applications:terminal-list')
}
kwargs.update(context)
diff --git a/apps/common/utils.py b/apps/common/utils.py
index 1fa8e3915..505d129d0 100644
--- a/apps/common/utils.py
+++ b/apps/common/utils.py
@@ -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
diff --git a/apps/users/forms.py b/apps/users/forms.py
index e4727c479..1c56e3a43 100644
--- a/apps/users/forms.py
+++ b/apps/users/forms.py
@@ -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):
diff --git a/apps/users/templates/users/first_login.html b/apps/users/templates/users/first_login.html
index 80b13cec2..1e16d4948 100644
--- a/apps/users/templates/users/first_login.html
+++ b/apps/users/templates/users/first_login.html
@@ -34,7 +34,7 @@
aria-disabled="false" aria-selected="true">
{% trans 'Step' %} {{ step }}
- {% endfor %}
+ {% endfor >%}
diff --git a/apps/users/templates/users/first_login_done.html b/apps/users/templates/users/first_login_done.html
new file mode 100644
index 000000000..650a2057c
--- /dev/null
+++ b/apps/users/templates/users/first_login_done.html
@@ -0,0 +1,51 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load i18n %}
+{% load bootstrap %}
+
+
+{% block custom_head_css_js %}
+{{ wizard.form.media }}
+
+{% endblock %}
+{% block first_login_message %}{% endblock %}
+{% block content %}
+
+
+
+
+
+
{% trans 'First Login' %}
+
+
+
+
+
+
+
+{% endblock %}
+{% block custom_foot_js %}
+
+{% endblock %}
diff --git a/apps/users/views/login.py b/apps/users/views/login.py
index 67bdd8e3a..fcbdac30c 100644
--- a/apps/users/views/login.py
+++ b/apps/users/views/login.py
@@ -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
diff --git a/config_example.py b/config_example.py
index d600832f0..7903d609d 100644
--- a/config_example.py
+++ b/config_example.py
@@ -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