Skip to content

Commit bdcac1a

Browse files
author
Justin Ridgewell
committed
Initial Commit.
0 parents  commit bdcac1a

18 files changed

+486
-0
lines changed

.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "test/support"
3+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
test/support/
3+
reports/

.jshintrc

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"esnext": true,
5+
"bitwise": true,
6+
"camelcase": false,
7+
"curly": true,
8+
"eqeqeq": true,
9+
"eqnull": true,
10+
"expr": true,
11+
"immed": true,
12+
"indent": 4,
13+
"latedef": true,
14+
"newcap": true,
15+
"noarg": true,
16+
"regexp": true,
17+
"undef": true,
18+
"unused": true,
19+
"strict": false,
20+
"trailing": true,
21+
"smarttabs": true,
22+
"white": false,
23+
"globals": {
24+
"after": false,
25+
"afterEach": false,
26+
"angular": false,
27+
"before": false,
28+
"beforeEach": false,
29+
"browser": false,
30+
"describe": false,
31+
"expect": false,
32+
"inject": false,
33+
"it": false,
34+
"spyOn": false,
35+
"devise": true
36+
}
37+
}

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
before_script:
5+
- npm install
6+
- npm install -g grunt-cli bower
7+
- bower install

Gruntfile.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*global module:false*/
2+
module.exports = function(grunt) {
3+
4+
// Project configuration.
5+
grunt.initConfig({
6+
pkg: grunt.file.readJSON('package.json'),
7+
meta: {
8+
version: '<%= pkg.version %>',
9+
banner:
10+
'// AngularDevise\n' +
11+
'// -------------------\n' +
12+
'// v<%= pkg.version %>\n' +
13+
'//\n' +
14+
'// Copyright (c)<%= grunt.template.today("yyyy") %> Justin Ridgewell\n' +
15+
'// Distributed under MIT license\n' +
16+
'//\n' +
17+
'// https://github.com/cloudspace/angular_devise\n' +
18+
'\n'
19+
},
20+
21+
preprocess: {
22+
build: {
23+
files: {
24+
'lib/devise.js' : 'src/build/devise.js'
25+
}
26+
}
27+
},
28+
29+
uglify : {
30+
options: {
31+
banner: "<%= meta.banner %>"
32+
},
33+
core : {
34+
src : 'lib/devise.js',
35+
dest : 'lib/devise-min.js',
36+
}
37+
},
38+
39+
jshint: {
40+
options: {
41+
jshintrc : '.jshintrc'
42+
},
43+
devise : [ 'src/*.js' ],
44+
test : [ 'test/*.js', 'test/specs/*.js' ],
45+
},
46+
47+
plato: {
48+
devise : {
49+
src : 'src/*.js',
50+
dest : 'reports',
51+
options : {
52+
jshint : false
53+
}
54+
}
55+
},
56+
57+
ngmin: {
58+
dist: {
59+
src: 'lib/devise.js',
60+
dest: 'lib/devise.js'
61+
}
62+
},
63+
64+
karma: {
65+
options: {
66+
configFile: 'karma.conf.js',
67+
},
68+
unit: {
69+
},
70+
continuous: {
71+
singleRun: false,
72+
browsers: ['PhantomJS']
73+
}
74+
}
75+
});
76+
77+
require('load-grunt-tasks')(grunt);
78+
require('time-grunt')(grunt);
79+
80+
// Default task.
81+
grunt.registerTask('lint-test', 'jshint:test');
82+
grunt.registerTask('test', 'karma:unit');
83+
grunt.registerTask('travis', ['jshint:devise', 'karma']);
84+
grunt.registerTask('default', ['jshint:devise', 'test', 'preprocess', 'ngmin', 'uglify']);
85+
86+
};

LICENSE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2013 Justin Ridgewell
2+
===================================
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
AngularDevise
2+
=============
3+
4+
A small AngularJS Service to interact with Devise Authentication.
5+
6+
7+
Requirements
8+
------------
9+
10+
This service requires Devise to respond to JSON. To do that, simply add
11+
12+
```ruby
13+
# app/controllers/application_controller.rb
14+
class ApplicationController < ActionController::Base
15+
respond_to :html, :json
16+
# ...
17+
end
18+
```

bower.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "AngularDevise",
3+
"version": "0.0.1",
4+
"main": "lib/devise.js",
5+
"ignore": [
6+
"**/.*",
7+
"node_modules",
8+
"components",
9+
"bower_components",
10+
"spec",
11+
"reports"
12+
],
13+
"author": {
14+
"name": "Justin Ridgewell"
15+
},
16+
"dependencies": {
17+
"angular": "~1.2.0"
18+
},
19+
"devDependencies": {
20+
"angular-mocks": "~1.2.0",
21+
"angular-scenario": "~1.2.0"
22+
}
23+
}

