Exemplo n.º 1
0
    def get(self, request, token, user):
        if self.malice_ip():
            return JsonResponse({
                'status': 'malice_check',
                'msg': '失败次数太多,请稍后尝试',
            })

        user = get_object_or_none(
            User,
            id=user,
        )
        if not user:
            return JsonResponse({
                'status': 'token_error',
                'msg': '无效token',
            })
        is_valid = token_generator.check_token(user, token)

        industrys = user.company_set.all().values_list('category__industry__code_name', flat=True)
        user_industry = industrys[0] if len(industrys) > 0 else ''

        if is_valid:
            self.clean_malice()
            return JsonResponse({
                'status': 'ok',
                'msg': '成功',
                'user_industry': user_industry
            })

        return JsonResponse({
            'status': 'token_error',
            'msg': '无效token',
        })
Exemplo n.º 2
0
 def authenticate(self, pk, token):
     try:
         user = User.objects.get(pk=pk)
     except User.DoesNotExist:
         return None
     if token_generator.check_token(user, token):
         return user
     return None
Exemplo n.º 3
0
 def authenticate(self, pk, token):
     try:
         user = User.objects.get(pk=pk)
     except User.DoesNotExist:
         return None
     if token_generator.check_token(user,
         token): 
         return user
     return None
Exemplo n.º 4
0
def token(request, token, user):
    data = {}
    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JSONError("User does not exist.")
    if token_generator.check_token(user, 
        token): 
        return JSONResponse({})
    else:
        return JSONError("Token did not match user.")
Exemplo n.º 5
0
    def authenticate(self, request=None, pk=None, token=None):
        try:
            user = get_user_model().objects.get(pk=pk)
        except get_user_model().DoesNotExist:
            return None

        # Reject users with is_active=False. Custom user models that don't have
        # that attribute are allowed.
        is_active = getattr(user, 'is_active', None)
        if (is_active or is_active is None) and token_generator.check_token(user, token):
            return user
Exemplo n.º 6
0
def token(request, token, user):
    data = {}

    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JSONError("User does not exist.")

    if token_generator.check_token(user, token):
        return JSONResponse({})
    else:
        return JSONError("Token did not match user.")
Exemplo n.º 7
0
    def authenticate(self, pk, token):
        try:
            user = User.objects.get(pk=pk)
        except User.DoesNotExist:
            return None

        TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False)

        if TOKEN_CHECK_ACTIVE_USER and not user.is_active:
            return None

        if token_generator.check_token(user, token):
            return user
        return None
Exemplo n.º 8
0
def token(request, token, user):
    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JsonError("User does not exist.")

    TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False)

    if TOKEN_CHECK_ACTIVE_USER and not user.is_active:
        return JsonError("User account is disabled.")

    if token_generator.check_token(user, token):
        return JsonResponse({})
    else:
        return JsonError("Token did not match user.")
Exemplo n.º 9
0
    def authenticate(self, pk, token):
        try:
            user = User.objects.get(pk=pk)
        except User.DoesNotExist:
            return None

        TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER",
                                          False)

        if TOKEN_CHECK_ACTIVE_USER and not user.is_active:
            return None

        if token_generator.check_token(user, token):
            return user
        return None
Exemplo n.º 10
0
def token(request, token, user):
    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JSONError("User does not exist.")

    TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False)

    if TOKEN_CHECK_ACTIVE_USER and not user.is_active:
        return JSONError("User account is disabled.")

    if token_generator.check_token(user, token):
        return JSONResponse({})
    else:
        return JSONError("Token did not match user.")
Exemplo n.º 11
0
def token(request):
    token = request.REQUEST.get('token')
    user, token = token.split('|')

    try:
        user = int(user)
    except ValueError:
        return JSONError("Inavalid token format.")

    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JSONError("User does not exist.")

    if token_generator.check_token(user, token):
        return JSONResponse({})
    else:
        return JSONError("Token did not match user.")
Exemplo n.º 12
0
def token(request):
    token = request.REQUEST.get('token')
    user, token = token.split('|')

    try:
        user = int(user)
    except ValueError:
        return JSONError("Inavalid token format.")

    try:
        user = User.objects.get(pk=user)
    except User.DoesNotExist:
        return JSONError("User does not exist.")

    if token_generator.check_token(user, token): 
        return JSONResponse({})
    else:
        return JSONError("Token did not match user.")
Exemplo n.º 13
0
def login_empous_user(request):
    username_or_email = request.POST.get('username_or_email',None)
    password = request.POST.get('password',None)
    token = request.POST.get('token',None)
    user = request.POST.get('user',None)
    empous_build = request.POST.get('build',-1)
    ios_token = request.POST.get('iostoken', None)
    using_lite_version = request.POST.get('isEmpousLite', "1")
    can_play_with_continents = request.POST.get('canPlayWithContinents', "0")

    #Check to see if the empous build is supplied is greater than the minimum version
    if empous_build < MIN_EMPOUS_BUILD:
        return HttpResponse(json.dumps(StatusCodes.APP_VERSION_OUTDATED), mimetype='application/json')

    #Check to see if the token is valid, if it is get a new one
    try:
        user = EmpousUser.objects.get(pk=user)
        if token_generator.check_token(user, token):

            #Check app version - only care if not using the lite_version
            if using_lite_version == "0":
                user.using_lite_version = False
                user.save()

            #Check to see if the user is playing with a new version of Empous that supports continents
            if can_play_with_continents == "1":
                user.can_play_with_continents = True
                user.save()

            #Check to see if the iostoken was specified for push notifications
            if ios_token:
                device, wasCreated = IosPushDevice.objects.get_or_create(ios_token=iostoken)
                user.ios_device = device
                user.save()

            #Generate a new token for the user
            token = token_generator.make_token(user)
            return HttpResponse(json.dumps(dict(StatusCodes.SUCCESS.items() + user.dictify(token).items())), mimetype='application/json')
    
    except User.DoesNotExist:
        pass

    if username_or_email and password:
        try:
            empous_user = EmpousUser.objects.get(Q(username__iexact=username_or_email)|Q(email__iexact=username_or_email))

            #Check app version - only care if not using the lite_version
            if using_lite_version == "0":
                empous_user.using_lite_version = False
                empous_user.save()

            #Check to see if the user is playing with a new version of Empous that supports continents
            if can_play_with_continents == "1":
                empous_user.can_play_with_continents = True
                empous_user.save()

            #Check to see if the iostoken was specified for push notifications
            if ios_token:
                device, wasCreated = IosPushDevice.objects.get_or_create(ios_token=iostoken)
                user.ios_device = device
                user.save()

            if password and authenticate(username=empous_user.username, password=password):
                #Get a token for the user
                token = token_generator.make_token(empous_user)
                return HttpResponse(json.dumps(dict(StatusCodes.SUCCESS.items() + empous_user.dictify(token).items())), mimetype='application/json')
        except EmpousUser.DoesNotExist:
            pass

    return HttpResponse(json.dumps(StatusCodes.BAD_CREDENTIALS), mimetype='application/json')