当我发布到烧瓶端点时:
@app.route('/api/v1/logout', methods=['POST','GET'])
def logout():
logout_user()
return jsonify(status=200, message='User has been successfully logged out.')
下次尝试登录时出现错误
InvalidRequestError: Object '<User at 0x7f09b4831c90>' is already attached to session '1' (this is '4')
我想知道如何注销并安全地使用 ajax。
编辑- angularjs 登录控制器:
LoginController: function ($scope, $http, authService, $location) {
$scope.submit = function() {
console.log('in logincontroller')
$http.defaults.headers.post['X-CSRFToken'] = csrf_token;
$http.defaults.headers.common['Content-Type'] = 'application/json'
//debugger;
$http.post(
'/login',
JSON.stringify({ email: $scope.email, password: $scope.password })
).success(
function(data) {
if (data.meta){
var status_code = data.meta.code;
}
else{
var status_code = data.status;
}
if (status_code == 200){
$.cookie('email', $scope.email, { expires: 7 });
$.cookie('auth_token', data.authentication_token, { expires: 7 });
$http.defaults.headers.common['Authentication-Token'] = data.authentication_token;
authService.loginConfirmed();
$location.path("/dashboard");
}
else{
//form stuff
}
}
).error(
function(data) {
alert('LoginController submit error');
$scope.errorMsg = data.reason;
//debugger;
}
);
};
}