cow_auth 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64a895f28d740efa94c2a8b5684cd97997d4d17cf50376b9859b869ed16b2a07
4
- data.tar.gz: 52cba6f14267edb2b7c8e764421a1ec53aef72e96650bbf104be2de2119804f4
3
+ metadata.gz: 0e246db4f5e60c64425fc46be892629169f5562b488995b9dae8baa5af7f0f4d
4
+ data.tar.gz: 9b80ec381be2ede4d05a5efbdc5e37b90a7f99237e6a8c7faf2dbbde1ccc1df9
5
5
  SHA512:
6
- metadata.gz: 9d23c75c2a71d0e4d1e574f86a2e8adc70e3b018674852b18452475eed477387c6b56f07a3e9aed59b64475eb9e21e3667ce863be852320adc71526de1315c04
7
- data.tar.gz: ad348254f5901b73ddd9a5a5ae79aa49305e55ee65cf019ab293f0338245fe1c65ed3bea8acdde0e5b6ce26a328aa64da4dd7c11f69458d90d6b128f93579f9c
6
+ metadata.gz: cc1ff51a2a5e8ce550391c0345d0616ee2be9cf8ee67483727a66c6ccbf8475955d1e99050e8d25d3235f5422a3156f95f03fb01c52c5ca989bb34efb3b3a7af
7
+ data.tar.gz: b35e88869eecfed877e8d29b68015bd2b9b6e42336fa814c27b7ac7bf2984ac2ef43817aec0e62d2193cf10408f697e1c3861ac10299f426b726a290dc272bc4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cow_auth (0.6.0)
4
+ cow_auth (0.6.1)
5
5
  activesupport (~> 5.1)
6
6
  scrypt (~> 3.0)
7
7
 
@@ -0,0 +1,21 @@
1
+ require 'cow_auth/exceptions'
2
+
3
+ module CowAuth
4
+ module SessionAuth
5
+ module AuthenticateRequest
6
+ extend ActiveSupport::Concern
7
+
8
+ private
9
+
10
+ def authenticate_user
11
+ @current_user = authentication_class.find_by(sid: session[:current_user])
12
+ raise CowAuth::NotAuthenticatedError.new('User not authenticated.') if @current_user.blank?
13
+ return true
14
+ end
15
+
16
+ def current_user
17
+ return @current_user
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'cow_auth/exceptions'
2
+
3
+ module CowAuth
4
+ module SessionAuth
5
+ module SessionEndpoints
6
+ extend ActiveSupport::Concern
7
+
8
+ def new
9
+ end
10
+
11
+ def create
12
+ user = authentication_class.find_by(email: params[:email])
13
+ if user.try(:authenticate_with_password, params[:password])
14
+ session[:current_user] = user.sid
15
+ redirect_to sign_in_success_path
16
+ else
17
+ session[:current_user] = nil
18
+ raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ if @current_user.present?
24
+ session[:current_user] = nil
25
+ redirect_to sign_out_success_path
26
+ else
27
+ raise CowAuth::StandardError.new('Could not sign user out.')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -8,7 +8,7 @@ module CowAuth
8
8
  def create
9
9
  user = authentication_class.find_by(email: params[:email])
10
10
  if user.try(:authenticate_with_password, params[:password])
11
- user.api_sign_in
11
+ user.create_auth_token
12
12
  render json: { sid: user.sid, auth_token: user.auth_token }, status: :ok
13
13
  else
14
14
  raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
@@ -16,7 +16,7 @@ module CowAuth
16
16
  end
17
17
 
18
18
  def destroy
19
- if @current_user.try(:api_sign_out)
19
+ if @current_user.try(:destroy_auth_token)
20
20
  head :no_content
21
21
  else
22
22
  raise CowAuth::NotAuthenticatedError.new('Could not sign user out.')
data/lib/cow_auth/user.rb CHANGED
@@ -34,7 +34,7 @@ module CowAuth
34
34
  return false
35
35
  end
36
36
 
37
- def api_sign_in
37
+ def create_auth_token
38
38
  self.update(
39
39
  auth_token: self.token_valid? ? self.auth_token : self.generate_auth_token,
40
40
  expires_at: self.generate_token_expires_at
@@ -42,7 +42,7 @@ module CowAuth
42
42
  return true
43
43
  end
44
44
 
45
- def api_sign_out
45
+ def destroy_auth_token
46
46
  self.update(
47
47
  auth_token: nil,
48
48
  expires_at: nil
@@ -1,3 +1,3 @@
1
1
  module CowAuth
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
data/lib/cow_auth.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'cow_auth/version'
2
2
  require 'cow_auth/user'
3
3
  require 'cow_auth/exceptions'
4
+ require 'cow_auth/session_auth/session_endpoints'
5
+ require 'cow_auth/session_auth/authenticate_request'
4
6
  require 'cow_auth/token_auth/session_endpoints'
5
7
  require 'cow_auth/token_auth/authenticate_request'
6
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cow_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickey Cowden
@@ -101,6 +101,8 @@ files:
101
101
  - cow_auth.gemspec
102
102
  - lib/cow_auth.rb
103
103
  - lib/cow_auth/exceptions.rb
104
+ - lib/cow_auth/session_auth/authenticate_request.rb
105
+ - lib/cow_auth/session_auth/session_endpoints.rb
104
106
  - lib/cow_auth/token_auth/authenticate_request.rb
105
107
  - lib/cow_auth/token_auth/session_endpoints.rb
106
108
  - lib/cow_auth/user.rb