summaryrefslogtreecommitdiff
path: root/web/apps/users/views.py
blob: 5a4457fbb73628fb76c9d7206e2041d4de3583e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.auth.backends import ModelBackend
from django.db.models import Q

# Create your views here.
from rest_framework import permissions

from .models import UserProfile, UserMachine


class CustomBackend(ModelBackend):
    """
    custom user auth
    """
    # todo use auth.py
    def authenticate(self, username=None, password=None, **kwargs):
        try:
            user = UserProfile.objects.get(Q(username=username))
            if user.check_password(password):
                return user


        except Exception as e:
            return None