I have a web app and I'm accessing an APP in this way:
.controller('LoginCtrl', function($scope, $ionicPopup, $state, $http) {
$scope.data = {};
$scope.login = function() {
$http.post('http://localhost:3000/login', $scope.data.session_email, $scope.data.session_password).success(function(data) {
$state.go('improvements');
}).error(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'User/Password is Wrong'
});
});
}
});
but I'm getting the following error:
NoMethodError (undefined method '[]' for nil:NilClass):
app/controllers/sessions_controller.rb:9:in 'create'
My controller:
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password]) && user.permission == true
params[:session][:remember_me] == '1' ? remember(user) : forget(user)
remember user
redirect_to user
elsif user && user.permission == false
flash.now[:notpermission] = "You do not have a permission"
render "new"
else
flash.now[:error] = "Invalid password or email"
render "new"
end
end
I know I need the token to access but I do not know how to do this ... can anyone give me a light?