add main login

This commit is contained in:
wcharles 2019-11-01 10:46:44 +08:00
parent be8503946f
commit 0ca9c2a7e9
5 changed files with 304 additions and 263 deletions

View File

@ -26,4 +26,3 @@ class UserForm(forms.Form):
#headimgurl = forms.CharField(label="头像", max_length=200, required=False, widget=forms.TextInput(attrs={'class': 'form-control'}))
usecomp = forms.ModelChoiceField(label="所属公司", queryset=s_models.Partment.objects.all(), widget=forms.Select(attrs={'class': 'form-control'}))

View File

@ -87,8 +87,9 @@ def company_userdetail(request, uid):
except s_models.User.DoesNotExist:
raise Http404("User does not exist")
#UserForm.set_usecomp(s_models.Partment.objects.all())
#UserForm.set_usecomp(s_models.Partment.objects.filter(group__id=1))
user_form = UserForm(model_to_dict(user))
return render(request, 'groups/company_userdetail.html', locals())
def groups_userupdate(request):

View File

@ -1,8 +1,10 @@
from django import forms
from captcha.fields import CaptchaField
class UserForm(forms.Form):
username = forms.CharField(max_length=30)
password = forms.CharField(max_length=30)
#username = forms.CharField(max_length=30)
#password = forms.CharField(max_length=30)
captcha = CaptchaField(label='验证码', error_messages={"invalid": "验证码错误"})
class CompanyInfoForm(forms.Form):
company_nature = (

View File

@ -110,6 +110,9 @@
top: 15px;
width: 12px;
}
#id_captcha_1{
width:60%;
}
</style>
</head>
@ -140,6 +143,11 @@
</div>
</div>
<p style="color:red;text-align: center">{{msg}}</p>
<div class="login-center clearfix">
<div class="login-center-input">
{{ user_form.captcha }}
</div>
</div>
<div class="login-button">
登录
</div>
@ -228,6 +236,21 @@
// },5000)
}
</script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' /* optional */
});
});
$('.captcha').click(function () {
$.getJSON("/groups/refresh_captcha/", function (result) {
$('.captcha').attr('src', result['image_url']);
$('#id_captcha_0').val(result['key'])
});
});
</script>
</body>
</html>

View File

@ -5,6 +5,7 @@ from .models import User,Trouble,Dickey,Partment,Dicclass,Train,Drill,TroubleAcc
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
from .forms import UserForm
import json
from uuid import UUID
import os
@ -286,19 +287,27 @@ def upfile(req):
def login(req):
if req.session.get('userid', None):
return redirect('index')
if req.method == 'POST':
user_form = UserForm(req.POST)
username = req.POST.get('username')
password = req.POST.get('password')
user = User.objects.filter(username__exact = username, password__exact = password,deletemark=1)
if user:
#比较成功跳转index
req.session['userid'] = user[0].userid
# req.session.set_expiry(60*30)
return redirect('index')
if user_form.is_valid():
# 比较成功跳转index
req.session['userid'] = user[0].userid
# req.session.set_expiry(60*30)
return redirect('index')
else:
msg = '验证码错误'
return render(req, 'login.html', locals())
else:
return render(req,'login.html',{'msg':'用户名或密码错误!'})
msg = '用户名或密码错误'
return render(req,'login.html', locals())
else:
return render(req,'login.html')
user_form = UserForm()
return render(req,'login.html', locals())
def index(req):
if not req.session.get('userid', None):
@ -6021,6 +6030,13 @@ def companyinfo(req):
return render(req, 'companyinfo.html',
{'companyinfo': companyinfo_form})
import json
from captcha.models import CaptchaStore
from captcha.helpers import captcha_image_url
def refresh_captcha(request):
hashkey = CaptchaStore.generate_key()
image_url = captcha_image_url(hashkey)
return HttpResponse(json.dumps({'key': hashkey, 'image_url': image_url}), content_type='application/json')
def dump(obj):
print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()]))