Modify and code review

pull/530/head
ibuler 8 years ago
parent f253d2ea69
commit 037d9323a4

@ -5,6 +5,7 @@ from __future__ import unicode_literals
from six import string_types
from itertools import chain
import string
import logging
from django.shortcuts import reverse as dj_reverse
from django.conf import settings
@ -97,3 +98,5 @@ def search_object_attr(obj, value='', attr_list=None, ignore_case=False):
return False
def get_logger(name=None):
return logging.getLogger('jumpserver.%s' % name)

@ -11,7 +11,6 @@ from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from rest_framework.authtoken.models import Token
from common.utils import encrypt, decrypt, date_expired_default
@ -240,13 +239,13 @@ class User(AbstractUser):
def init_all_models():
for model in (UserGroup, User):
if hasattr(model, 'initial'):
if hasattr(model, b'initial'):
model.initial()
def generate_fake():
for model in (UserGroup, User):
if hasattr(model, 'generate_fake'):
if hasattr(model, b'generate_fake'):
model.generate_fake()

@ -10,7 +10,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.core.files.storage import default_storage
from django.db.models import Q
from django.http import HttpResponseRedirect,HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, reverse, redirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
@ -25,14 +25,14 @@ from django.views.generic.detail import DetailView
from formtools.wizard.views import SessionWizardView
from common.utils import get_object_or_none
from common.utils import get_object_or_none, get_logger
from .models import User, UserGroup
from .forms import (UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm)
from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm
from .utils import AdminUserRequiredMixin, user_add_success_next, send_reset_password_mail
logger = logging.getLogger('jumpserver.users.views')
logger = get_logger(__name__)
@method_decorator(sensitive_post_parameters(), name='dispatch')
@ -52,6 +52,10 @@ class UserLoginView(FormView):
auth_login(self.request, form.get_user())
return redirect(self.get_success_url())
def form_invalid(self, form):
logger.debug(form.errors)
return super(UserLoginView, self).form_invalid(form)
def get_success_url(self):
if self.request.user.is_first_login:
return reverse('users:user-first-login')
@ -176,6 +180,7 @@ class UserDeleteView(AdminUserRequiredMixin, DeleteView):
return HttpResponseRedirect(success_url)
class UserDetailView(AdminUserRequiredMixin, DetailView):
model = User
template_name = 'users/user_detail.html'
@ -249,7 +254,7 @@ class UserGroupDeleteView(DeleteView):
class UserForgotPasswordView(TemplateView):
template_name = 'users/forgot_password.html'
def post(self, request, *args, **kwargs):
def post(self, request):
email = request.POST.get('email')
user = get_object_or_none(User, email=email)
if not user:

Loading…
Cancel
Save