I'm trying to login an user using Angular instead of regular login (which works atm). Here's my authenticate method:
def authenticate
authenticate_or_request_with_http_token do |token, options|
User.find_by(:auth_token => token)
end
end
Here's my controller:
if user && user.authenticate(params[:session][:password])
sign_in user
user.update_attribute(:last_login, DateTime.now)
if user.admin?
redirect_to admin_path
else
redirect_to user
end
else
redirect_to signin_path, notice: "Invalid email/password combination"
end
This works fine with a Rails based login (no Angular or Ajax).
Now, when I try to implement Angular login (basic for the moment):
$http.post('/api/signin', $scope.user).success(function (data) {
console.log(data);
});
I get the error Invalid email/password combination. I'm assuming is to with CSRF token, which is not passed via Angular $http but I'm using protect_from_forgery with: :null_session in the sessions controller.
Other point that is I haven't added csrf_meta_tags in my Angular html. Would I need to? And how would it render if the html is not served by rails?
What am I missing here?