add main login
This commit is contained in:
parent
be8503946f
commit
0ca9c2a7e9
|
@ -26,4 +26,3 @@ class UserForm(forms.Form):
|
||||||
#headimgurl = forms.CharField(label="头像", max_length=200, required=False, widget=forms.TextInput(attrs={'class': 'form-control'}))
|
#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'}))
|
usecomp = forms.ModelChoiceField(label="所属公司", queryset=s_models.Partment.objects.all(), widget=forms.Select(attrs={'class': 'form-control'}))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,9 @@ def company_userdetail(request, uid):
|
||||||
except s_models.User.DoesNotExist:
|
except s_models.User.DoesNotExist:
|
||||||
raise Http404("User does not exist")
|
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))
|
user_form = UserForm(model_to_dict(user))
|
||||||
|
|
||||||
return render(request, 'groups/company_userdetail.html', locals())
|
return render(request, 'groups/company_userdetail.html', locals())
|
||||||
|
|
||||||
def groups_userupdate(request):
|
def groups_userupdate(request):
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from captcha.fields import CaptchaField
|
||||||
|
|
||||||
class UserForm(forms.Form):
|
class UserForm(forms.Form):
|
||||||
username = forms.CharField(max_length=30)
|
#username = forms.CharField(max_length=30)
|
||||||
password = forms.CharField(max_length=30)
|
#password = forms.CharField(max_length=30)
|
||||||
|
captcha = CaptchaField(label='验证码', error_messages={"invalid": "验证码错误"})
|
||||||
|
|
||||||
class CompanyInfoForm(forms.Form):
|
class CompanyInfoForm(forms.Form):
|
||||||
company_nature = (
|
company_nature = (
|
||||||
|
|
|
@ -110,6 +110,9 @@
|
||||||
top: 15px;
|
top: 15px;
|
||||||
width: 12px;
|
width: 12px;
|
||||||
}
|
}
|
||||||
|
#id_captcha_1{
|
||||||
|
width:60%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -140,6 +143,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p style="color:red;text-align: center">{{msg}}</p>
|
<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 class="login-button">
|
||||||
登录
|
登录
|
||||||
</div>
|
</div>
|
||||||
|
@ -228,6 +236,21 @@
|
||||||
// },5000)
|
// },5000)
|
||||||
}
|
}
|
||||||
</script>
|
</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>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -5,6 +5,7 @@ from .models import User,Trouble,Dickey,Partment,Dicclass,Train,Drill,TroubleAcc
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
|
from .forms import UserForm
|
||||||
import json
|
import json
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
import os
|
import os
|
||||||
|
@ -286,19 +287,27 @@ def upfile(req):
|
||||||
def login(req):
|
def login(req):
|
||||||
if req.session.get('userid', None):
|
if req.session.get('userid', None):
|
||||||
return redirect('index')
|
return redirect('index')
|
||||||
|
|
||||||
if req.method == 'POST':
|
if req.method == 'POST':
|
||||||
|
user_form = UserForm(req.POST)
|
||||||
username = req.POST.get('username')
|
username = req.POST.get('username')
|
||||||
password = req.POST.get('password')
|
password = req.POST.get('password')
|
||||||
user = User.objects.filter(username__exact = username, password__exact = password,deletemark=1)
|
user = User.objects.filter(username__exact = username, password__exact = password,deletemark=1)
|
||||||
if user:
|
if user:
|
||||||
#比较成功,跳转index
|
if user_form.is_valid():
|
||||||
|
# 比较成功,跳转index
|
||||||
req.session['userid'] = user[0].userid
|
req.session['userid'] = user[0].userid
|
||||||
# req.session.set_expiry(60*30)
|
# req.session.set_expiry(60*30)
|
||||||
return redirect('index')
|
return redirect('index')
|
||||||
else:
|
else:
|
||||||
return render(req,'login.html',{'msg':'用户名或密码错误!'})
|
msg = '验证码错误'
|
||||||
|
return render(req, 'login.html', locals())
|
||||||
else:
|
else:
|
||||||
return render(req,'login.html')
|
msg = '用户名或密码错误'
|
||||||
|
return render(req,'login.html', locals())
|
||||||
|
else:
|
||||||
|
user_form = UserForm()
|
||||||
|
return render(req,'login.html', locals())
|
||||||
|
|
||||||
def index(req):
|
def index(req):
|
||||||
if not req.session.get('userid', None):
|
if not req.session.get('userid', None):
|
||||||
|
@ -6021,6 +6030,13 @@ def companyinfo(req):
|
||||||
return render(req, 'companyinfo.html',
|
return render(req, 'companyinfo.html',
|
||||||
{'companyinfo': companyinfo_form})
|
{'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):
|
def dump(obj):
|
||||||
print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()]))
|
print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()]))
|
Loading…
Reference in New Issue