|
|
|
@ -1,14 +1,13 @@ |
|
|
|
|
from django.core.cache import cache |
|
|
|
|
from rest_framework.authentication import BaseAuthentication |
|
|
|
|
from rest_framework.exceptions import AuthenticationFailed |
|
|
|
|
from api.models import Token, UserInfo |
|
|
|
|
from api.models import UserInfo |
|
|
|
|
from rest_framework.permissions import BasePermission |
|
|
|
|
from fir_ser.settings import CACHE_KEY_TEMPLATE |
|
|
|
|
import base64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExpiringTokenAuthentication(BaseAuthentication): |
|
|
|
|
|
|
|
|
|
def authenticate(self, request): |
|
|
|
|
def get_user_from_auth(request): |
|
|
|
|
if request.method == "OPTIONS": |
|
|
|
|
return None |
|
|
|
|
request_token = request.META.get("HTTP_AUTHORIZATION", request.query_params.get("token", None)) |
|
|
|
@ -42,3 +41,29 @@ class ExpiringTokenAuthentication(BaseAuthentication): |
|
|
|
|
return user_obj, auth_token |
|
|
|
|
else: |
|
|
|
|
raise AuthenticationFailed({"code": 1001, "error": "用户被禁用"}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExpiringTokenAuthentication(BaseAuthentication): |
|
|
|
|
|
|
|
|
|
def authenticate(self, request): |
|
|
|
|
return get_user_from_auth(request) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StoragePermission(BasePermission): |
|
|
|
|
message = "权限不足" |
|
|
|
|
|
|
|
|
|
def has_permission(self, request, view): |
|
|
|
|
results = get_user_from_auth(request) |
|
|
|
|
if results and results[0]: |
|
|
|
|
return results[0].storage_active |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SuperSignPermission(BasePermission): |
|
|
|
|
message = "权限不足" |
|
|
|
|
|
|
|
|
|
def has_permission(self, request, view): |
|
|
|
|
results = get_user_from_auth(request) |
|
|
|
|
if results and results[0]: |
|
|
|
|
return results[0].supersign_active |
|
|
|
|
return True |
|
|
|
|