mirror of https://github.com/jumpserver/jumpserver
start capcha support
parent
9803dd9547
commit
90ca5a8bb7
|
@ -61,6 +61,7 @@ INSTALLED_APPS = [
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
'bootstrapform',
|
'bootstrapform',
|
||||||
|
'captcha',
|
||||||
# 'django.contrib.admin',
|
# 'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
|
|
@ -2,21 +2,15 @@
|
||||||
|
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from captcha.fields import CaptchaField
|
||||||
|
|
||||||
from .models import User, UserGroup
|
from .models import User, UserGroup
|
||||||
|
|
||||||
|
|
||||||
# class UserLoginForm(ModelForm):
|
|
||||||
# class Meta:
|
|
||||||
# model = User
|
|
||||||
# fields = [
|
|
||||||
# "email", "password"
|
|
||||||
# ]
|
|
||||||
|
|
||||||
|
|
||||||
class UserLoginForm(forms.Form):
|
class UserLoginForm(forms.Form):
|
||||||
username = forms.CharField(label='用户名', max_length=100)
|
username = forms.CharField(label='用户名', max_length=100)
|
||||||
password = forms.CharField(label='密码', widget=forms.PasswordInput, max_length=100)
|
password = forms.CharField(label='密码', widget=forms.PasswordInput, max_length=100)
|
||||||
|
# captcha = CaptchaField()
|
||||||
|
|
||||||
|
|
||||||
class UserAddForm(ModelForm):
|
class UserAddForm(ModelForm):
|
||||||
|
|
|
@ -43,13 +43,16 @@
|
||||||
<form class="m-t" role="form" method="post" action="{% url 'users:login' %}">
|
<form class="m-t" role="form" method="post" action="{% url 'users:login' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if form.errors %}
|
{% if form.errors %}
|
||||||
<p class="red-fonts">用户名/密码 不正确, 请重试</p>
|
<p class="red-fonts">{{ form.errors }}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if errors %}
|
||||||
|
<p class="red-fonts">{{ errors }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="text" class="form-control" name="username" placeholder="Username" required="">
|
<input type="text" class="form-control" name="{{ form.username.html_name }}" placeholder="Username" required="">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="password" class="form-control" name="password" placeholder="Password" required="">
|
<input type="password" class="form-control" name="{{ form.password.html_name }}" placeholder="Password" required="">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
|
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
|
||||||
|
|
||||||
|
@ -58,12 +61,9 @@
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<p class="text-muted text-center">
|
<p class="text-muted text-center">
|
||||||
{# <small>Do not have an account?</small>#}
|
|
||||||
</p>
|
</p>
|
||||||
{# <a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a>#}
|
|
||||||
</form>
|
</form>
|
||||||
<p class="m-t">
|
<p class="m-t">
|
||||||
{# <small>Inspinia we app framework base on Bootstrap 3 © 2014</small>#}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url, include
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
|
|
||||||
import views
|
import views
|
||||||
|
@ -7,8 +7,9 @@ import api
|
||||||
app_name = 'users'
|
app_name = 'users'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^login$', auth_views.login, {'template_name': 'users/login.html'}, name='login'),
|
url(r'^login$', views.UserLoginView.as_view(), name='login'),
|
||||||
url(r'^logout$', auth_views.logout, {'template_name': 'users/login.html'}, name='logout'),
|
url(r'^logout$', auth_views.logout, {'template_name': 'users/login.html'}, name='logout'),
|
||||||
|
url(r'^captcha/', include('captcha.urls')),
|
||||||
url(r'^password/forget$', views.UserForgetPasswordView.as_view(), name='forget-password'),
|
url(r'^password/forget$', views.UserForgetPasswordView.as_view(), name='forget-password'),
|
||||||
url(r'^password/forget/sendmail-success$',
|
url(r'^password/forget/sendmail-success$',
|
||||||
views.UserForgetPasswordSendmailSuccessView.as_view(), name='forget-password-sendmail-success'),
|
views.UserForgetPasswordSendmailSuccessView.as_view(), name='forget-password-sendmail-success'),
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404, reverse, render, Http404
|
from django.shortcuts import get_object_or_404, reverse, render, Http404, redirect
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -15,6 +15,7 @@ from django.views.generic.detail import DetailView
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.contrib.auth import views as auth_view, authenticate, login
|
||||||
|
|
||||||
from common.utils import get_object_or_none
|
from common.utils import get_object_or_none
|
||||||
|
|
||||||
|
@ -26,6 +27,30 @@ from .utils import AdminUserRequiredMixin, ssh_key_gen, user_add_success_next, s
|
||||||
logger = logging.getLogger('jumpserver.users.views')
|
logger = logging.getLogger('jumpserver.users.views')
|
||||||
|
|
||||||
|
|
||||||
|
class UserLoginView(FormView):
|
||||||
|
template_name = 'users/login.html'
|
||||||
|
form_class = UserLoginForm
|
||||||
|
redirect_field_name = 'next'
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
if self.request.user.is_staff:
|
||||||
|
return redirect(request.GET.get(self.redirect_field_name, reverse('index')))
|
||||||
|
return super(UserLoginView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
form = self.get_form()
|
||||||
|
username = form['username'].value()
|
||||||
|
password = form['password'].value()
|
||||||
|
|
||||||
|
user = authenticate(username=username, password=password)
|
||||||
|
if user is None:
|
||||||
|
kwargs.update({'errors': '账号密码不正确'})
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
login(request, user)
|
||||||
|
return redirect(request.GET.get(self.redirect_field_name, reverse('index')))
|
||||||
|
|
||||||
|
|
||||||
class UserListView(AdminUserRequiredMixin, ListView):
|
class UserListView(AdminUserRequiredMixin, ListView):
|
||||||
model = User
|
model = User
|
||||||
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
|
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
|
||||||
|
|
Loading…
Reference in New Issue