login with ajax,Django, Secure Login with Ajax from Http page

在尝试从HTTP页面通过AJAX登录到HTTPS页面时遇到问题,响应未返回,可能是因为视图函数返回的HttpResponse对象无法正确传递到HTTPS页面。尝试过使TweetButton与HTTPS兼容但遇到困难。代码中展示了登录异步请求的处理,包括用户验证和登录操作,以及返回JSON数据的响应处理。
摘要由CSDN通过智能技术生成

I log in users from a Http page via ajax. I'm making the request to a secure (https) page. My issue is that I'm not receiving a response because (I assume) my view function is returning an HttpResponse object to the https page (my user is still at http).

Here is the code

@secure_required

def login_async(request):

if request.method=='POST':

email=request.POST.get('email', '')

try:

user=User.objects.get(email__exact=email)

username=user.username

except User.DoesNotExist:

username=''

password=request.POST.get('password', '')

user=auth.authenticate(username=username, password=password)

if user is not None:

auth.login(request,user)

user_status=1

user_fname=user.first_name

user_data=[{'user_status':user_status, 'user_fname':user_fname,'user_favorite':user_favorite,'flag_record':flag_record, 'message_sent':message_sent,'is_post_owner':is_post_owner}]

json_data=json.dumps(user_data)

response=HttpResponse()

response['Content-Type']="text/javascript"

response.write(json_data)

return response

else:

user_data=[{'user_status':user_status}]

json_data=json.dumps(user_data)

response=HttpResponse()

response['Content-Type']="text/javascript"

response.write(json_data)

return response

else:

user_data=[{'user_status':"0"}]

json_data=json.dumps(user_data)

response=HttpResponse()

response['Content-Type']="text/javascript"

response.write(json_data)

return response

Why not just make the whole page https, you ask? Good question. I was having some issues with making the Tweet Button https compatible.

Thanks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值