1. 程式人生 > >微博第三方登錄使用social_django實現顯示登陸的用戶名

微博第三方登錄使用social_django實現顯示登陸的用戶名

indexof string oci res spl code 信息 顯示 ++

首先修改social_soce源碼,將用戶信息添加進cookie 技術分享圖片

技術分享圖片

將其修改為:

response = backend.strategy.redirect(url)
payload = jwt_payload_handler(user)
response.set_cookie(‘user_name‘,user.username,max_age=24*3600)
response.set_cookie(‘user_id‘,技術分享圖片user.id,max_age=24*3600)
response.set_cookie(‘token‘,jwt_encode_handler(payload),max_age=24*3600)
return response
然後在前端頁面獲取Cookie信息:
getCookie: function (cname) {
var name = cname + "=";
var ca = document.cookie.split(‘;‘);
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ‘ ‘) c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
},

微博第三方登錄使用social_django實現顯示登陸的用戶名