daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top