【发布时间】:2018-11-05 21:15:22
【问题描述】:
得到响应 200 ok 状态但从邮递员那里得到响应错误 霸气的
{
"errors": "Unable to log you in, please try again.",
"success": false
}
发帖网址:https://demo.cognitonetworks.com/cognito/gettoken
[{"key":"Content-Type","value":"application/json","description":""}]
@csrf_exempt
def token_new(request):
if request.method == 'POST':
email = request.POST.get('username')
print email
try:
UserObj = CognitoUser.objects.get(user__email=email)
username = UserObj.user.username
group = UserObj.user.groups.filter(name__in=['Admin','Manager'])
group_name = ''
if group:
group_name = group[0].name
except:
return JsonResponseUnauthorized("Unable to log you in, please try again.")
password = request.POST.get('password')
if username and password:
user = authenticate(username=username, password=password)
if user:
TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False)
if TOKEN_CHECK_ACTIVE_USER and not user.is_active:
return JsonResponseForbidden("User account is disabled.")
token = token_generator.make_token(user)
data = {
'token': token,
'user': user.pk,
'userName':UserObj.user.username,
'companyId':UserObj.company.companyid,
'companyApikey':UserObj.company.apikey,
'group_name':group_name
}
request.session['token'] = token
request.session['token'] = user.pk
return JsonResponse(data)
else:
return JsonResponseUnauthorized("Unable to log you in, please try again.")
else:
return JsonError("Must include 'username' and 'password' as POST parameters.")
else:
return JsonError("Must access via a POST request.")
【问题讨论】:
标签: javascript python html ajax django