Guest User

Untitled

a guest
Oct 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. app.factory('Authentication', function($http,session){
  2. var service = {};
  3.  
  4. service.login = function(username,password) {
  5. return $http
  6. .post('http://localhost:3000/loginfo',{
  7. username : username,
  8. password : password
  9. })
  10. .then(
  11. function successCallback(response){
  12. session.create(response.data.id,response.data.username);
  13. return response.data;
  14. });
  15. };
  16.  
  17. service.isAuthenticated = function() {
  18. return !!session.username;
  19. };
  20. return service;
  21. });
  22.  
  23. /*-----Main Controller-----*/
  24.  
  25. app.controller('credientials',['$scope','$route','$http','Authentication',function($scope,$route,$http,Authentication) {
  26.  
  27. $scope.isAuthenticated = false;
  28.  
  29. $scope.userCred = {
  30. username: '',
  31. password: ''
  32. }
  33.  
  34. /*-----Form Submition-----*/
  35.  
  36. $scope.log = function(userCred){
  37.  
  38. Authentication.login(userCred.username,userCred.password)
  39. .then(function(result){
  40. console.log(result);
  41. })
  42. .catch(function(err){
  43. console.error(err);
  44. });
Add Comment
Please, Sign In to add comment