From a25b2df4531d12c77a548eee497dd3fb02c3f0f7 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Tue, 23 Sep 2014 21:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webroot/AutoSa/AutoSa/views.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/webroot/AutoSa/AutoSa/views.py b/webroot/AutoSa/AutoSa/views.py index 3b671aa60..e8bd74e44 100644 --- a/webroot/AutoSa/AutoSa/views.py +++ b/webroot/AutoSa/AutoSa/views.py @@ -170,18 +170,23 @@ def login(request): else: username = request.POST.get('username') password = request.POST.get('password') - user = User.objects.get(username=username) - if password == user.password: - request.session['username'] = username - if user.is_admin: - request.session['admin'] = 1 - elif user.is_superuser: - request.session['admin'] = 2 + user = User.objects.filter(username=username) + if user: + user = user[0] + if user and password == user.password: + request.session['username'] = username + if user.is_admin: + request.session['admin'] = 1 + elif user.is_superuser: + request.session['admin'] = 2 + else: + request.session['admin'] = 0 + return HttpResponseRedirect('/') else: - request.session['admin'] = 0 - return HttpResponseRedirect('/') + error = '密码错误,请重新输入。' + else: - error = '密码错误,请重新输入。' + error = '用户不存在。' return render_to_response('login.html', {'error': error})