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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cow_auth/session_auth/authenticate_request.rb +21 -0
- data/lib/cow_auth/session_auth/session_endpoints.rb +32 -0
- data/lib/cow_auth/token_auth/session_endpoints.rb +2 -2
- data/lib/cow_auth/user.rb +2 -2
- data/lib/cow_auth/version.rb +1 -1
- data/lib/cow_auth.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e246db4f5e60c64425fc46be892629169f5562b488995b9dae8baa5af7f0f4d
|
4
|
+
data.tar.gz: 9b80ec381be2ede4d05a5efbdc5e37b90a7f99237e6a8c7faf2dbbde1ccc1df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1ff51a2a5e8ce550391c0345d0616ee2be9cf8ee67483727a66c6ccbf8475955d1e99050e8d25d3235f5422a3156f95f03fb01c52c5ca989bb34efb3b3a7af
|
7
|
+
data.tar.gz: b35e88869eecfed877e8d29b68015bd2b9b6e42336fa814c27b7ac7bf2984ac2ef43817aec0e62d2193cf10408f697e1c3861ac10299f426b726a290dc272bc4
|
data/Gemfile.lock
CHANGED
@@ -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.
|
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(:
|
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
|
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
|
45
|
+
def destroy_auth_token
|
46
46
|
self.update(
|
47
47
|
auth_token: nil,
|
48
48
|
expires_at: nil
|
data/lib/cow_auth/version.rb
CHANGED
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.
|
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
|