16 changed files with 100 additions and 46 deletions
-
3abonapp/locale/ru/LC_MESSAGES/django.po
-
6abonapp/models.py
-
7abonapp/templates/abonapp/log.html
-
2abonapp/views.py
-
32clientsideapp/locale/ru/LC_MESSAGES/django.po
-
8clientsideapp/templates/clientsideapp/debt_buy.html
-
5clientsideapp/templates/clientsideapp/modal_service_buy.html
-
12clientsideapp/views.py
-
3devapp/models.py
-
2devapp/templates/devapp/devices.html
-
42djing/auth_backends.py
-
5djing/settings.py
-
6msg_app/models.py
-
5taskapp/context_proc.py
-
2taskapp/handle.py
-
2taskapp/locale/ru/LC_MESSAGES/django.po
@ -0,0 +1,42 @@ |
|||
from django.contrib.auth.backends import ModelBackend |
|||
from accounts_app.models import BaseAccount, UserProfile |
|||
from abonapp.models import Abon |
|||
|
|||
|
|||
class CustomAuthBackend(ModelBackend): |
|||
def authenticate(self, request, username=None, password=None, **kwargs): |
|||
if username is None: |
|||
username = kwargs.get(BaseAccount.USERNAME_FIELD) |
|||
print('username', username) |
|||
try: |
|||
user = BaseAccount._default_manager.get_by_natural_key(username) |
|||
print('user', user) |
|||
if user.check_password(password): |
|||
if user.is_admin: |
|||
print('is adm') |
|||
auser = UserProfile.objects.get_by_natural_key(username) |
|||
else: |
|||
print('no adm') |
|||
auser = Abon.objects.get_by_natural_key(username) |
|||
if self.user_can_authenticate(auser): |
|||
print('can auth') |
|||
return auser |
|||
print('no can auth') |
|||
else: |
|||
print('wrong password') |
|||
except BaseAccount.DoesNotExist: |
|||
print('does not exist') |
|||
# Run the default password hasher once to reduce the timing |
|||
# difference between an existing and a non-existing user (#20760). |
|||
BaseAccount().set_password(password) |
|||
|
|||
def get_user(self, user_id): |
|||
try: |
|||
user = BaseAccount._default_manager.get(pk=user_id) |
|||
if user.is_admin: |
|||
user = UserProfile._default_manager.get(pk=user_id) |
|||
else: |
|||
user = Abon._default_manager.get(pk=user_id) |
|||
except BaseAccount.DoesNotExist: |
|||
return None |
|||
return user if self.user_can_authenticate(user) else None |
|||
@ -1,12 +1,13 @@ |
|||
from django.contrib.auth.models import AnonymousUser |
|||
|
|||
from taskapp.models import Task |
|||
from accounts_app.models import UserProfile |
|||
|
|||
|
|||
def get_active_tasks_count(request): |
|||
tasks_count = 0 |
|||
if not isinstance(request.user, AnonymousUser): |
|||
tasks_count = Task.objects.filter(recipients=request.user, state='S').count() |
|||
if isinstance(request.user, UserProfile): |
|||
tasks_count = Task.objects.filter(recipients__in=[request.user], state='S').count() |
|||
return { |
|||
'tasks_count': tasks_count |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue