def login_user(request): # tmp_user = get_object_or_404(User,username=request.POST.get("username"),password=request.POST.get("password")) # try: if request.user.is_authenticated: Logger.logout(request.user, None, None) logout(request) tmp_user = User.objects.filter(username=request.POST.get("username")) if len(tmp_user) == 0: return render(request, 'accounts/login.html', {'error_message': 'کاربر موردنظر یافت نشد!'}) tmp_user = get_object(User, username=request.POST.get("username")) if tmp_user.password != request.POST.get("password"): return render(request, 'accounts/login.html', {'error_message': 'رمز اشتباهه -.-'}) if not tmp_user.is_active: return render(request, 'accounts/login.html', {'error_message': 'لطفاً حساب خود را تایید کنید.'}) if tmp_user.is_charity: login(request, user=tmp_user) Logger.login(request.user, None, None) return HttpResponseRedirect(reverse('accounts:charity_dashboard')) elif tmp_user.is_benefactor: login(request, tmp_user) Logger.login(request.user, None, None) return HttpResponseRedirect(reverse('accounts:benefactor_dashboard')) else: login(request, tmp_user) Logger.login(request.user, None, None) return HttpResponseRedirect(reverse('admin'))
def logout_user(request): if not request.user.is_authenticated: # TODO Raise Authentication Error context = error_context_generate('Authentication Error', 'You are not Signed In!', 'accounts:login_view') template = loader.get_template('accounts/error_page.html') return HttpResponse(template.render(context, request)) Logger.logout(request.user, None, None) logout(request) template = loader.get_template('accounts/login.html') return HttpResponse(template.render({}, request))