I have been working on implementing a login feature for my app by using a custom REST API. Initially, I was able to successfully authenticate by manually entering the complete URL with the username and password:
http://www.myexample.com/ACTION/USER/PASSWORD/
However, I now need to retrieve the data from the input fields of my form. Here is the function code from my controller:
$scope.authenticate = function(selectedUs, selectedPw){
$scope.remoteData = null;
dataService.getData(function(data) {
$scope.resultAPI = data;
$scope.username = $scope.resultAPI.username;
$scope.id_user = $scope.resultAPI.id_user;
$scope.isauthenticated = $scope.resultAPI.isauthenticated;
$scope.user_role = $scope.resultAPI.user_role;
$scope.complete_name = $scope.resultAPI.complete_name;
});
}
Below is the service code handling the request:
.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.getData = function(callback) {
var myparams = {a: '', u: '', p: ''};
myparams.a = 'ZW50cmFy';
myparams.u = 'anRk';
myparams.p = '899960d8dd39b29e790845912cb35d96';
$http({
method: 'GET',
url: 'http://www.adagal.net/api_adagal/api.php',
withCredentials: false,
params: myparams,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function(data, status, header, config){
callback(data);
}).error(function(){
$scope.remoteData = null;
return "Connection Error";
});
}
});
I am currently exploring different methods to construct the URL dynamically based on user input. How can I achieve this in an effective manner?