im working on an ionic project to create android and ios app. im new in ionic and need help to understand how to make a login trough restful services hosted on my server.
the restful uses this auth for every POST
or PUT
request:
username: admin
pass: 123123
so i am testing a POST
request. i have no idea how to authenticate.
the serverside is set up and running. and the api had been tested and no bug. (tested using cocoa restclient)
ok. this is my app.js
angular.module('tapp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('testapp', {
url: "/tapp",
abstract: true,
templateUrl: "template/menu.html",
controller: 'MenuCtrl'
})
.state('tapp.home', {
url: '/home',
views: {
'tappMenu': {
templateUrl: 'template/home.html',
controller: 'HomeCtrl'
}
}
})
.state('tapp.dash', {
url: '/dash',
views: {
'tappMenu': {
templateUrl: 'template/dash.html',
controller: 'DashCtrl'
}
}
})
$urlRouterProvider.otherwise('/tapp/home');
here is my controller:
.controller('HomeCtrl', function($scope, $http){
$scope.formData = [] // just testing post data
$scope.submit = function(){
var data = $scope.formData.push($scope.inputData);
$http.post('http://localhost/tapp-server/posted', data);
};
}
my php function (using codeigniter rest server)
public function posted_post()
{
$this->response(json_encode($_POST), 200);
}
the issue here is, i dont know how to apply the basic restful authentication whenever the app will post the data to the php because whenever it post the data, i get error as "not authorized".
for other data such as getting the data using GET
, i receive the data and processed flawlessly. only on this POST
part i am in confusion.