首先修改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 "";
},
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 "";
},