karma.conf.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = function(config) {
2+
config.set({
3+
// base path, that will be used to resolve files and exclude
4+
basePath: '',
5+
6+
// testing framework to use (jasmine/mocha/qunit/...)
7+
frameworks: ['jasmine'],
8+
9+
// list of files / patterns to load in the browser
10+
files: [
11+
'test/support/angular/angular.js',
12+
'test/support/angular-mocks/angular-mocks.js',
13+
'test/devise.js',
14+
'src/*.js',
15+
'test/mock/**/*.js',
16+
'test/spec/**/*.js'
17+
],
18+
19+
// list of files / patterns to exclude
20+
exclude: [],
21+
22+
// web server port
23+
port: 8080,
24+
25+
// level of logging
26+
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
27+
logLevel: config.LOG_INFO,
28+
29+
30+
// enable / disable watching file and executing tests whenever any file changes
31+
autoWatch: true,
32+
33+
34+
browsers: ['Chrome'],
35+
36+
singleRun: true
37+
});
38+
};

lib/.gitkeep

Whitespace-only changes.

lib/devise-min.js

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/devise.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'use strict';
2+
(function (angular) {
3+
var devise = angular.module('Devise', []);
4+
devise.config([
5+
'$httpProvider',
6+
function ($httpProvider) {
7+
$httpProvider.interceptors.push(function ($location, $q) {
8+
return {
9+
responseError: function (response) {
10+
if (response.status === 401) {
11+
$location.path('/users/login');
12+
return response;
13+
}
14+
return $q.reject(response);
15+
}
16+
};
17+
});
18+
$httpProvider.defaults.headers.common['X-CSRF-Token'] = angular.element(document.querySelector('meta[name=csrf-token]')).attr('content');
19+
}
20+
]);
21+
devise.factory('Auth', [
22+
'$q',
23+
'$location',
24+
'$http',
25+
function ($q, $location, $http) {
26+
var slice = Array.prototype.slice;
27+
function redirect(url) {
28+
if (url == null) {
29+
return;
30+
}
31+
url = url || '/';
32+
$location.path(url);
33+
}
34+
function pick(old) {
35+
var obj = {};
36+
var props = slice.call(arguments, 1);
37+
var l = props.length;
38+
var prop;
39+
while (l--) {
40+
prop = props[l];
41+
obj[prop] = old[prop];
42+
}
43+
return obj;
44+
}
45+
var service = {
46+
currentUser: null,
47+
login: function (opts) {
48+
if (!opts) {
49+
opts = {};
50+
}
51+
var user = pick(opts, 'email', 'password');
52+
return $http.post('/users/sign_in.json', { user: user }).then(function (response) {
53+
service.currentUser = response.data;
54+
redirect(opts.redirect);
55+
return service.requestCurrentUser();
56+
});
57+
},
58+
logout: function (opts) {
59+
if (!opts) {
60+
opts = {};
61+
}
62+
$http.delete('/users/sign_out.json').then(function () {
63+
service.currentUser = null;
64+
redirect(opts.redirect);
65+
});
66+
},
67+
register: function (opts) {
68+
if (!opts) {
69+
opts = {};
70+
}
71+
var user = pick(opts, 'email', 'password', 'password_confirmation');
72+
if (!user.password_confirmation) {
73+
user.password_confirmation = user.password;
74+
}
75+
return $http.post('/users.json', { user: user }).then(function (response) {
76+
service.currentUser = response.data;
77+
redirect(opts.redirect);
78+
});
79+
},
80+
requestCurrentUser: function () {
81+
if (service.isAuthenticated()) {
82+
return $q.when(service.currentUser);
83+
}
84+
return service.login();
85+
},
86+
isAuthenticated: function () {
87+
return !!service.currentUser;
88+
}
89+
};
90+
return service;
91+
}
92+
]);
93+
}(angular));

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "AngularDevise",
3+
"version": "0.0.1",
4+
"description": "A small AngularJS Service to interact with Devise Authentication.",
5+
"main": "lib/devise.js",
6+
"scripts": {
7+
"test": "grunt test"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/cloudspace/angular_devise.git"
12+
},
13+
"keywords": [
14+
"Angular",
15+
"AngularJS",
16+
"Devise"
17+
],
18+
"author": "Justin Ridgewell",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/cloudspace/angular_devise/issues"
22+
},
23+
"dependencies": {},
24+
"devDependencies": {
25+
"grunt": "~0.4.1",
26+
"grunt-ngmin": "~0.0.2",
27+
"grunt-plato": "~0.2.1",
28+
"grunt-preprocess": "~2.3.0",
29+
"grunt-contrib-jshint": "~0.6.2",
30+
"grunt-contrib-uglify": "~0.2.2",
31+
"grunt-karma": "~0.6.2",
32+
"load-grunt-tasks": "~0.2.0",
33+
"time-grunt": "~0.2.1"
34+
}
35+
}

0 commit comments

Comments
 (0)