ember-auth-rails 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ember-auth-rails
2
+
3
+ `ember-auth` provides token authentication support to
4
+ [ember.js](http://emberjs.com/).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'ember-auth-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install ember-auth-rails
19
+
20
+ ## Usage
21
+
22
+ See [README](https://github.com/heartsentwined/ember-auth) at the main
23
+ `ember-auth` site.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,137 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+
4
+ window.Auth = Em.Object.create({
5
+ authToken: null,
6
+ currentUserId: null,
7
+ error: null,
8
+ prevRoute: null,
9
+ signIn: function(data) {
10
+ var _this = this;
11
+ if (data == null) {
12
+ data = {};
13
+ }
14
+ return this.ajax(Auth.Config.get('tokenCreateUrl'), 'POST', {
15
+ data: data,
16
+ success: function(json) {
17
+ _this.set('authToken', json[Auth.Config.get('tokenKey')]);
18
+ return _this.set('currentUserId', json[Auth.Config.get('idKey')]);
19
+ },
20
+ error: function(json) {
21
+ return _this.set('error', json);
22
+ },
23
+ complete: function() {
24
+ return _this.set('prevRoute', null);
25
+ }
26
+ });
27
+ },
28
+ signOut: function(data) {
29
+ var _this = this;
30
+ if (data == null) {
31
+ data = {};
32
+ }
33
+ data[Auth.Config.get('tokenKey')] = this.get('authToken');
34
+ return this.ajax(Auth.Config.get('tokenDestroyUrl'), 'DELETE', {
35
+ data: data,
36
+ success: function(json) {
37
+ _this.set('authToken', null);
38
+ return _this.set('currentUserId', null);
39
+ },
40
+ error: function(json) {
41
+ return _this.set('error', json);
42
+ },
43
+ complete: function() {
44
+ return _this.set('prevRoute', null);
45
+ }
46
+ });
47
+ },
48
+ resolveRedirectRoute: function(type) {
49
+ var fallback, isSmart, sameRoute, typeClassCase;
50
+ if (type !== 'signIn' && type !== 'signOut') {
51
+ return null;
52
+ }
53
+ typeClassCase = "" + (type[0].toUpperCase()) + (type.slice(1));
54
+ isSmart = Auth.Config.get("smart" + typeClassCase + "Redirect");
55
+ fallback = Auth.Config.get("" + type + "RedirectFallbackRoute");
56
+ sameRoute = Auth.Config.get("" + type + "Route");
57
+ if (!isSmart) {
58
+ return fallback;
59
+ }
60
+ if (!(this.prevRoute != null) || this.prevRoute === sameRoute) {
61
+ return fallback;
62
+ } else {
63
+ return this.prevRoute;
64
+ }
65
+ },
66
+ ajax: function(url, type, hash) {
67
+ hash.url = url;
68
+ hash.type = type;
69
+ hash.dataType = 'json';
70
+ hash.contentType = 'application/json; charset=utf-8';
71
+ if (hash.data && type !== 'GET') {
72
+ hash.data = JSON.stringify(hash.data);
73
+ }
74
+ return jQuery.ajax(hash);
75
+ }
76
+ });
77
+
78
+ Auth.Config = Em.Object.create({
79
+ tokenCreateUrl: null,
80
+ tokenDestroyUrl: null,
81
+ tokenKey: null,
82
+ idKey: null,
83
+ signInRoute: null,
84
+ signOutRoute: null,
85
+ authRedirect: false,
86
+ smartSignInRedirect: false,
87
+ smartSignOutRedirect: false,
88
+ signInRedirectFallbackRoute: 'index',
89
+ signOutRedirectFallbackRoute: 'index'
90
+ });
91
+
92
+ Auth.Route = Em.Route.extend({
93
+ redirect: function() {
94
+ if (Auth.Config.get('authRedirect') && !Auth.get('authToken')) {
95
+ Auth.set('prevRoute', this.routeName);
96
+ return this.transitionTo(Auth.Config.get('signInRoute'));
97
+ }
98
+ }
99
+ });
100
+
101
+ Auth.SignInController = Em.ObjectController.extend({
102
+ registerRedirect: function() {
103
+ return Auth.addObserver('authToken', this, 'smartSignInRedirect');
104
+ },
105
+ smartSignInRedirect: function() {
106
+ if (Auth.get('authToken')) {
107
+ this.get('target.router').transitionTo(Auth.resolveRedirectRoute('signIn'));
108
+ return Auth.removeObserver('authToken', this, 'smartSignInRedirect');
109
+ }
110
+ }
111
+ });
112
+
113
+ Auth.SignOutController = Em.ObjectController.extend({
114
+ registerRedirect: function() {
115
+ return Auth.addObserver('authToken', this, 'smartSignOutRedirect');
116
+ },
117
+ smartSignOutRedirect: function() {
118
+ if (!Auth.get('authToken')) {
119
+ this.get('target.router').transitionTo(Auth.resolveRedirectRoute('signOut'));
120
+ return Auth.removeObserver('authToken', this, 'smartSignOutRedirect');
121
+ }
122
+ }
123
+ });
124
+
125
+ Auth.RESTAdapter = DS.RESTAdapter.extend({
126
+ ajax: function(url, type, hash) {
127
+ var token;
128
+ if (token = Auth.get('authToken')) {
129
+ hash.data || (hash.data = {});
130
+ hash.data[Auth.Config.get('tokenKey')] = Auth.get('authToken');
131
+ }
132
+ hash.context = this;
133
+ return Auth.ajax(url, type, hash);
134
+ }
135
+ });
136
+
137
+ }).call(this);
@@ -0,0 +1 @@
1
+ //= require ./ember-auth
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ember-auth/rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ember-auth-rails"
8
+ gem.version = EmberAuth::Rails::VERSION
9
+ gem.authors = ["heartsentwined"]
10
+ gem.email = ["heartsentwined@cogito-lab.com"]
11
+ gem.summary = 'Ember-auth for Rails'
12
+ gem.description = <<-EOS
13
+ Ember-auth provides token authentication support to ember.js.
14
+ It is expected to work out of the box with rails + devise.
15
+ EOS
16
+ gem.homepage = 'https://github.com/heartsentwined/ember-auth-rails'
17
+
18
+ gem.add_dependency 'ember-rails', ['~> 0.9']
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
+
25
+ gem.license = 'GPL-3'
26
+ end
@@ -0,0 +1,7 @@
1
+ require "ember-auth/rails/version"
2
+
3
+ module EmberAuth
4
+ module Rails
5
+ require 'ember-auth/rails/engine'
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module EmberAuth
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module EmberAuth
2
+ module Rails
3
+ VERSION = '1.0.2'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module EmberAuth
2
+ VERSION = '1.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ember-auth-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - heartsentwined
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ember-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ description: ! " Ember-auth provides token authentication support to ember.js.\n
31
+ \ It is expected to work out of the box with rails + devise.\n"
32
+ email:
33
+ - heartsentwined@cogito-lab.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.md
41
+ - Rakefile
42
+ - app/assets/javascripts/ember-auth/ember-auth.js
43
+ - app/assets/javascripts/ember-auth/index.js
44
+ - ember-auth-rails.gemspec
45
+ - lib/ember-auth-rails.rb
46
+ - lib/ember-auth/rails/engine.rb
47
+ - lib/ember-auth/rails/version.rb
48
+ - lib/ember-auth/version.rb
49
+ homepage: https://github.com/heartsentwined/ember-auth-rails
50
+ licenses:
51
+ - GPL-3
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.24
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Ember-auth for Rails
74
+ test_files: []