Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('signIn', ['ngCookies'])
  2.     .controller('signInCtrl', ['$scope' ,'$rootScope', '$http', '$cookies', '$cookieStore', '$location', '$routeParams', function ($scope, $rootScope, $http, $cookies, $cookieStore, $location, $routeParams) {
  3.         $scope.message = $routeParams.message;
  4.         $scope.signIn = function () {
  5.             $scope.showMessage = false;
  6.             var params = "grant_type=password&username=" + $scope.username + "&password=" + $scope.password;
  7.             $http({
  8.                 url: '/Token',
  9.                 method: "POST",
  10.                 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  11.                 data: params
  12.             })
  13.             .success(function (data, status, headers, config) {
  14.                 $http.defaults.headers.common.Authorization = "Bearer " + data.access_token;
  15.                 $http.defaults.headers.common.RefreshToken = data.refresh_token;
  16.                
  17.                 $cookieStore.put('_Token', data.access_token);
  18.                 window.location = '#/todomanager';
  19.             })
  20.             .error(function (data, status, headers, config) {
  21.                 $scope.message = data.error_description.replace(/["']{1}/gi, "");
  22.                 $scope.showMessage = true;
  23.             });
  24.         }
  25.     }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement