Advertisement
Ludwiq

angular

Jul 21st, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.factory("getToken", ["$http", function () {
  2.     return function (username, password) {
  3.         return $http.post('token', {
  4.             username: username,
  5.             password: password,
  6.             grant_type: "password"
  7.         })
  8.             .success(function (data) {
  9.                 return data.access_token;
  10.             })
  11.             .error(function (err) {
  12.                 return err;
  13.             });
  14.     }
  15. }]);
  16.  
  17. app.controller('loginForm', ['$scope', 'getToken', function ($scope, getToken) {
  18.         $scope.sendToServer = function (user) {
  19.             getToken(user.email, user.password)
  20.                 .success(function (data) {
  21.                     $scope.token = data;
  22.                 }).error(function (err) {
  23.                     $scope.tokenError = err;
  24.                 });
  25.         };
  26.     }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement