Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .factory('AuthenticationService',
- ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
- function (Base64, $http, $cookieStore, $rootScope, $timeout) {
- var service = {};
- service.Login = function (UserName, Password, callback) {
- /* Dummy authentication for testing, uses $timeout to simulate api call
- ----------------------------------------------
- $timeout(function () {
- var response = { success: UserName === 'test' && Password === 'test' };
- if (!response.success) {
- response.message = 'UserName or Password is incorrect';
- }
- callback(response);
- }, 1000);
- */
- /* Use this for real authentication
- ----------------------------------------------*/
- $http({
- method: 'POST',
- url: 'http://216.0.1.209/AuthenticateUser',
- data: {
- UserName: 'UserName',
- Password: 'Password'
- },
- headers: {
- 'content-type: multipart/form-data; boundary=---011000010111000001101001'
- }
- }).then(function(response) {
- console.log(response)
- });
- };
- service.SetCredentials = function (UserName, Password) {
- var authdata = Base64.encode(UserName + ':' + Password);
- $rootScope.globals = {
- currentUser: {
- UserName: UserName,
- authdata: authdata
- }
- };
- $http.defaults.headers.common['Authorization'] = '0 ' + authdata; // jshint ignore:line
- $cookieStore.put('globals', $rootScope.globals);
- };
- service.ClearCredentials = function () {
- $rootScope.globals = {};
- $cookieStore.remove('globals');
- $http.defaults.headers.common.Authorization = '0 ';
- };
- return service;
- }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement