try:
user=UserProfile.objects.get(Q(username=username)|Q(email=username))
if user.check_password(password):
return user
else:
user = UserProfile(username=username, password='')
return user
except UserProfile.DoesNotExist:
user = UserProfile(username='',password=password)
return user
if not user.username:
return render(request, 'login.html', {'msg':u'用户名不存在','username':user_name,'password':pass_word})
elif not user.password:
return render(request, 'login.html', {'msg':u'密码错误','username':user_name,'password':pass_word})
else:
login(request, user)
return render(request, 'index.html', {})