@melkotoury wrote:
hey everyone
I need to make an ionic app that login through authentication http web service and I finished it and it's working , but I have t pass to the url the following (username , password , auth)
auth is either student or staff
so i need to use the user object in other places in the app (other controllers ) but i don't know how to get the parameters again , since i can't get it from the service because i have to pass username , password and auth to get the user object
what to dothis is my userService Code
This message was deletedmgisApp.factory('userService', function($http) { var users = {}; return { getUser: function(username,password,auth){ var servicebase = "http://www.al-almanya.com/alalmanya-api/login-route-api?"; return $http.get(servicebase + "username="+username+"&password=" + password + "&auth="+auth).then(function(response){ //http://www.al-almanya.com/alalmanya-api/login-route-api?username=301&password=123456&auth=student users = response; return users; }); }, getSingleUser: function(uid){ return users[uid]; } } });
and this is the controller that works well with it which is the login controller
mgisApp.controller('LoginCtrl', function($scope,$state, $stateParams, userService, $ionicPopup) { // An alert dialog $scope.showAlert = function() { var alertPopup = $ionicPopup.alert({ title: 'Error', template: 'invalid username or password' }); alertPopup.then(function(res) { console.log('you have accepted the alert'); }); } $scope.onSignInClicked = function(username,password,auth) { var inputUsername=username, inputPassword=password, inputAuth=auth; console.log("Input Fields:"+ inputUsername + "- "+inputPassword+ "- "+inputAuth); // var user = userService.getUser(inputUsername,inputPassword,inputAuth); userService.getUser(inputUsername,inputPassword,inputAuth).then(function(user){ //user var serviceUsername=user.data.username, servicePassword=user.data.password, serviceAuth=user.data.auth; console.log("Service Fields:"+ serviceUsername + "- "+servicePassword+ "- "+serviceAuth); console.log("Service ID: "+ user.id); console.log(user); if (inputUsername == serviceUsername && inputPassword == servicePassword && inputAuth == serviceAuth) { localStorage.setItem('loggedIn', true); $state.go('tab.dash'); } else { $scope.showAlert(); } });
I need to get a list of messages that this particular user have
mgisApp.factory('Chats', function($http) { var chats = {}; return { getChats: function(auth,id,api_token){ var servicebase = "http://al-almanya.com/alalmanya-api/notifications-route-api?"; return $http.get(servicebase + "auth="+auth+"&id=" + id + "&api_token="+api_token).then(function(response){ // http://al-almanya.com/alalmanya-api/notifications-route-api?auth=student&id=301&api_token=sEy4nqOUxOI6FGD7ekbUElDvR0XN6AmekL2CcGxl chats = response; return chats; }); } } });
` and the controller I am trying to work on , trying to get the auth , id , api_token is right here
mgisApp.controller('DashCtrl', function($scope ,userService) { userService.getUser(inputUsername,inputPassword,inputAuth).then(function(user){ console.log(user.fullname); //cant access the user because i can't have the parameters, username , password , auth } });
Posts: 2
Participants: 2