metova 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzkwM2Y4ZGZmZWVmZmJhM2U2N2E0NjM5YWQyZGIyMWJlNWM3YWYzMw==
4
+ OGQzZjc2YWI3OGY2MzEwNzA1ZWJlNjUyYjUyNjg4ZmIxNDdmM2I3MA==
5
5
  data.tar.gz: !binary |-
6
- MWNiZGU1MjQ2NjA5YjQxYmZkNjI0MThiZGM5ZDBhY2M5OWQwMDVkOA==
6
+ YmE1OWI2Mzk3YjVlYWQyNmExZWFkOWNmMGI4MjI0MTQwMWY3OTAzNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTExMjAzOTcyM2NlNDE2Mzc2YzA0Y2I5MzAyOGU5ZmE4Mzg2ZWQxNmRlODBj
10
- NjlkYzhiNTJjNjUxMmFjMjEzOGVkZWU1YTY1MDY0ZTMxMTQwMjBhZWM2NGVh
11
- ZjlkODQ0YjFjNTdhOGI3YjcwNGFjNzEzYzA1YzIwZmVkNmM0NGY=
9
+ MjlhODdlZTMwOWVjMDc1MDdjOGQxMjhhZTkzZjYyNzA1ZTdlYWNkYWM1NWVj
10
+ ZDQ1ZDNlYWFlNjk2OGZiZjkyNjZhYTM1MWJlMWI1MmMxOWNkYTM4ODEyOGFh
11
+ OGVlYTEyOTlhMDA0MGJiMGIxNTc0NGQ1NGVkNTRiOGY3MWFkMmY=
12
12
  data.tar.gz: !binary |-
13
- YzZlYWUwY2ViMTgzYTgyNGYyMjY3ZWFlYTVmYzNiOTkwNGM2ZDVkNGU0ZGYy
14
- MzBjM2MxMDE5ODJiMGVjZjQzNjIwMTgxN2U2MWU1YjM4NzEyYTNkMjZlZWQz
15
- NGU4NWI0ZGNiZWFjMDVhYTMzYzU5MWJlMzllNTVhZTE4ZGZjYmQ=
13
+ YjlhZmQ3YjQxZTk0MTlmNzUxODUxODc0Y2U1MDRmMjQzM2I0NGUxODNjZWFh
14
+ OThiOGYwNWU2ODUyYTY3ZWEzZTdkNmZjZjAzNjVlNDhkMjRlMDczZTNhOWM0
15
+ OWM2ZDVjYTYxOTQzMjgzMmQ1MzQ4Y2ZmYmZhMTY1MjI1ODA1ZjY=
@@ -0,0 +1,18 @@
1
+ module Metova
2
+ module Devise
3
+ module Controller
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ respond_to :json
8
+ before_action :accept_user_param_root!
9
+ self.responder = Metova::Responder
10
+ end
11
+
12
+ def accept_user_param_root!
13
+ params[:api_user] = params[:user] if params[:user] && !params[:api_user]
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ require 'devise'
2
+
3
+ module Devise
4
+ module Models
5
+ module TokenAuthenticatable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_save :ensure_authentication_token!
10
+ end
11
+
12
+ def self.required_fields(klass)
13
+ [:authentication_token]
14
+ end
15
+
16
+ def reset_authentication_token
17
+ self.authentication_token = loop do
18
+ token = SecureRandom.hex(20)
19
+ break token unless self.class.exists?(authentication_token: token)
20
+ end
21
+ end
22
+
23
+ def reset_authentication_token!
24
+ reset_authentication_token
25
+ save validate: false
26
+ end
27
+
28
+ def ensure_authentication_token!
29
+ reset_authentication_token! if authentication_token.blank?
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ require 'devise'
2
+
3
+ module Devise
4
+ module Strategies
5
+ class TokenAuthenticatable < Base
6
+
7
+ def authenticate!
8
+ user = mapping.to.find_by(email: options[:email])
9
+ if user && valid_token?(user)
10
+ success! user
11
+ else
12
+ fail! 'Invalid authentication token'
13
+ end
14
+ end
15
+
16
+ def valid?
17
+ token.present? && options.include?(:email)
18
+ end
19
+
20
+ private
21
+
22
+ def valid_token?(user)
23
+ Devise.secure_compare user.authentication_token, token
24
+ end
25
+
26
+ def token
27
+ @_token ||= token_and_options[0]
28
+ end
29
+
30
+ def options
31
+ @_options ||= token_and_options[1]
32
+ end
33
+
34
+ def token_and_options
35
+ @_token_and_options ||= ActionController::HttpAuthentication::Token.token_and_options(request)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
data/lib/metova/engine.rb CHANGED
@@ -3,6 +3,7 @@ module Metova
3
3
  isolate_namespace Metova
4
4
 
5
5
  require 'kaminari'
6
+ require 'devise'
6
7
  require 'responders'
7
8
 
8
9
  end
@@ -0,0 +1,14 @@
1
+ module Metova
2
+ class Error
3
+ include ActiveModel::Model
4
+
5
+ def initialize(message)
6
+ @message = message
7
+ end
8
+
9
+ def errors
10
+ [@message]
11
+ end
12
+
13
+ end
14
+ end
@@ -10,7 +10,7 @@ module Metova
10
10
  def to_format
11
11
  validate!
12
12
  if errors.any?
13
- display({ errors: errors })
13
+ display({ errors: errors }, status: 400)
14
14
  else
15
15
  super
16
16
  end
@@ -19,6 +19,10 @@ module Metova
19
19
  def validate!
20
20
  end
21
21
 
22
+ def json_resource_errors
23
+ { errors: resource.errors.full_messages }
24
+ end
25
+
22
26
  private
23
27
 
24
28
  def errors
@@ -1,3 +1,3 @@
1
1
  module Metova
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/metova.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'metova/engine'
2
+ require 'metova/error'
2
3
 
3
4
  require 'metova/responders/pagination_responder'
4
5
  require 'metova/responders/ids_filter_responder'
@@ -10,5 +11,9 @@ require 'metova/versioning/router_dsl'
10
11
  require 'metova/versioning/constraints'
11
12
  require 'metova/versioning/railtie'
12
13
 
14
+ require 'metova/devise/controller'
15
+ require 'metova/devise/strategies/token_authenticatable'
16
+ require 'metova/devise/models/token_authenticatable'
17
+
13
18
  module Metova
14
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metova
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Serman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0.rc3
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0.rc3
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: kaminari
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +126,11 @@ files:
126
126
  - lib/metova.rb
127
127
  - lib/metova/carrierwave.rb
128
128
  - lib/metova/carrierwave/railtie.rb
129
+ - lib/metova/devise/controller.rb
130
+ - lib/metova/devise/models/token_authenticatable.rb
131
+ - lib/metova/devise/strategies/token_authenticatable.rb
129
132
  - lib/metova/engine.rb
133
+ - lib/metova/error.rb
130
134
  - lib/metova/mandrill.rb
131
135
  - lib/metova/mandrill/railtie.rb
132
136
  - lib/metova/responder.rb
@@ -139,7 +143,7 @@ files:
139
143
  - lib/metova/versioning/router_dsl.rb
140
144
  - lib/metova/versioning/unsupported_version_app.rb
141
145
  - lib/tasks/metova_tasks.rake
142
- homepage: http://github.com/metova/metova
146
+ homepage: http://github.com/metova/metova-rails
143
147
  licenses:
144
148
  - MIT
145
149
  metadata: {}