[
  {
    "path": "Gruntfile.js",
    "content": "/*global module:false*/\nmodule.exports = function(grunt) {\n\n    // Project configuration.\n    grunt.initConfig({\n        pkg: grunt.file.readJSON('package.json'),\n        meta: {\n            version: '<%= pkg.version %>',\n            banner:\n                '// AngularDevise\\n' +\n                '// -------------------\\n' +\n                '// v<%= pkg.version %>\\n' +\n                '//\\n' +\n                '// Copyright (c)<%= grunt.template.today(\"yyyy\") %> Justin Ridgewell\\n' +\n                '// Distributed under MIT license\\n' +\n                '//\\n' +\n                '// https://github.com/cloudspace/angular_devise\\n' +\n                '\\n'\n        },\n\n        preprocess: {\n            build: {\n                files: {\n                    'lib/devise.js' : 'src/build/devise.js'\n                }\n            }\n        },\n\n        uglify : {\n            options: {\n                banner: \"<%= meta.banner %>\"\n            },\n            core : {\n                src : 'lib/devise.js',\n                dest : 'lib/devise-min.js',\n            }\n        },\n\n        jshint: {\n            options: {\n                jshintrc : '.jshintrc'\n            },\n            devise : [ 'src/*.js' ],\n            test : [ 'test/*.js', 'test/specs/*.js' ],\n        },\n\n        plato: {\n            devise : {\n                src : 'src/*.js',\n                dest : 'reports',\n                options : {\n                    jshint : false\n                }\n            }\n        },\n\n        ngAnnotate: {\n            options: {\n                singleQuotes: true\n            },\n            dist: {\n                files: {\n                    'lib/devise.js': ['lib/devise.js']\n                }\n            }\n        },\n\n        karma: {\n            options: {\n                configFile: 'karma.conf.js',\n                browsers: ['PhantomJS']\n            },\n            unit: {\n            },\n            continuous: {\n                singleRun: false\n            }\n        }\n    });\n\n    require('load-grunt-tasks')(grunt);\n    require('time-grunt')(grunt);\n\n    // Default task.\n    grunt.registerTask('lint-test', 'jshint:test');\n    grunt.registerTask('test', function(type) {\n        type = type || 'unit';\n        grunt.task.run('karma:' + type);\n    });\n    grunt.registerTask('travis', ['jshint:devise', 'karma']);\n    grunt.registerTask('build', ['default', 'preprocess', 'ngAnnotate', 'uglify']);\n    grunt.registerTask('default', ['jshint:devise', 'test']);\n\n};\n"
  },
  {
    "path": "LICENSE.md",
    "content": "Copyright (c) 2013 Justin Ridgewell\n===================================\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "AngularDevise [![Build Status](https://travis-ci.org/cloudspace/angular_devise.png)](http://travis-ci.org/cloudspace/angular_devise)\n=============\n\nA small AngularJS Service to interact with Devise Authentication.\n\n\nRequirements\n------------\n\nThis service requires Devise to respond to JSON. To do that, simply add\n\n```ruby\n# config/application.rb\nmodule RailsApp\n  class Application < Rails::Application\n    # ...\n\n    config.to_prepare do\n      DeviseController.respond_to :html, :json\n    end\n  end\nend\n```\n\nAdditionally, if you have [CSRF Forgery\nProtection](http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html)\nenabled for your controller actions, you will also need to include the\n`X-CSRF-TOKEN` header with the token provided by rails. The easiest way\nto include this is to follow this post:\n\n[angular_rails_csrf](http://stackoverflow.com/questions/14734243/rails-csrf-protection-angular-js-protect-from-forgery-makes-me-to-log-out-on).\n\nDownloading\n-----------\n\nAngularDevise is registered as `angular-devise` in\n[bower](http://sindresorhus.com/bower-components/#!/search/angular-devise).\n\n```bash\nbower install --save angular-devise\n```\n\nYou can then use the main file at `angular-devise/lib/devise-min.js`.\n\nRails Assets\n------------\n\nTo get AngularDevise via [Rails Assets](https://rails-assets.org/) add to your Gemfile:\n\n```ruby\nsource \"https://rails-assets.org\" do\n  gem \"rails-assets-angular-devise\"\nend\n```\n\nThen `bundle`. Finally, to require the JS:\n\n```js\n//= require angular-devise\n```\n\nUsage\n-----\n\nJust register `Devise` as a dependency for your module. Then, the `Auth`\nservice will be available for use.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        // Configure Auth service with AuthProvider\n    }).\n    controller('myCtrl', function(Auth) {\n        // Use your configured Auth service.\n    });\n```\n\n### Auth.currentUser()\n\n`Auth.currentUser()` returns a promise that will be resolved into the\ncurrentUser. There are three possible outcomes:\n\n 1. Auth has authenticated a user, and will resolve with that user.\n 2. Auth has not authenticated a user but the server has a previously\n    authenticated session, Auth will attempt to retrieve that session\n    and resolve with its user. Then, a `devise:new-session` event will\n    be broadcast with the current user as the argument.\n 3. Neither Auth nor the server has an authenticated session, and a\n    rejected promise will be returned. (see [Interceptor](#interceptor)\n    for for custom handling.)\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        Auth.currentUser().then(function(user) {\n            // User was logged in, or Devise returned\n            // previously authenticated session.\n            console.log(user); // => {id: 1, ect: '...'}\n        }, function(error) {\n            // unauthenticated error\n        });\n    });\n```\n\n#### Auth._currentUser\n\n`Auth._currentUser` will be either `null` or the currentUser's object\nrepresentation. It is not recommended to directly access\n`Auth._currentUser`, but instead use\n[Auth.currentUser()](#authcurrentuser).\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        console.log(Auth._currentUser); // => null\n\n        // Log in user...\n\n        console.log(Auth._currentUser); // => {id: 1, ect: '...'}\n    });\n```\n\n\n### Auth.isAuthenticated()\n\n`Auth.isAuthenticated()` is a helper method to determine if a\ncurrentUser is logged in with Auth.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        console.log(Auth.isAuthenticated()); // => false\n\n        // Log in user...\n\n        console.log(Auth.isAuthenticated()); // => true\n    });\n```\n\n### Auth.login(creds, config)\n\nUse `Auth.login()` to authenticate with the server. Keep in mind,\ncredentials are sent in plaintext; use a SSL connection to secure them.\n`creds` is an object which should contain any credentials needed to\nauthenticate with the server. `Auth.login()` will return a promise that\nwill resolve to the logged-in user. See\n[Auth.parse(response)](#authparseresponse) to customize how the response\nis parsed into a user.\n\nUpon a successful login, two events will be broadcast, `devise:login` and\n`devise:new-session`, both with the currentUser as the argument. New-Session will only\nbe broadcast if the user was logged in by `Auth.login({...})`. If the server\nhas a previously authenticated session, only the login event will be broadcast.\n\nPass any additional config options you need to provide to `$http` with\n`config`.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        var credentials = {\n            email: 'user@domain.com',\n            password: 'password1'\n        };\n        var config = {\n            headers: {\n                'X-HTTP-Method-Override': 'POST'\n            }\n        };\n\n        Auth.login(credentials, config).then(function(user) {\n            console.log(user); // => {id: 1, ect: '...'}\n        }, function(error) {\n            // Authentication failed...\n        });\n\n        $scope.$on('devise:login', function(event, currentUser) {\n            // after a login, a hard refresh, a new tab\n        });\n\n        $scope.$on('devise:new-session', function(event, currentUser) {\n            // user logged in by Auth.login({...})\n        });\n    });\n```\n\nBy default, `login` will POST to '/users/sign_in.json' using the\nresource name `user`. The path, HTTP method, and resource name used to\nlogin are configurable using:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        AuthProvider.loginPath('path/on/server.json');\n        AuthProvider.loginMethod('GET');\n        AuthProvider.resourceName('customer');\n    });\n```\n\n### Auth.logout()\n\nUse `Auth.logout()` to de-authenticate from the server. `Auth.logout()`\nreturns a promise that will be resolved to the old currentUser. Then a\n`devise:logout` event will be broadcast with the old currentUser as the argument.\n\nPass any additional config options you need to provide to `$http` with\n`config`.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        var config = {\n            headers: {\n                'X-HTTP-Method-Override': 'DELETE'\n            }\n        };\n        // Log in user...\n        // ...\n        Auth.logout(config).then(function(oldUser) {\n            // alert(oldUser.name + \"you're signed out now.\");\n        }, function(error) {\n            // An error occurred logging out.\n        });\n\n        $scope.$on('devise:logout', function(event, oldCurrentUser) {\n            // ...\n        });\n    });\n```\n\nBy default, `logout` will DELETE to '/users/sign_out.json'. The path and\nHTTP method used to logout are configurable using:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        AuthProvider.logoutPath('path/on/server.json');\n        AuthProvider.logoutMethod('GET');\n    });\n```\n\n### Auth.parse(response)\n\nThis is the method used to parse the `$http` response into the appropriate\nuser object. By default, it simply returns `response.data`. This can be\ncustomized either by specifying a parse function during configuration:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        // Customize user parsing\n        // NOTE: **MUST** return a truth-y expression\n        AuthProvider.parse(function(response) {\n            return response.data.user;\n        });\n    });\n```\n\nor by directly overwriting it, perhaps when writing a custom version of\nthe Auth service which depends on another service:\n\n```javascript\nangular.module('myModule', ['Devise']).\n  factory('User', function() {\n    // Custom user factory\n  }).\n  factory('CustomAuth', function(Auth, User) {\n    Auth['parse'] = function(response) {\n      return new User(response.data);\n    };\n    return Auth;\n  });\n```\n\n### Auth.register(creds)\n\nUse `Auth.register()` to register and authenticate with the server. Keep\nin mind, credentials are sent in plaintext; use a SSL connection to\nsecure them. `creds` is an object that should contain any credentials\nneeded to register with the server. `Auth.register()` will return a\npromise that will resolve to the registered user. See\n[Auth.parse(response)](#authparseresponse) to customize how the response\nis parsed into a user. Then a `devise:new-registration` event will be\nbroadcast with the user object as the argument.\n\nPass any additional config options you need to provide to `$http` with\n`config`.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        var credentials = {\n            email: 'user@domain.com',\n            password: 'password1',\n            password_confirmation: 'password1'\n        };\n        var config = {\n            headers: {\n                'X-HTTP-Method-Override': 'POST'\n            }\n        };\n\n        Auth.register(credentials, config).then(function(registeredUser) {\n            console.log(registeredUser); // => {id: 1, ect: '...'}\n        }, function(error) {\n            // Registration failed...\n        });\n\n        $scope.$on('devise:new-registration', function(event, user) {\n            // ...\n        });\n    });\n```\n\nBy default, `register` will POST to '/users.json' using the resource\nname `user`. The path, HTTP method, and resource name used to register\nare configurable using:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        AuthProvider.registerPath('path/on/server.json');\n        AuthProvider.registerMethod('GET');\n        AuthProvider.resourceName('customer');\n    });\n```\n\n\n### Auth.sendResetPasswordInstructions(creds)\n\nUse `Auth.sendResetPasswordInstructions()` to send reset password mail to user. Keep\nin mind, credentials are sent in plaintext; use a SSL connection to\nsecure them. `creds` is an object that should contain the email associated with the user.\n`Auth.sendResetPasswordInstructions()` will return a promise with no params.\nThen a `devise:send-reset-password-instructions-successfully` event will be broadcast.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        var parameters = {\n            email: 'user@domain.com'\n        };\n\n        Auth.sendResetPasswordInstructions(parameters).then(function() {\n            // Sended email if user found otherwise email not sended...\n        });\n\n        $scope.$on('devise:send-reset-password-instructions-successfully', function(event) {\n            // ...\n        });\n    });\n```\n\nBy default, `sendResetPasswordInstructions` will POST to '/users/password.json'. The path and HTTP\nmethod used to send the reset password instructions are configurable using:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        AuthProvider.sendResetPasswordInstructionsPath('path/on/server.json');\n        AuthProvider.sendResetPasswordInstructionsMethod('POST');\n    });\n```\n\n### Auth.resetPassword(creds)\n\nUse `Auth.resetPassword()` to reset user password. Keep\nin mind, credentials are sent in plaintext; use a SSL connection to\nsecure them. `creds` is an object that should contain password, password_confirmation and reset_password_token.\n`Auth.resetPassword()` will return a\npromise that will resolve to the new user data. See\n[Auth.parse(response)](#authparseresponse) to customize how the response\nis parsed into a user. Then a `devise:reset-password-successfully` event will be broadcast.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    controller('myCtrl', function(Auth) {\n        var parameters = {\n            password: 'new_password',\n            password_confirmation: 'new_password',\n            reset_password_token: 'reset_token',\n        };\n\n        Auth.resetPassword(parameters).then(function(new_data) {\n            console.log(new_data); // => {id: 1, ect: '...'}\n        }, function(error) {\n            // Reset password failed...\n        });\n\n        $scope.$on('devise:reset-password-successfully', function(event) {\n            // ...\n        });\n    });\n```\n\nBy default, `resetPassword` will PUT to '/users/password.json'. The path and HTTP\nmethod used to reset password are configurable using:\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider) {\n        AuthProvider.resetPasswordPath('path/on/server.json');\n        AuthProvider.resetPasswordMethod('PUT');\n    });\n```\n\n\nInterceptor\n-----------\n\nAngularDevise comes with a [$http\nInterceptor](http://docs.angularjs.org/api/ng.$http#description_interceptors)\nthat may be enabled using the `interceptAuth` config. Its purpose is to\nlisten for `401 Unauthorized` responses and give you the ability to\nseamlessly recover. When it catches a 401, it will:\n 1. create a deferred\n 2. broadcast a `devise:unauthorized` event passing:\n    - the ajax response\n    - the deferred\n 3. return the deferred's promise\n\nSince the deferred is passed to the `devise:unauthorized` event, you are\nfree to resolve it (and the request) inside of the event listener. For\ninstance:\n\n```javascript\nangular.module('myModule', []).\n    controller('myCtrl', function($scope, Auth, $http) {\n        // Guest user\n\n        // Catch unauthorized requests and recover.\n        $scope.$on('devise:unauthorized', function(event, xhr, deferred) {\n            // Disable interceptor on _this_ login request,\n            // so that it too isn't caught by the interceptor\n            // on a failed login.\n            var config = {\n                interceptAuth: false\n            };\n\n            // Ask user for login credentials\n            Auth.login(credentials, config).then(function() {\n                // Successfully logged in.\n                // Redo the original request.\n                return $http(xhr.config);\n            }).then(function(response) {\n                // Successfully recovered from unauthorized error.\n                // Resolve the original request's promise.\n                deferred.resolve(response);\n            }, function(error) {\n                // There was an error logging in.\n                // Reject the original request's promise.\n                deferred.reject(error);\n            });\n        });\n\n        // Request requires authorization\n        // Will cause a `401 Unauthorized` response,\n        // that will be recovered by our listener above.\n        $http.delete('/users/1', {\n            interceptAuth: true\n        }).then(function(response) {\n            // Deleted user 1\n        }, function(error) {\n            // Something went wrong.\n        });\n    });\n```\n\nThe Interceptor can be enabled globally or on a per-request basis using the\n`interceptAuth` setting on the AuthIntercept provider.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthInterceptProvider) {\n        // Intercept 401 Unauthorized everywhere\n        AuthInterceptProvider.interceptAuth(true);\n    }).\n    controller('myCtrl', function($http) {\n        // Disable per-request\n        $http({\n            url: '/',\n            interceptAuth: false,\n            // ...\n        });\n    });\n```\n\n\nAuthProvider\n------------\n\nBy default, AngularDevise uses the following HTTP methods/paths:\n\n| Method   | HTTP Method | HTTP Path            |\n| -------- | ----------- | -------------------- |\n| login    | POST        | /users/sign_in.json  |\n| logout   | DELETE      | /users/sign_out.json |\n| register | POST        | /users.json          |\n| sendResetPasswordInstructions | POST | /users/password.json |\n| resetPassword | POST   | /users/password.json |\n\nAll credentials will be under the `users` namespace, and the following\nparse function will be used to parse the response:\n\n```javascript\nfunction(response) {\n    return response.data;\n};\n```\n\nAll of these can be configured using a `.config` block in your module.\n\n```javascript\nangular.module('myModule', ['Devise']).\n    config(function(AuthProvider, AuthInterceptProvider) {\n        // Customize login\n        AuthProvider.loginMethod('GET');\n        AuthProvider.loginPath('/admins/login.json');\n\n        // Customize logout\n        AuthProvider.logoutMethod('POST');\n        AuthProvider.logoutPath('/user/logout.json');\n\n        // Customize register\n        AuthProvider.registerMethod('PATCH');\n        AuthProvider.registerPath('/user/sign_up.json');\n\n        // Customize the resource name data use namespaced under\n        // Pass false to disable the namespace altogether.\n        AuthProvider.resourceName('customer');\n\n        // Also you can change host URL for backend calls\n        // (for example if it's on another server than your angular app)\n        AuthProvider.baseUrl('http://localhost:3000');\n\n        // Customize user parsing\n        // NOTE: **MUST** return a truth-y expression\n        AuthProvider.parse(function(response) {\n            return response.data.user;\n        });\n\n        // Intercept 401 Unauthorized everywhere\n        // Enables `devise:unauthorized` interceptor\n        AuthInterceptProvider.interceptAuth(true);\n    });\n```\n\n\nCredits\n-------\n\n[![Cloudspace](http://cloudspace.com/assets/images/logo.png)](http://cloudspace.com/)\n\nAngularDevise is maintained by [Cloudspace](http://cloudspace.com/), and\nis distributed under the [MIT License](/LICENSE.md).\n"
  },
  {
    "path": "bower.json",
    "content": "{\n  \"name\": \"AngularDevise\",\n  \"main\": \"lib/devise.js\",\n  \"ignore\": [\n    \"**/.*\",\n    \"node_modules\",\n    \"components\",\n    \"bower_components\",\n    \"spec\",\n    \"reports\"\n  ],\n  \"author\": {\n      \"name\": \"Justin Ridgewell\"\n  },\n  \"dependencies\": {\n      \"angular\": \"^1.2.0\"\n  },\n  \"devDependencies\": {\n      \"angular-mocks\": \"^1.2.0\",\n      \"angular-scenario\": \"^1.2.0\"\n  }\n}\n"
  },
  {
    "path": "karma.conf.js",
    "content": "module.exports = function(config) {\n    config.set({\n        // base path, that will be used to resolve files and exclude\n        basePath: '',\n\n        // testing framework to use (jasmine/mocha/qunit/...)\n        frameworks: ['jasmine'],\n\n        plugins : ['karma-jasmine', 'karma-phantomjs-launcher'],\n\n        // list of files / patterns to load in the browser\n        files: [\n            'test/support/angular/angular.js',\n            'test/support/angular-mocks/angular-mocks.js',\n            'test/devise.js',\n            'src/*.js',\n            'test/mock/**/*.js',\n            'test/spec/**/*.js'\n        ],\n\n        // list of files / patterns to exclude\n        exclude: [],\n\n        // web server port\n        port: 8080,\n\n        // level of logging\n        // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG\n        logLevel: config.LOG_INFO,\n\n\n        // enable / disable watching file and executing tests whenever any file changes\n        autoWatch: true,\n\n\n        browsers: ['Chrome'],\n\n        singleRun: true\n    });\n};\n"
  },
  {
    "path": "lib/devise-min.js",
    "content": "// AngularDevise\n// -------------------\n// v1.2.1\n//\n// Copyright (c)2016 Justin Ridgewell\n// Distributed under MIT license\n//\n// https://github.com/cloudspace/angular_devise\n\n!function(a){\"use strict\";var b=a.module(\"Devise\",[]);b.provider(\"AuthIntercept\",function(){var a=!1;this.interceptAuth=function(b){return a=!!b||void 0===b,this},this.$get=[\"$rootScope\",\"$q\",function(b,c){return{responseError:function(d){var e=d.config.interceptAuth;if(e=!!e||a&&void 0===e,e&&401===d.status){var f=c.defer();return b.$broadcast(\"devise:unauthorized\",d,f),f.reject(d),f.promise}return c.reject(d)}}}]}).config([\"$httpProvider\",function(a){a.interceptors.push(\"AuthIntercept\")}]),b.provider(\"Auth\",function(){function b(b,c,d){var h={method:f[b].toLowerCase(),url:e[b]};return c&&(g?(h.data={},h.data[g]=c):h.data=c),a.extend(h,d),h}function c(b,c){a.forEach(b,function(a,d){this[d+c]=function(a){return void 0===a?b[d]:(b[d]=a,this)}},this)}function d(a){return function(){return a}}var e={login:\"/users/sign_in.json\",logout:\"/users/sign_out.json\",register:\"/users.json\",sendResetPasswordInstructions:\"/users/password.json\",resetPassword:\"/users/password.json\"},f={login:\"POST\",logout:\"DELETE\",register:\"POST\",sendResetPasswordInstructions:\"POST\",resetPassword:\"PUT\"},g=\"user\",h=function(a){return a.data};c.call(this,f,\"Method\"),c.call(this,e,\"Path\"),this.resourceName=function(a){return void 0===a?g:(g=a,this)},this.parse=function(a){return\"function\"!=typeof a?h:(h=a,this)},this.$get=[\"$q\",\"$http\",\"$rootScope\",function(a,c,e){function f(a){return j._currentUser=a,a}function g(){f(null),j._promise=null}function i(a){return function(b){return e.$broadcast(\"devise:\"+a,b),b}}var j={_currentUser:null,parse:h,_promise:null,reset:function(){g(),j.currentUser()},login:function(a,d){var e=arguments.length>0,g=j.isAuthenticated();return a=a||{},c(b(\"login\",a,d)).then(j.parse).then(f).then(function(a){return e&&!g?i(\"new-session\")(a):a}).then(i(\"login\"))},logout:function(a){var e=d(j._currentUser);return c(b(\"logout\",void 0,a)).then(g).then(e).then(i(\"logout\"))},register:function(a,d){return a=a||{},c(b(\"register\",a,d)).then(j.parse).then(f).then(i(\"new-registration\"))},sendResetPasswordInstructions:function(a){return a=a||{},c(b(\"sendResetPasswordInstructions\",a)).then(j.parse).then(i(\"send-reset-password-instructions-successfully\"))},resetPassword:function(a){return a=a||{},c(b(\"resetPassword\",a)).then(j.parse).then(f).then(i(\"reset-password-successfully\"))},currentUser:function(){return j.isAuthenticated()?a.when(j._currentUser):(null===j._promise&&(j._promise=j.login()),j._promise)},isAuthenticated:function(){return!!j._currentUser}};return j}]})}(angular);"
  },
  {
    "path": "lib/devise.js",
    "content": "(function(angular) {\n    'use strict';\n    var devise = angular.module('Devise', []);\n\n    devise.provider('AuthIntercept', function AuthInterceptProvider() {\n    /**\n     * Set to true to intercept 401 Unauthorized responses\n     */\n    var interceptAuth = false;\n\n    // The interceptAuth config function\n    this.interceptAuth = function(value) {\n        interceptAuth = !!value || value === void 0;\n        return this;\n    };\n\n    this.$get = ['$rootScope', '$q', function($rootScope, $q) {\n        // Only for intercepting 401 requests.\n        return {\n            responseError: function(response) {\n                // Determine if the response is specifically disabling the interceptor.\n                var intercept = response.config.interceptAuth;\n                intercept = !!intercept || (interceptAuth && intercept === void 0);\n\n                if (intercept && response.status === 401) {\n                    var deferred = $q.defer();\n                    $rootScope.$broadcast('devise:unauthorized', response, deferred);\n                    deferred.reject(response);\n                    return deferred.promise;\n                }\n\n                return $q.reject(response);\n            }\n        };\n    }];\n}).config(['$httpProvider', function($httpProvider) {\n    $httpProvider.interceptors.push('AuthIntercept');\n}]);\n\n    devise.provider('Auth', function AuthProvider() {\n    /**\n     * The default paths.\n     */\n    var paths = {\n        login: '/users/sign_in.json',\n        logout: '/users/sign_out.json',\n        register: '/users.json',\n        sendResetPasswordInstructions: '/users/password.json',\n        resetPassword: '/users/password.json'\n    };\n\n    /**\n     * The default HTTP methods to use.\n     */\n    var methods = {\n        login: 'POST',\n        logout: 'DELETE',\n        register: 'POST',\n        sendResetPasswordInstructions: 'POST',\n        resetPassword: 'PUT'\n    };\n\n    /**\n     * Default devise resource_name is 'user', can be set to any string.\n     * If it's falsey, it will not namespace the data.\n     */\n    var resourceName = 'user';\n\n    /**\n     * The parsing function used to turn a $http\n     * response into a \"user\".\n     *\n     * Can be swapped with another parsing function\n     * using\n     *\n     *  angular.module('myModule', ['Devise']).\n     *  config(function(AuthProvider) {\n     *      AuthProvider.parse(function(response) {\n     *          return new User(response.data);\n     *      });\n     *  });\n     */\n    var _parse = function(response) {\n        return response.data;\n    };\n\n    // A helper function that will setup the ajax config\n    // and merge the data key if provided\n    function httpConfig(action, data, additionalConfig) {\n        var config = {\n            method: methods[action].toLowerCase(),\n            url: paths[action]\n        };\n\n        if (data) {\n            if (resourceName) {\n                config.data = {};\n                config.data[resourceName] = data;\n            } else {\n                config.data = data;\n            }\n        }\n\n        angular.extend(config, additionalConfig);\n        return config;\n    }\n\n    // A helper function to define our configure functions.\n    // Loops over all properties in obj, and creates a get/set\n    // method for [key + suffix] to set that property on obj.\n    function configure(obj, suffix) {\n        angular.forEach(obj, function(v, action) {\n            this[action + suffix] = function(param) {\n                if (param === undefined) {\n                    return obj[action];\n                }\n                obj[action] = param;\n                return this;\n            };\n        }, this);\n    }\n    configure.call(this, methods, 'Method');\n    configure.call(this, paths, 'Path');\n\n    // The resourceName config function\n    this.resourceName = function(value) {\n        if (value === undefined) {\n            return resourceName;\n        }\n        resourceName = value;\n        return this;\n    };\n\n    // The parse configure function.\n    this.parse = function(fn) {\n        if (typeof fn !== 'function') {\n            return _parse;\n        }\n        _parse = fn;\n        return this;\n    };\n\n    // Creates a function that always\n    // returns a given arg.\n    function constant(arg) {\n        return function() {\n            return arg;\n        };\n    }\n\n    this.$get = ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {\n        // Our shared save function, called\n        // by `then`s.\n        function save(user) {\n            service._currentUser = user;\n            return user;\n        }\n        // A reset that saves null for currentUser\n        function reset() {\n            save(null);\n            service._promise = null;\n        }\n\n        function broadcast(name) {\n            return function(data) {\n                $rootScope.$broadcast('devise:' + name, data);\n                return data;\n            };\n        }\n\n        var service = {\n            /**\n             * The Auth service's current user.\n             * This is shared between all instances of Auth\n             * on the scope.\n             */\n            _currentUser: null,\n\n            /**\n             * The Auth service's parsing function.\n             * Defaults to the parsing function set in the provider,\n             * but may also be overwritten directly on the service.\n             */\n            parse: _parse,\n\n            /**\n             * The Auth service's current promise\n             * This is shared between all instances of Auth\n             * on the scope.\n             */\n            _promise: null,\n\n            /* reset promise and current_user, after call this method all\n             * xhr request will be reprocessed when they will be call\n             */\n            reset: function(){\n                reset();\n                service.currentUser();\n            },\n\n            /**\n             * A login function to authenticate with the server.\n             * Keep in mind, credentials are sent in plaintext;\n             * use a SSL connection to secure them. By default,\n             * `login` will POST to '/users/sign_in.json'.\n             *\n             * The path and HTTP method used to login are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.loginPath('path/on/server.json');\n             *      AuthProvider.loginMethod('GET');\n             *  });\n             *\n             * @param {Object} [creds] A hash of user credentials.\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            login: function(creds, config) {\n                var withCredentials = arguments.length > 0,\n                    loggedIn = service.isAuthenticated();\n\n                creds = creds || {};\n                return $http(httpConfig('login', creds, config))\n                    .then(service.parse)\n                    .then(save)\n                    .then(function(user) {\n                        if (withCredentials && !loggedIn) {\n                            return broadcast('new-session')(user);\n                        }\n                        return user;\n                    })\n                    .then(broadcast('login'));\n            },\n\n            /**\n             * A logout function to de-authenticate from the server.\n             * By default, `logout` will DELETE to '/users/sign_out.json'.\n             *\n             * The path and HTTP method used to logout are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.logoutPath('path/on/server.json');\n             *      AuthProvider.logoutMethod('GET');\n             *  });\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            logout: function(config) {\n                var returnOldUser = constant(service._currentUser);\n                return $http(httpConfig('logout', undefined, config))\n                    .then(reset)\n                    .then(returnOldUser)\n                    .then(broadcast('logout'));\n            },\n\n            /**\n             * A register function to register and authenticate\n             * with the server. Keep in mind, credentials are sent\n             * in plaintext; use a SSL connection to secure them.\n             * By default, `register` will POST to '/users.json'.\n             *\n             * The path and HTTP method used to login are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.registerPath('path/on/server.json');\n             *      AuthProvider.registerMethod('GET');\n             *  });\n             *\n             * @param {Object} [creds] A hash of user credentials.\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            register: function(creds, config) {\n                creds = creds || {};\n                return $http(httpConfig('register', creds, config))\n                    .then(service.parse)\n                    .then(save)\n                    .then(broadcast('new-registration'));\n            },\n\n            /**\n             * A function to send the reset password instructions to the\n             * user email.\n             * By default, `sendResetPasswordInstructions` will POST to '/users/password.json'.\n             *\n             * The path and HTTP method used to send instructions are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.sendResetPasswordInstructionsPath('path/on/server.json');\n             *      AuthProvider.sendResetPasswordInstructionsMethod('POST');\n             *  });\n             *\n             * @param {Object} [creds] A hash containing user email.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            sendResetPasswordInstructions: function(creds) {\n                creds = creds || {};\n                return $http(httpConfig('sendResetPasswordInstructions', creds))\n                    .then(service.parse)\n                    .then(broadcast('send-reset-password-instructions-successfully'));\n            },\n\n            /**\n             * A reset function to reset user password.\n             * By default, `resetPassword` will PUT to '/users/password.json'.\n             *\n             * The path and HTTP method used to reset password are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.resetPasswordPath('path/on/server.json');\n             *      AuthProvider.resetPasswordMethod('POST');\n             *  });\n             *\n             * @param {Object} [creds] A hash containing password, password_confirmation and reset_password_token.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            resetPassword: function(creds) {\n                creds = creds || {};\n                return $http(httpConfig('resetPassword', creds))\n                    .then(service.parse)\n                    .then(save)\n                    .then(broadcast('reset-password-successfully'));\n            },\n\n            /**\n             * A helper function that will return a promise with the currentUser.\n             * Three different outcomes can happen:\n             *  1. Auth has authenticated a user, and will resolve with it\n             *  2. Auth has not authenticated a user but the server has an\n             *      authenticated session, Auth will attempt to retrieve that\n             *      session and resolve with its user.\n             *  3. Neither Auth nor the server has an authenticated session,\n             *      and will reject with an unauthenticated error.\n             *\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            currentUser: function() {\n                if (service.isAuthenticated()) {\n                    return $q.when(service._currentUser);\n                }\n                if(service._promise === null){\n                    service._promise = service.login();\n                }\n                return service._promise;\n            },\n\n            /**\n             * A helper function to determine if a currentUser is present.\n             *\n             * @returns Boolean\n             */\n            isAuthenticated: function(){\n                return !!service._currentUser;\n            }\n        };\n\n        return service;\n    }];\n});\n\n})(angular);\n"
  },
  {
    "path": "package.json",
    "content": "{\n    \"name\": \"AngularDevise\",\n    \"version\": \"1.3.0\",\n    \"description\": \"A small AngularJS Service to interact with Devise Authentication.\",\n    \"main\": \"lib/devise.js\",\n    \"scripts\": {\n        \"test\": \"grunt test\"\n    },\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"https://github.com/cloudspace/angular_devise.git\"\n    },\n    \"keywords\": [\n        \"Angular\",\n        \"AngularJS\",\n        \"Devise\"\n    ],\n    \"author\": \"Justin Ridgewell\",\n    \"license\": \"MIT\",\n    \"bugs\": {\n        \"url\": \"https://github.com/cloudspace/angular_devise/issues\"\n    },\n    \"dependencies\": {},\n    \"devDependencies\": {\n        \"grunt\": \"~0.4.1\",\n        \"grunt-contrib-jshint\": \"~0.6.2\",\n        \"grunt-contrib-uglify\": \"~0.2.2\",\n        \"grunt-karma\": \"~0.12.1\",\n        \"grunt-ng-annotate\": \"~0.5.0\",\n        \"grunt-plato\": \"~0.2.1\",\n        \"grunt-preprocess\": \"~2.3.0\",\n        \"jasmine\": \"^2.4.1\",\n        \"karma\": \"^0.13.21\",\n        \"karma-jasmine\": \"^0.3.7\",\n        \"karma-phantomjs-launcher\": \"^1.0.0\",\n        \"load-grunt-tasks\": \"~0.2.0\",\n        \"phantomjs-prebuilt\": \"^2.1.4\",\n        \"time-grunt\": \"~0.2.1\"\n    }\n}\n"
  },
  {
    "path": "src/401.js",
    "content": "devise.provider('AuthIntercept', function AuthInterceptProvider() {\n    /**\n     * Set to true to intercept 401 Unauthorized responses\n     */\n    var interceptAuth = false;\n\n    // The interceptAuth config function\n    this.interceptAuth = function(value) {\n        interceptAuth = !!value || value === void 0;\n        return this;\n    };\n\n    this.$get = function($rootScope, $q) {\n        // Only for intercepting 401 requests.\n        return {\n            responseError: function(response) {\n                // Determine if the response is specifically disabling the interceptor.\n                var intercept = response.config.interceptAuth;\n                intercept = !!intercept || (interceptAuth && intercept === void 0);\n\n                if (intercept && response.status === 401) {\n                    var deferred = $q.defer();\n                    $rootScope.$broadcast('devise:unauthorized', response, deferred);\n                    deferred.reject(response);\n                    return deferred.promise;\n                }\n\n                return $q.reject(response);\n            }\n        };\n    };\n}).config(function($httpProvider) {\n    $httpProvider.interceptors.push('AuthIntercept');\n});\n"
  },
  {
    "path": "src/auth.js",
    "content": "devise.provider('Auth', function AuthProvider() {\n    /**\n     * The default paths.\n     */\n    var paths = {\n        login: '/users/sign_in.json',\n        logout: '/users/sign_out.json',\n        register: '/users.json',\n        sendResetPasswordInstructions: '/users/password.json',\n        resetPassword: '/users/password.json'\n    };\n\n    /**\n     * The default HTTP methods to use.\n     */\n    var methods = {\n        login: 'POST',\n        logout: 'DELETE',\n        register: 'POST',\n        sendResetPasswordInstructions: 'POST',\n        resetPassword: 'PUT'\n    };\n\n    /**\n     * The default host URL.\n     */\n    var baseUrl = '';\n\n    /**\n     * Default devise resource_name is 'user', can be set to any string.\n     * If it's falsey, it will not namespace the data.\n     */\n    var resourceName = 'user';\n\n    /**\n     * The parsing function used to turn a $http\n     * response into a \"user\".\n     *\n     * Can be swapped with another parsing function\n     * using\n     *\n     *  angular.module('myModule', ['Devise']).\n     *  config(function(AuthProvider) {\n     *      AuthProvider.parse(function(response) {\n     *          return new User(response.data);\n     *      });\n     *  });\n     */\n    var _parse = function(response) {\n        return response.data;\n    };\n\n    // A helper function that will setup the ajax config\n    // and merge the data key if provided\n    function httpConfig(action, data, additionalConfig) {\n        var config = {\n            method: methods[action].toLowerCase(),\n            url: paths[action]\n        };\n\n        if (data) {\n            if (resourceName) {\n                config.data = {};\n                config.data[resourceName] = data;\n            } else {\n                config.data = data;\n            }\n        }\n\n        angular.extend(config, additionalConfig);\n        return config;\n    }\n\n    // A helper function to define our configure functions.\n    // Loops over all properties in obj, and creates a get/set\n    // method for [key + suffix] to set that property on obj.\n    function configure(obj, suffix) {\n        angular.forEach(obj, function(v, action) {\n            this[action + suffix] = function(param) {\n                if (param === undefined) {\n                    return obj[action];\n                }\n                obj[action] = param;\n                return this;\n            };\n        }, this);\n    }\n    configure.call(this, methods, 'Method');\n    configure.call(this, paths, 'Path');\n\n    // The baseUrl config function\n    this.baseUrl = function(value) {\n      if (value === undefined) {\n          return baseUrl;\n      }\n      baseUrl = value;\n      return this;\n    };\n\n    // The resourceName config function\n    this.resourceName = function(value) {\n        if (value === undefined) {\n            return resourceName;\n        }\n        resourceName = value;\n        return this;\n    };\n\n    // The parse configure function.\n    this.parse = function(fn) {\n        if (typeof fn !== 'function') {\n            return _parse;\n        }\n        _parse = fn;\n        return this;\n    };\n\n    // Creates a function that always\n    // returns a given arg.\n    function constant(arg) {\n        return function() {\n            return arg;\n        };\n    }\n\n    this.$get = function($q, $http, $rootScope) {\n        // Our shared save function, called\n        // by `then`s.\n        function save(user) {\n            service._currentUser = user;\n            return user;\n        }\n        // A reset that saves null for currentUser\n        function reset() {\n            save(null);\n            service._promise = null;\n        }\n\n        function broadcast(name) {\n            return function(data) {\n                $rootScope.$broadcast('devise:' + name, data);\n                return data;\n            };\n        }\n\n        var service = {\n            /**\n             * The Auth service's current user.\n             * This is shared between all instances of Auth\n             * on the scope.\n             */\n            _currentUser: null,\n\n            /**\n             * The Auth service's parsing function.\n             * Defaults to the parsing function set in the provider,\n             * but may also be overwritten directly on the service.\n             */\n            parse: _parse,\n\n            /**\n             * The Auth service's current promise\n             * This is shared between all instances of Auth\n             * on the scope.\n             */\n            _promise: null,\n\n            /* reset promise and current_user, after call this method all\n             * xhr request will be reprocessed when they will be call\n             */\n            reset: function(){\n                reset();\n                service.currentUser();\n            },\n\n            /**\n             * A login function to authenticate with the server.\n             * Keep in mind, credentials are sent in plaintext;\n             * use a SSL connection to secure them. By default,\n             * `login` will POST to '/users/sign_in.json'.\n             *\n             * The path and HTTP method used to login are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.loginPath('path/on/server.json');\n             *      AuthProvider.loginMethod('GET');\n             *  });\n             *\n             * @param {Object} [creds] A hash of user credentials.\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            login: function(creds, config) {\n                var withCredentials = arguments.length > 0,\n                    loggedIn = service.isAuthenticated();\n\n                creds = creds || {};\n                return $http(httpConfig('login', creds, config))\n                    .then(service.parse)\n                    .then(save)\n                    .then(function(user) {\n                        if (withCredentials && !loggedIn) {\n                            return broadcast('new-session')(user);\n                        }\n                        return user;\n                    })\n                    .then(broadcast('login'));\n            },\n\n            /**\n             * A logout function to de-authenticate from the server.\n             * By default, `logout` will DELETE to '/users/sign_out.json'.\n             *\n             * The path and HTTP method used to logout are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.logoutPath('path/on/server.json');\n             *      AuthProvider.logoutMethod('GET');\n             *  });\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            logout: function(config) {\n                var returnOldUser = constant(service._currentUser);\n                return $http(httpConfig('logout', undefined, config))\n                    .then(reset)\n                    .then(returnOldUser)\n                    .then(broadcast('logout'));\n            },\n\n            /**\n             * A register function to register and authenticate\n             * with the server. Keep in mind, credentials are sent\n             * in plaintext; use a SSL connection to secure them.\n             * By default, `register` will POST to '/users.json'.\n             *\n             * The path and HTTP method used to login are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.registerPath('path/on/server.json');\n             *      AuthProvider.registerMethod('GET');\n             *  });\n             *\n             * @param {Object} [creds] A hash of user credentials.\n             * @param {Object} [config] Optional, additional config which\n             *                  will be added to http config for underlying\n             *                  $http.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            register: function(creds, config) {\n                creds = creds || {};\n                return $http(httpConfig('register', creds, config))\n                    .then(service.parse)\n                    .then(save)\n                    .then(broadcast('new-registration'));\n            },\n\n            /**\n             * A function to send the reset password instructions to the\n             * user email.\n             * By default, `sendResetPasswordInstructions` will POST to '/users/password.json'.\n             *\n             * The path and HTTP method used to send instructions are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.sendResetPasswordInstructionsPath('path/on/server.json');\n             *      AuthProvider.sendResetPasswordInstructionsMethod('POST');\n             *  });\n             *\n             * @param {Object} [creds] A hash containing user email.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            sendResetPasswordInstructions: function(creds) {\n                creds = creds || {};\n                return $http(httpConfig('sendResetPasswordInstructions', creds))\n                    .then(service.parse)\n                    .then(broadcast('send-reset-password-instructions-successfully'));\n            },\n\n            /**\n             * A reset function to reset user password.\n             * By default, `resetPassword` will PUT to '/users/password.json'.\n             *\n             * The path and HTTP method used to reset password are configurable\n             * using\n             *\n             *  angular.module('myModule', ['Devise']).\n             *  config(function(AuthProvider) {\n             *      AuthProvider.resetPasswordPath('path/on/server.json');\n             *      AuthProvider.resetPasswordMethod('POST');\n             *  });\n             *\n             * @param {Object} [creds] A hash containing password, password_confirmation and reset_password_token.\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            resetPassword: function(creds) {\n                creds = creds || {};\n                return $http(httpConfig('resetPassword', creds))\n                    .then(service.parse)\n                    .then(save)\n                    .then(broadcast('reset-password-successfully'));\n            },\n\n            /**\n             * A helper function that will return a promise with the currentUser.\n             * Three different outcomes can happen:\n             *  1. Auth has authenticated a user, and will resolve with it\n             *  2. Auth has not authenticated a user but the server has an\n             *      authenticated session, Auth will attempt to retrieve that\n             *      session and resolve with its user.\n             *  3. Neither Auth nor the server has an authenticated session,\n             *      and will reject with an unauthenticated error.\n             *\n             * @returns {Promise} A $http promise that will be resolved or\n             *                  rejected by the server.\n             */\n            currentUser: function() {\n                if (service.isAuthenticated()) {\n                    return $q.when(service._currentUser);\n                }\n                if(service._promise === null){\n                    service._promise = service.login();\n                }\n                return service._promise;\n            },\n\n            /**\n             * A helper function to determine if a currentUser is present.\n             *\n             * @returns Boolean\n             */\n            isAuthenticated: function(){\n                return !!service._currentUser;\n            }\n        };\n\n        return service;\n    };\n});\n"
  },
  {
    "path": "src/build/devise.js",
    "content": "(function(angular) {\n    'use strict';\n    var devise = angular.module('Devise', []);\n\n    // @include ../401.js\n    // @include ../auth.js\n})(angular);\n"
  },
  {
    "path": "test/devise.js",
    "content": "var devise = angular.module('Devise', []);\n"
  },
  {
    "path": "test/spec/401.js",
    "content": "'use strict';\n\ndescribe('Service: Devise.401', function () {\n\n    // load the service's module\n    beforeEach(module('Devise'));\n    var AuthInterceptProvider;\n    // load the service's module\n    beforeEach(module('Devise', function(_AuthInterceptProvider_) {\n        AuthInterceptProvider = _AuthInterceptProvider_;\n    }));\n\n    var $http, $httpBackend;\n    beforeEach(inject(function(_$http_, _$httpBackend_) {\n        $http = _$http_;\n        $httpBackend = _$httpBackend_;\n    }));\n\n    describe('responseError', function() {\n        beforeEach(function() {\n            $httpBackend.expect('GET', '/foo').respond(401);\n        });\n\n        describe('when interceptAuth is true', function() {\n            beforeEach(function() {\n                AuthInterceptProvider.interceptAuth();\n            });\n            afterEach(function() {\n                AuthInterceptProvider.interceptAuth(false);\n            });\n\n            it('can be disabled per request', inject(function ($rootScope) {\n                var callback = jasmine.createSpy('callback');\n                $rootScope.$on('devise:unauthorized', callback);\n                $http.get('/foo', { interceptAuth: false });\n                $httpBackend.flush();\n                expect(callback).not.toHaveBeenCalled();\n            }));\n\n            it('broadcasts \"devise:unauthorized\" on 401 error', inject(function ($rootScope) {\n                var callback = jasmine.createSpy('callback');\n                $rootScope.$on('devise:unauthorized', callback);\n                $http.get('/foo');\n                $httpBackend.flush();\n                expect(callback).toHaveBeenCalled();\n            }));\n\n            it('passes response to broadcast', inject(function ($rootScope) {\n                var response;\n                $rootScope.$on('devise:unauthorized', function(event, resp) {\n                    response = resp;\n                });\n\n                $http.get('/foo');\n                $httpBackend.flush();\n\n                expect(response.status).toBe(401);\n            }));\n\n            it('passes a deferred to broadcast', inject(function ($rootScope) {\n                var deferred;\n                $rootScope.$on('devise:unauthorized', function(event, resp, d) {\n                    deferred = d;\n                });\n\n                $http.get('/foo');\n                $httpBackend.flush();\n\n                expect(typeof deferred.resolve).toBe('function');\n                expect(typeof deferred.reject).toBe('function');\n            }));\n\n            it(\"returns deferred's promise\", inject(function ($rootScope) {\n                var data = {};\n                $rootScope.$on('devise:unauthorized', function(event, response, deferred) {\n                    deferred.resolve(data);\n                });\n\n                var ret;\n                $http.get('/foo').then(function(data) {\n                    ret = data;\n                });\n                $httpBackend.flush();\n\n                expect(ret).toBe(data);\n            }));\n        });\n\n        describe('when interceptAuth is false (default)', function() {\n            it('returns rejected promise on 401', function () {\n                var callback = jasmine.createSpy('callback');\n                $http.get('/foo').catch(callback);\n                $httpBackend.flush();\n                expect(callback).toHaveBeenCalled();\n            });\n\n            it('can be enabled per request', inject(function ($rootScope) {\n                var callback = jasmine.createSpy('callback');\n                $rootScope.$on('devise:unauthorized', callback);\n                $http.get('/foo', { interceptAuth: true });\n                $httpBackend.flush();\n                expect(callback).toHaveBeenCalled();\n            }));\n\n        });\n    });\n\n});\n"
  },
  {
    "path": "test/spec/auth.js",
    "content": "'use strict';\n\ndescribe('Provider: Devise.Auth', function () {\n\n    var AuthProvider;\n    // load the service's module\n    beforeEach(module('Devise', function(_AuthProvider_) {\n        AuthProvider = _AuthProvider_;\n    }));\n\n    // instantiate service\n    var Auth, $rootScope, $http, $httpBackend;\n    beforeEach(inject(function (_Auth_, _$rootScope_, _$http_, _$httpBackend_) {\n        Auth = _Auth_;\n        $rootScope = _$rootScope_;\n        $http = _$http_;\n        $httpBackend = _$httpBackend_;\n    }));\n    function forceSignIn(Auth, user) {\n        user = (user === undefined) ? {} : user;\n        Auth._currentUser = user;\n        return user;\n    }\n    function jsonEquals(obj, other) {\n        return JSON.stringify(obj) === JSON.stringify(other);\n    }\n    function constantTrue() {\n        return true;\n    }\n\n    describe('can configure', function() {\n        function initService(fn) {\n            fn();\n            inject(function($q, $http, $rootScope) {\n                Auth = new AuthProvider.$get($q, $http, $rootScope);\n            });\n        }\n        function testPathConfigure(action, method, overrideMethod) {\n            initService(function() {\n                if (overrideMethod) {\n                    AuthProvider[action + 'Method'](method);\n                }\n                AuthProvider[action + 'Path']('/test/test');\n            });\n            $httpBackend.expect(method, '/test/test').respond({});\n            Auth[action]();\n            $httpBackend.flush();\n        }\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('.loginPath', function() {\n            testPathConfigure('login', 'POST');\n        });\n\n        it('.logoutPath', function() {\n            testPathConfigure('logout', 'DELETE');\n        });\n\n        it('.registerPath', function() {\n            testPathConfigure('register', 'POST');\n        });\n\n        it('.sendResetPasswordInstructionsPath', function() {\n            testPathConfigure('sendResetPasswordInstructions', 'POST');\n        });\n\n        it('.resetPasswordPath', function() {\n            testPathConfigure('resetPassword', 'PUT');\n        });\n\n        it('.loginMethod', function() {\n            testPathConfigure('login', 'GET', true);\n        });\n\n        it('.logoutMethod', function() {\n            testPathConfigure('logout', 'GET', true);\n        });\n\n        it('.registerMethod', function() {\n            testPathConfigure('register', 'GET', true);\n        });\n\n        it('.sendResetPasswordInstructionsMethod', function() {\n            testPathConfigure('sendResetPasswordInstructions', 'GET', true);\n        });\n\n        it('.resetPasswordMethod', function() {\n            testPathConfigure('resetPassword', 'GET', true);\n        });\n\n        it('.parse', function() {\n            initService(function() {\n                AuthProvider.parse(function(response) {\n                    return new User(response.data);\n                });\n            });\n            var User = function(params) {\n                this.params = params;\n            };\n            var params = {id: 1, name: 'test', email: 'test@email.com', password: 'password'};\n            var callCount = 0;\n            var callback = function(user) {\n                expect(user instanceof User).toBe(true);\n                expect(user.params).toEqual(params);\n                ++callCount;\n            };\n            $httpBackend.expect('POST', '/users/sign_in.json').respond(params);\n\n            Auth.login().then(callback);\n            $httpBackend.flush();\n\n            expect(callCount).toBe(1);\n        });\n\n        it('.baseUrl', function() {\n            var baseUrl = 'http://localhost:3000';\n            initService(function() {\n              AuthProvider.baseUrl(baseUrl);\n            });\n            expect(AuthProvider.baseUrl()).toEqual(baseUrl);\n        });\n\n        describe('.resourceName', function() {\n            var credentials = {test: 'test'};\n            afterEach(function() {\n                $httpBackend.verifyNoOutstandingExpectation();\n                $httpBackend.verifyNoOutstandingRequest();\n            });\n\n            describe('truthy resourceName', function() {\n                it('.login', function() {\n                    initService(function() {\n                        AuthProvider.resourceName('test');\n                    });\n                    $httpBackend.expect('POST', '/users/sign_in.json', {test: credentials}).respond({});\n\n                    Auth.login({test: 'test'});\n                    $httpBackend.flush();\n                });\n\n                it('.register', function() {\n                    initService(function() {\n                        AuthProvider.resourceName('test');\n                    });\n                    $httpBackend.expect('POST', '/users.json', {test: credentials}).respond({});\n\n                    Auth.register({test: 'test'});\n                    $httpBackend.flush();\n                });\n            });\n\n            describe('falsey resourceName', function() {\n                it('.login', function() {\n                    initService(function() {\n                        AuthProvider.resourceName(false);\n                    });\n                    $httpBackend.expect('POST', '/users/sign_in.json', credentials).respond({});\n\n                    Auth.login({test: 'test'});\n                    $httpBackend.flush();\n                });\n\n                it('.register', function() {\n                    initService(function() {\n                        AuthProvider.resourceName(false);\n                    });\n                    $httpBackend.expect('POST', '/users.json', credentials).respond({});\n\n                    Auth.register({test: 'test'});\n                    $httpBackend.flush();\n                });\n            });\n        });\n\n    });\n\n    describe('.login', function() {\n        var user;\n        var creds = {email: 'test', blah: true};\n        var postCallback, headerCallback;\n        function callbackWraper(data) {\n            data = JSON.parse(data);\n            return postCallback(data);\n        }\n        function headerWrapper(headers) {\n            return headerCallback(headers);\n        }\n\n        beforeEach(function() {\n            headerCallback = postCallback = constantTrue;\n            user = {id: 1, name: 'test', email: 'test@email.com', password: 'password'};\n            $httpBackend.expect('POST', '/users/sign_in.json', callbackWraper, headerWrapper).respond(user);\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('POSTs to /users/sign_in.json', function() {\n            Auth.login();\n            $httpBackend.flush();\n        });\n\n        it('POSTS credential data', function() {\n            postCallback = function(data) {\n                return jsonEquals(data.user, creds);\n            };\n            Auth.login(creds);\n            $httpBackend.flush();\n        });\n\n        it('returns a promise', function() {\n            expect(Auth.login().then).toBeDefined();\n            $httpBackend.flush();\n        });\n\n        it('resolves promise to currentUser', function() {\n            var callback = jasmine.createSpy('callback');\n            Auth.login().then(callback);\n\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(user);\n        });\n\n        it('broadcasts the session event and login events', function() {\n            var loginCallback = jasmine.createSpy('login callback');\n            var sessionCallback = jasmine.createSpy('session callback');\n            $rootScope.$on('devise:new-session', sessionCallback);\n            $rootScope.$on('devise:login', loginCallback);\n\n            Auth.login(creds);\n            $httpBackend.flush();\n\n            expect(loginCallback).toHaveBeenCalledWith(jasmine.any(Object), user);\n            expect(sessionCallback).toHaveBeenCalledWith(jasmine.any(Object), user);\n        });\n\n        it('sends additional config to underlying $http', function() {\n            headerCallback = function(headers) {\n                return headers.test;\n            };\n            var headers = { test: true };\n            Auth.login(user, {headers: headers});\n            $httpBackend.flush();\n        });\n    });\n\n    describe('.logout', function() {\n        var headerCallback;\n        function headerWrapper(headers) {\n            return headerCallback(headers);\n        }\n\n        beforeEach(function() {\n            headerCallback = constantTrue;\n            $httpBackend.expect('DELETE', '/users/sign_out.json', null, headerWrapper).respond({});\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('DELETEs to /users/sign_out.json', function() {\n            Auth.logout();\n            $httpBackend.flush();\n        });\n\n        it('returns a promise', function() {\n            expect(Auth.logout().then).toBeDefined();\n            $httpBackend.flush();\n        });\n\n        it('resolves promise to old currentUser', function() {\n            var user = forceSignIn(Auth, {id: 0});\n            var callback = jasmine.createSpy('callback');\n            Auth.logout().then(callback);\n\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(user);\n        });\n\n        it('broadcasts the logout event', function() {\n            var callback = jasmine.createSpy('logout callback');\n            $rootScope.$on('devise:logout', callback);\n\n            Auth.logout();\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalled();\n        });\n\n        it('sends additional config to underlying $http', function() {\n            headerCallback = function(headers) {\n                return headers.test;\n            };\n            var headers = { test: true };\n            Auth.logout({headers: headers});\n            $httpBackend.flush();\n        });\n    });\n\n    describe('.register', function() {\n        var user;\n        var postCallback, headerCallback;\n        function callbackWraper(data) {\n            data = JSON.parse(data);\n            return postCallback(data);\n        }\n        function headerWrapper(headers) {\n            return headerCallback(headers);\n        }\n\n        beforeEach(function() {\n            headerCallback = postCallback = constantTrue;\n            user = {id: 1, name: 'test', email: 'test@email.com', password: 'password'};\n            $httpBackend.expect('POST', '/users.json', callbackWraper, headerWrapper).respond(user);\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('POSTs to /users.json', function() {\n            Auth.register();\n            $httpBackend.flush();\n        });\n\n        it('POSTS credential data', function() {\n            var u = {email: 'test', blah: true};\n            postCallback = function(data) {\n                return jsonEquals(data.user, u);\n            };\n            Auth.register(u);\n            $httpBackend.flush();\n        });\n\n        it('returns a promise', function() {\n            expect(Auth.register().then).toBeDefined();\n            $httpBackend.flush();\n        });\n\n        it('resolves promise to currentUser', function() {\n            var callback = jasmine.createSpy('callback');\n            Auth.register().then(callback);\n\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(user);\n        });\n\n        it('broadcasts the new-registration event after a sucessful registration', function() {\n            var callback = jasmine.createSpy('callback');\n            $rootScope.$on('devise:new-registration', callback);\n\n            Auth.register();\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(jasmine.any(Object), user);\n        });\n\n        it('sends additional config to underlying $http', function() {\n            headerCallback = function(headers) {\n                return headers.test;\n            };\n            var headers = { test: true };\n            Auth.register(null, {headers: headers});\n            $httpBackend.flush();\n        });\n    });\n\n    describe('.sendResetPasswordInstructions', function() {\n        var user;\n        var postCallback;\n        function constantTrue() {\n            return true;\n        }\n        function callbackWraper(data) {\n            data = JSON.parse(data);\n            return postCallback(data);\n        }\n\n        beforeEach(function() {\n            postCallback = constantTrue;\n            $httpBackend.expect('POST', '/users/password.json', callbackWraper).respond(\"\");\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('POSTs to /users/password.json', function() {\n            Auth.sendResetPasswordInstructions();\n            $httpBackend.flush();\n        });\n\n        it('POSTs email data', function() {\n            var u = {user: {email: 'new_email'}};\n            postCallback = function(data) {\n                return jsonEquals(data.user, u);\n            };\n            Auth.sendResetPasswordInstructions(u);\n            $httpBackend.flush();\n        });\n\n        it('returns a promise', function() {\n            expect(Auth.sendResetPasswordInstructions().then).toBeDefined();\n            $httpBackend.flush();\n        });\n\n        it('broadcasts the send-reset-password-instructions-successfully event after a sucessful sendResetPasswordInstructions', function() {\n            var callback = jasmine.createSpy('callback');\n            $rootScope.$on('devise:send-reset-password-instructions-successfully', callback);\n\n            Auth.sendResetPasswordInstructions();\n            $httpBackend.flush();\n        });\n    });\n\n    describe('.resetPassword', function() {\n        var user;\n        var postCallback;\n        function constantTrue() {\n            return true;\n        }\n        function callbackWraper(data) {\n            data = JSON.parse(data);\n            return postCallback(data);\n        }\n\n        beforeEach(function() {\n            postCallback = constantTrue;\n            user = {user: { id: 1, name: 'test', email: 'test@email.com', password: 'password'}};\n            $httpBackend.expect('PUT', '/users/password.json', callbackWraper).respond(user);\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('PUTs to /users/password.json', function() {\n            Auth.resetPassword();\n            $httpBackend.flush();\n        });\n\n        it('PUTs updated data', function() {\n            var u = {user: {password: 'new_password', password_confirmation: 'new_password', reset_password_token: 'token'}};\n            postCallback = function(data) {\n                return jsonEquals(data.user, u);\n            };\n            Auth.resetPassword(u);\n            $httpBackend.flush();\n        });\n\n        it('returns a promise', function() {\n            expect(Auth.resetPassword().then).toBeDefined();\n            $httpBackend.flush();\n        });\n\n        it('resolves promise to currentUser', function() {\n            var callback = jasmine.createSpy('callback');\n            Auth.resetPassword().then(callback);\n\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(user);\n        });\n\n        it('broadcasts the reset-password-successfully event after a sucessful resetPassword', function() {\n            var callback = jasmine.createSpy('callback');\n            $rootScope.$on('devise:reset-password-successfully', callback);\n\n            Auth.resetPassword();\n            $httpBackend.flush();\n\n            expect(callback).toHaveBeenCalledWith(jasmine.any(Object), user);\n        });\n    });\n\n    describe('.parse', function() {\n        beforeEach(function() {\n            var response = {id: 1, name: 'test', email: 'test@email.com'};\n            $httpBackend.when('POST', '/users/sign_in.json').respond(response);\n        });\n        afterEach(function() {\n            $httpBackend.verifyNoOutstandingExpectation();\n            $httpBackend.verifyNoOutstandingRequest();\n        });\n\n        it('can be customized', function() {\n            var User = function(params) {\n                this.params = params;\n            };\n            var callCount = 0;\n\n            Auth.login().then(function(user){\n                expect(user instanceof User).toBe(false);\n                ++callCount;\n            });\n            Auth.parse = function(response) {\n                return new User(response.data);\n            };\n            Auth.login().then(function(user){\n                expect(user instanceof User).toBe(true);\n                ++callCount;\n            });\n            $httpBackend.flush();\n\n            expect(callCount).toBe(2);\n        });\n    });\n\n    describe('.currentUser', function() {\n        describe('when authenticated', function() {\n            var user;\n            beforeEach(function() {\n                user = forceSignIn(Auth);\n            });\n\n            it('returns a promise', function() {\n                var callback = jasmine.createSpy('callback');\n\n                Auth.currentUser().then(callback);\n                // use #$apply to have the promise resolve.\n                $rootScope.$apply();\n\n                expect(callback).toHaveBeenCalled();\n            });\n\n            it('resolves the promise with the currentUser', function() {\n                var callback = jasmine.createSpy('callback');\n\n                Auth.currentUser().then(callback);\n                // use #$apply to have the promise resolve.\n                $rootScope.$apply();\n\n                expect(callback).toHaveBeenCalledWith(user);\n            });\n\n            it('does not broadcasts any events', function() {\n                var callback = jasmine.createSpy('any callback');\n                $rootScope.$on('devise:new-session', callback);\n                $rootScope.$on('devise:login', callback);\n                Auth.currentUser();\n                $rootScope.$apply();\n\n                expect(callback).not.toHaveBeenCalled();\n            });\n        });\n\n        describe('when unauthenticated', function() {\n            describe('when user is logged in on server', function() {\n                var user = {};\n                beforeEach(function() {\n                    $httpBackend.expect('POST', '/users/sign_in.json').respond(user);\n                });\n\n                it('fetches user from server', function() {\n                    Auth.currentUser();\n                    $httpBackend.flush();\n                    $httpBackend.verifyNoOutstandingExpectation();\n                    $httpBackend.verifyNoOutstandingRequest();\n                });\n\n                it('resolves promise with fetched user', function() {\n                    var callback = jasmine.createSpy('callback');\n                    Auth.currentUser().then(callback);\n                    $httpBackend.flush();\n\n                    expect(callback).toHaveBeenCalledWith(user);\n                });\n\n                it('broadcasts the session event but not the login event', function() {\n                    var loginCallback = jasmine.createSpy('login callback');\n                    var sessionCallback = jasmine.createSpy('new-session callback');\n                    $rootScope.$on('devise:new-session', sessionCallback);\n                    $rootScope.$on('devise:login', loginCallback);\n\n                    Auth.currentUser();\n                    $httpBackend.flush();\n\n                    expect(sessionCallback).not.toHaveBeenCalled();\n                    expect(loginCallback).toHaveBeenCalledWith(jasmine.any(Object), user);\n                });\n            });\n\n            describe('when user is not logged in on server', function() {\n                var error = {error: 'unauthorized'};\n                beforeEach(function() {\n                    $httpBackend.expect('POST', '/users/sign_in.json').respond(401, error);\n                });\n\n                it('does not resolve promise', function() {\n                    var callback = jasmine.createSpy('callback');\n                    Auth.currentUser().then(callback);\n                    $httpBackend.flush();\n\n                    expect(callback).not.toHaveBeenCalled();\n                });\n            });\n        });\n    });\n\n    describe('.isAuthenticated', function() {\n        it('returns false if no currentUser', function() {\n            forceSignIn(Auth, null);\n            expect(Auth.isAuthenticated()).toBe(false);\n        });\n\n        it('returns true if a currentUser', function() {\n            forceSignIn(Auth);\n            expect(Auth.isAuthenticated()).toBe(true);\n        });\n    });\n});\n"
  }
]