0
我試圖通過使用JSON & AJAX使用鋼軌API認證以下教程:http://jessehowarth.com/deviseAjax設備認證不起作用?
它似乎工作,但無論輸入怎樣的登錄的憑據(現有的和不存在的),它失敗每次我點擊提交。
我讓使用Node.js的
var post_data = querystring.stringify({
'email' : '[email protected]',
'password': 'foo',
'remember_me': 1
});
var options = {
host: 'localhost',
path: '/users/sign_in.json',
port: '3000',
method: 'POST'
};
callback = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function() {
console.log(str);
});
}
var req = http.request(options, callback);
req.write(post_data);
req.end();
請求
我色器件,會話控制器看起來是這樣的:
class SessionsController < Devise::SessionsController
def create
respond_to do |format|
format.html{ super }
format.json do
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
return sign_in_and_redirect(resource_name, resource)
end
end
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
respond_to do |format|
format.json {render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}}
format.html {redirect_to root_url}
end
end
def failure
respond_to do |format|
format.json { render:json => {:success => false, :errors => ["Login failed."]} }
end
end
end
輸出我得到:
{"success":false,"errors":["Login failed."]}
任何對此有何建議?
謝謝!