text: (function () {
      'use strict';
  
      angular
          .module('app')
          .factory('AuthenticationService', Service);
  
      function Service($http, $localStorage) {
          var service = {};
  
          service.Login = Login;
          service.Logout = Logout;
          service.Register = Register;
  
          return service;
  
          function Register(username, password, callback) {
              $http.post('/register', { name: username, password: password })
                  .success(function (response) {
                      // register successful if response returns success boolean
                      if (response.success) {
                          // login on successful attempt
                          Login(username, password, callback);
                      } else {
                          // execute callback with false to indicate failed login
                          callback(false);
                      }
                  });
          }
  
          function Login(username, password, callback) {
              $http.post('/authenticate', { name: username, password: password })
                  .success(function (response) {
                      // login successful if there's a token in the response
                      if (response.token) {
                          // store username and token in local storage to keep user logged in between page refreshes
                          $localStorage.currentUser = { name: username, token: response.token };
                          
                          // add jwt token to auth header for all requests made by the $http service
                          $http.defaults.headers.common.Authorization = $localStorage.currentUser.token;
  
                          // execute callback with true to indicate successful login
                          callback(true);
                      } else {
                          // execute callback with false to indicate failed login
                          callback(false);
                      }
                  });
          }
  
          function Logout() {
              // remove user from local storage and clear http auth header
              delete $localStorage.currentUser;
              $http.defaults.headers.common.Authorization = '';
          }
      }
  })();
  