Commit b8bebc9b authored by ibuler's avatar ibuler

Merge branch 'api' of code.simcu.com:jumpserver/jumpserver into api

parents 2c112558 90ca5a8b
......@@ -61,6 +61,7 @@ INSTALLED_APPS = [
'rest_framework',
'rest_framework.authtoken',
'bootstrapform',
'captcha',
# 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......
......@@ -2,21 +2,15 @@
from django.forms import ModelForm
from django import forms
from captcha.fields import CaptchaField
from .models import User, UserGroup
# class UserLoginForm(ModelForm):
# class Meta:
# model = User
# fields = [
# "email", "password"
# ]
class UserLoginForm(forms.Form):
username = forms.CharField(label='用户名', max_length=100)
password = forms.CharField(label='密码', widget=forms.PasswordInput, max_length=100)
# captcha = CaptchaField()
class UserAddForm(ModelForm):
......
......@@ -43,13 +43,16 @@
<form class="m-t" role="form" method="post" action="{% url 'users:login' %}">
{% csrf_token %}
{% 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 %}
<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 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>
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
......@@ -58,12 +61,9 @@
</a>
<p class="text-muted text-center">
{# <small>Do not have an account?</small>#}
</p>
{# <a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a>#}
</form>
<p class="m-t">
{# <small>Inspinia we app framework base on Bootstrap 3 &copy; 2014</small>#}
</p>
</div>
</div>
......
from django.conf.urls import url
from django.conf.urls import url, include
from django.contrib.auth import views as auth_views
import views
......@@ -7,8 +7,9 @@ import api
app_name = 'users'
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'^captcha/', include('captcha.urls')),
url(r'^password/forget$', views.UserForgetPasswordView.as_view(), name='forget-password'),
url(r'^password/forget/sendmail-success$',
views.UserForgetPasswordSendmailSuccessView.as_view(), name='forget-password-sendmail-success'),
......
......@@ -4,7 +4,7 @@ from __future__ import unicode_literals
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.urls import reverse_lazy
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.conf import settings
from django.http import HttpResponseRedirect
from django.contrib.auth import views as auth_view, authenticate, login
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')
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):
model = User
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
......
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