agilib 0.1.0.beta4 → 0.1.0.beta5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/app/controllers/agilib/tokens_controller.rb +9 -3
- data/lib/.DS_Store +0 -0
- data/lib/agilib/cli.rb +0 -5
- data/lib/agilib/token_authentication/token_authentication.rb +6 -2
- data/lib/agilib/token_authentication/token_authentication_handler.rb +11 -7
- data/lib/agilib/version.rb +1 -1
- data/lib/agilib.rb +18 -5
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/agilib/.DS_Store +0 -0
- data/lib/generators/agilib/install/.DS_Store +0 -0
- data/lib/generators/agilib/install/install_generator.rb +2 -36
- data/lib/generators/agilib/install/templates/.DS_Store +0 -0
- data/lib/generators/agilib/install/templates/config/initializers/agilib.rb +36 -0
- data/spec/agilib-rails_spec.rb +3 -3
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43499d4ac4dab407c6d6825a7e4bee1584214f07
|
4
|
+
data.tar.gz: 9893937af149ad71099c978830280a7514cafd3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 834822470987ba90c8f4d86f72b762ea4ae335da6df9798f6e21669a0482719d335f61e9d2be27a1fccedff2c004e27992ee338f6b4e7d818dc93fe75049999d
|
7
|
+
data.tar.gz: 01eb285f0b0f73dd1db809097e3e37986d15b33027eae7eb815c1006587f1ba1d9a9773fab282b670807aee89ba2f31b35978877bb5d8251ab37a415e0eaad9a
|
data/.DS_Store
CHANGED
Binary file
|
@@ -4,8 +4,8 @@ module Agilib
|
|
4
4
|
respond_to :json
|
5
5
|
|
6
6
|
def create
|
7
|
-
login = params[:
|
8
|
-
password = params[:password]
|
7
|
+
login = params[Agilib.token_login_params[:login]]
|
8
|
+
password = params[Agilib.token_login_params[:password]]
|
9
9
|
|
10
10
|
if request.format != :json
|
11
11
|
render :status=>406, :json => { :message => "The request must be json" }
|
@@ -40,7 +40,13 @@ module Agilib
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def destroy
|
43
|
-
|
43
|
+
|
44
|
+
if User.respond_to? "find_by"
|
45
|
+
@user = User.find_by(authentication_token: login.downcase)
|
46
|
+
elsif User.respond_to? "find_by_authentication_token"
|
47
|
+
@user = User.find_by_authentication_token(login.downcase)
|
48
|
+
end
|
49
|
+
|
44
50
|
if @user.nil?
|
45
51
|
render :status=>404, :json=>{:message=>"Invalid token."}
|
46
52
|
else
|
data/lib/.DS_Store
CHANGED
Binary file
|
data/lib/agilib/cli.rb
CHANGED
@@ -10,11 +10,6 @@ module Agilib
|
|
10
10
|
opts.banner = "Usage:\n agilib [options] <location>"
|
11
11
|
opts.separator "\nOptions: "
|
12
12
|
|
13
|
-
opts.on("-l <language>", "--language <language>",
|
14
|
-
"Language of output (see API docs for valid choices)") do |language|
|
15
|
-
# Agilib.configure(:language => language)
|
16
|
-
end
|
17
|
-
|
18
13
|
opts.on_tail("-v", "--version", "Print version number") do
|
19
14
|
require "agilib/version"
|
20
15
|
out << "Agilib #{Agilib::VERSION}\n"
|
@@ -24,8 +24,12 @@ module Agilib
|
|
24
24
|
|
25
25
|
module ClassMethods
|
26
26
|
def agilib_token_authenticatable(options = {})
|
27
|
-
|
28
|
-
|
27
|
+
unless Agilib.use_token_authentication
|
28
|
+
puts "Para usar a autenticacao por token, precisa ativar na configuracao: use_token_authentication = true"
|
29
|
+
else
|
30
|
+
include Agilib::TokenAuthenticatable
|
31
|
+
before_save :ensure_authentication_token
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -19,14 +19,14 @@ module Agilib
|
|
19
19
|
def authenticate_user_from_token!
|
20
20
|
# Set the authentication token params if not already present,
|
21
21
|
# see http://stackoverflow.com/questions/11017348/rails-api-authentication-by-headers-token
|
22
|
-
if user_token = params[:user_token].blank? && request.headers["X-User-Token"]
|
23
|
-
params[:user_token] = user_token
|
22
|
+
if user_token = params[Agilib.token_authentication_params[:user_token]].blank? && request.headers["X-User-Token"]
|
23
|
+
params[Agilib.token_authentication_params[:user_token]] = user_token
|
24
24
|
end
|
25
|
-
if user_email = params[:user_email].blank? && request.headers["X-User-Email"]
|
26
|
-
params[:user_email] = user_email
|
25
|
+
if user_email = params[Agilib.token_authentication_params[:user_email]].blank? && request.headers["X-User-Email"]
|
26
|
+
params[Agilib.token_authentication_params[:user_email]] = user_email
|
27
27
|
end
|
28
28
|
|
29
|
-
user_email = params[:user_email].presence
|
29
|
+
user_email = params[Agilib.token_authentication_params[:user_email]].presence
|
30
30
|
# See https://github.com/ryanb/cancan/blob/1.6.10/lib/cancan/controller_resource.rb#L108-L111
|
31
31
|
if User.respond_to? "find_by"
|
32
32
|
user = user_email && User.find_by(email: user_email)
|
@@ -37,7 +37,7 @@ module Agilib
|
|
37
37
|
# Notice how we use Devise.secure_compare to compare the token
|
38
38
|
# in the database with the token given in the params, mitigating
|
39
39
|
# timing attacks.
|
40
|
-
if user && Devise.secure_compare(user.authentication_token, params[:user_token])
|
40
|
+
if user && Devise.secure_compare(user.authentication_token, params[Agilib.token_authentication_params[:user_token]])
|
41
41
|
# Notice we are passing store false, so the user is not
|
42
42
|
# actually stored in the session and a token is needed
|
43
43
|
# for every request. If you want the token to work as a
|
@@ -60,7 +60,11 @@ module Agilib
|
|
60
60
|
|
61
61
|
module ClassMethods
|
62
62
|
def agilib_token_authentication_handler(options = {})
|
63
|
-
include Agilib::TokenAuthenticationHandlerMethods
|
63
|
+
include Agilib::TokenAuthenticationHandlerMethods if Agilib.use_token_authentication
|
64
|
+
|
65
|
+
unless Agilib.use_token_authentication
|
66
|
+
puts "Para usar a autenticacao por token, precisa ativar na configuracao: use_token_authentication = true"
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/agilib/version.rb
CHANGED
data/lib/agilib.rb
CHANGED
@@ -1,19 +1,32 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
require 'set'
|
4
|
+
require 'securerandom'
|
2
5
|
|
3
6
|
module Agilib
|
4
7
|
|
8
|
+
|
9
|
+
# set to use token authentication
|
10
|
+
mattr_accessor :use_token_authentication
|
11
|
+
@@use_token_authentication = true
|
12
|
+
def self.use_token_authentication=(use)
|
13
|
+
@@use_token_authentication = use
|
14
|
+
end
|
15
|
+
|
16
|
+
mattr_accessor :token_authentication_params
|
17
|
+
@@token_authentication_params = {:user_token => :user_token, :user_email => :user_email}
|
18
|
+
|
19
|
+
mattr_accessor :token_login_params
|
20
|
+
@@token_login_params = {:login => :login, :password => :password}
|
21
|
+
|
5
22
|
def self.rails4?
|
6
23
|
::Rails::VERSION::STRING.split(".")[0].to_i > 3
|
7
24
|
end
|
8
25
|
|
9
|
-
def self.say
|
10
|
-
"hello"
|
11
|
-
end
|
12
|
-
|
13
26
|
def self.setup
|
14
27
|
yield self
|
15
28
|
end
|
16
|
-
|
29
|
+
|
17
30
|
end
|
18
31
|
|
19
32
|
require 'agilib/version'
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,45 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# encoding: utf-8
|
3
2
|
module Agilib
|
4
3
|
module Generators
|
5
4
|
class InstallGenerator < ::Rails::Generators::Base
|
6
5
|
desc "Instalação da Agilib"
|
7
6
|
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
class_option :template_engine, :desc => 'Template engine to be invoked (erb, haml or slim).'
|
9
|
-
class_option :bootstrap, :type => :boolean, :desc => 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
|
10
|
-
class_option :foundation, :type => :boolean, :desc => 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
|
11
|
-
|
12
|
-
def info_bootstrap
|
13
|
-
return if options.bootstrap? || options.foundation?
|
14
|
-
puts "SimpleForm 2 supports Twitter Bootstrap and Zurb Foundation 3. If you want "\
|
15
|
-
"a configuration that is compatible with one of these frameworks, then please " \
|
16
|
-
"re-run this generator with --bootstrap or --foundation as an option."
|
17
|
-
end
|
18
|
-
|
19
7
|
def copy_config
|
20
|
-
|
21
|
-
|
22
|
-
# if options[:bootstrap]
|
23
|
-
# template "config/initializers/simple_form_bootstrap.rb"
|
24
|
-
# elsif options[:foundation]
|
25
|
-
# template "config/initializers/simple_form_foundation.rb"
|
26
|
-
# end
|
27
|
-
|
28
|
-
# directory 'config/locales'
|
29
|
-
puts "copy_config"
|
30
|
-
end
|
31
|
-
|
32
|
-
def copy_scaffold_template
|
33
|
-
# engine = options[:template_engine]
|
34
|
-
# copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
35
|
-
puts "copy_scaffold_template"
|
36
|
-
end
|
37
|
-
|
38
|
-
def show_readme
|
39
|
-
# if behavior == :invoke && options.bootstrap?
|
40
|
-
# readme "README"
|
41
|
-
# end
|
42
|
-
puts "show_readme"
|
8
|
+
template "config/initializers/agilib.rb"
|
43
9
|
end
|
44
10
|
end
|
45
11
|
end
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Agilib.setup do |config|
|
2
|
+
|
3
|
+
|
4
|
+
# Define se a aplicação vai usar autenticação por token
|
5
|
+
# Caso esteja habilitado, será preciso criar uma rota dentro do scope do devise, direcionando para
|
6
|
+
# o controller da Agilib
|
7
|
+
#
|
8
|
+
# Exemplo:
|
9
|
+
#
|
10
|
+
# config/routes.rb
|
11
|
+
#
|
12
|
+
# devise_scope :user do
|
13
|
+
# post "tokens" => "agilib/tokens#create"
|
14
|
+
# delete "tokens/:token" => "agilib/tokens#destroy"
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Este procedimento é necessário para que a rota /tokens.json esteja disponível
|
18
|
+
config.use_token_authentication = true
|
19
|
+
|
20
|
+
# Define quais parâmetros serão passados para solicitar o token
|
21
|
+
#
|
22
|
+
# Exemplo:
|
23
|
+
#
|
24
|
+
# /tokens.json?email=agivis@agivis.com.br&password=12345
|
25
|
+
#
|
26
|
+
config.token_login_params = {:login => :email, :password => :password}
|
27
|
+
|
28
|
+
# Define em quais parâmetros serão passados o token e o email do usuário
|
29
|
+
#
|
30
|
+
# Exemplo:
|
31
|
+
#
|
32
|
+
# /posts.json?user_token=AhAuHEAUheAU&user_email=agivis@agivis.com.br
|
33
|
+
#
|
34
|
+
config.token_authentication_params = {:user_token => :user_token, :user_email => :user_email}
|
35
|
+
|
36
|
+
end
|
data/spec/agilib-rails_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe "AgilibRails" do
|
|
5
5
|
# fail "hey buddy, you should probably rename this file and start specing for real"
|
6
6
|
# end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it "test agilib" do
|
9
|
+
Agilib.use_token_authentication = true
|
10
|
+
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agilib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Junior
|
@@ -138,7 +138,12 @@ files:
|
|
138
138
|
- lib/agilib/token_authentication/token_authentication.rb
|
139
139
|
- lib/agilib/token_authentication/token_authentication_handler.rb
|
140
140
|
- lib/agilib/version.rb
|
141
|
+
- lib/generators/.DS_Store
|
142
|
+
- lib/generators/agilib/.DS_Store
|
143
|
+
- lib/generators/agilib/install/.DS_Store
|
141
144
|
- lib/generators/agilib/install/install_generator.rb
|
145
|
+
- lib/generators/agilib/install/templates/.DS_Store
|
146
|
+
- lib/generators/agilib/install/templates/config/initializers/agilib.rb
|
142
147
|
- spec/agilib-rails_spec.rb
|
143
148
|
- spec/spec_helper.rb
|
144
149
|
homepage: http://github.com/marcosgugs/agilib
|