123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
- @AUTHOR: ASJRD018
- @NAME: AnsjerOA
- @software: PyCharm
- @DATE: 2018/8/13 15:36
- @Version: python3.6
- @MODIFY DECORD:ansjer dev
- @file: TokenObject.py
- @Contact: chanjunkai@163.com
- """
- from Ansjer.config import OAUTH_ACCESS_TOKEN_SECRET
- import jwt
- from Model.models import oauth_user
- class TokenObject:
- def __init__(self, token=None):
- if token == 'debug':
- token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvaWQiOiJhNDVmN2U3MC04NTAwLTRkOTItYWRkZS1mMmMxMDdkYzVkYzEiLCJsYW5nIjpudWxsLCJleHAiOjE1NzA5ODY4Mzl9.uDLfBjUQqWQB0pOMtXN17iikEbxztDhcus_UCH36XZw'
- if token == 'test':
- token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvaWQiOiJhNDVmN2U3MC04NTAwLTRkOTItYWRkZS1mMmMxMDdkYzVkYzEiLCJsYW5nIjpudWxsLCJleHAiOjE1MzUwNzQ0Njl9.MW7iU_LMo_uqceYeoePVZiyJoYc1wZTJTxpxOa0aha8'
- self.token = token
- self.code = 0
- self.userID = None
- self.lang = None
- def valid(self):
- try:
- res = jwt.decode(self.token, OAUTH_ACCESS_TOKEN_SECRET, algorithms='HS256')
- self.userID = res.get('userID', None)
- self.lang = res.get('lang', None)
- except jwt.ExpiredSignatureError as e:
- print('过期')
- print(repr(e))
- self.code = 307
- except Exception as e:
- print(repr(e))
- self.code = 303
- def userID(self):
- oid = self.oid
- if oid is not None:
- oauth_user_qs = oauth_user.objects.filter(oid=oid)
- if oauth_user_qs.exists():
- return oauth_user_qs[0].userID.userID
- return None
|