tafax / angular-digest-auth

AngularJS module to manage HTTP Digest Authentication
MIT License
28 stars 6 forks source link

Documentation could be better. #8

Closed thenetimp closed 9 years ago

thenetimp commented 9 years ago

After weeks of having to do something else for work I have returned to this. I am still trying to get a hang of Angular and while I thought I had it set up correctly when I add the callbacks I get errors in the console. A full example instead of segments would be helpful. I've added my code maybe you can tell me what I am doing wrong.

(function($){

  /**
   * example of http digest injection.
   */
  app = angular.module('authMain', ['dgAuth']);

  app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
  {
      dgAuthServiceProvider.setConfig({
          login: {
              method: 'POST',
              url: '/api/user/authenticate'
          },
          logout: {
              method: 'POST',
              url: '/api/user/deauthenticate'
          }
      });

      // dgAuthServiceProvider.setHeader('');
      dgAuthServiceProvider.setLimit(5);
      dgAuthServiceProvider.setStorage(localStorage);

      /**
       * You can add the callbacks to manage what happens after
       * successful of the login.
       */
      dgAuthServiceProvider.callbacks.login.push(['serviceInject', function(serviceInject)
      {
          return {
              successful: function(response)
              {
                console.write('login success');
              },
              error: function(response)
              {
                console.write('login error');
              },
              required: function(response)
              {
                console.write('login requried');
              },
              limit: function(response)
              {
                console.write('login limit');
              }
          };
      }]);

      //This is the same for the logout.

      /**
       * You can add the callbacks to manage what happens after
       * successful of the logout.
       */
      dgAuthServiceProvider.callbacks.logout.push(['serviceInject', function(serviceInject)
      {
          return {
              successful: function(response)
              {
                console.write('logout success');
              },
              error: function(response)
              {
                console.write('logout fail');
              }
          };
      }]);

  }]);

  app.run(['dgAuthService', function(dgAuthService)
  {
      /**
       * It tries to sign in. If the service doesn't find
       * the credentials stored or the user is not signed in yet,
       * the service executes the required function.
       */
      dgAuthService.start();
  }]);

  app.controller("LoginController", ['dgAuthService', function(dgAuthService){

    this.user = {};

    this.doLogin = function()
    {
      console.log(this.user);
      dgAuthService.setCredentials(this.user.emailAddress, this.user.password);
      dgAuthService.signin();
    }

  }]);

})(jQuery);
thenetimp commented 9 years ago

I get the following error

https://docs.angularjs.org/error/$injector/unpr?p0=serviceInjectProvider%20%3C-%20serviceInject

after I add the code for the callbacks.

thenetimp commented 9 years ago

nevermind I saw someone else had the same issue.....