lockie 0.2.3 → 0.2.4

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: 22b01ff539d6b9fe6b8fb0fcd73e6b8bc105ca61a0648f8a16c89849d053fc51
4
- data.tar.gz: 7599b02b2baa3bd11fb5c7047472103d45b81c175dfe718c04d419013f535b7a
3
+ metadata.gz: 9952a555d5390e0d3afa8a26bddab8aa1107d761d31db543ab52c09b344ce1ba
4
+ data.tar.gz: ac4384cb0a1dee463cabff6e334e9eb9ea3266c2bfecfd6ea90430a7fb4af8fc
5
5
  SHA512:
6
- metadata.gz: 489f49143709e699aa79b8c97af3936740b7b7806dfe46fdc5239a01d6dd2174344fc44a3e2813321593e15257e9ab23595e97e970c7a894de83207433042b18
7
- data.tar.gz: 182b318346dea189a9b1798bc788cb7714d820ffe901a314cb406c4b2dc809cadff978262267175917132cfebd84bf73e7c0819dba154cf83bb3c21daee50bbc
6
+ metadata.gz: fca45221ce6b5b2303a7cb9d0884f2298c11214aecc99c16b8fe418105f180fca094136e46edd33c4c940e4e062b037af3f608c607e9845fdde66cf1c6957f33
7
+ data.tar.gz: 833cc9dbffc754cf7fb0a0fb40c437a2a9dc81996289ffa1388855972a81882559f5386530cfe675608dcea34574ff4104b06f437f069bf8a7afff1f12cf8752
data/README.md CHANGED
@@ -41,9 +41,8 @@ Session controller
41
41
  class SessionController < ApplicationController
42
42
  skip_before_action :authenticate!, only: [:new]
43
43
 
44
- def create
45
- # on successful login redirect to your user's page
46
- redirect_to root_url
44
+ def create
45
+ redirect_to root_url # redirect to your homepage if username and password is valid
47
46
  end
48
47
 
49
48
  def destroy
@@ -64,12 +63,27 @@ get 'logout' => 'session#destroy'
64
63
  session/new.html.erb view:
65
64
  ```ruby
66
65
  <%= form_tag(login_url) do -%>
67
- <%= email_field_tag 'email' %>
68
- <%= password_field_tag 'password' %>
69
- <%= submit_tag "Login" %>
66
+ <%= email_field_tag 'email' %>
67
+ <%= password_field_tag 'password' %>
68
+ <%= submit_tag "Login" %>
70
69
  <% end -%>
71
70
  ```
72
71
 
72
+ ## Configuration
73
+
74
+ config/initializers/lockie.rb
75
+ ```ruby
76
+ Lockie.configure do |c|
77
+ c.jwt_secret = ENV.fetch("JWT_SECRET") { "i-am-jwt-secret" }
78
+ c.model_name = "Account" # default to 'User'
79
+ c.unauthenticated_path = "/some/login/path" # default to '/login'
80
+ c.hash_algorithm = "HS512" # default to 'HS256'
81
+
82
+ # add custom warden strategy, default strategies and priority are [:email_password, :jwt]
83
+ c.default_strategies = [:auth0, :jwt]
84
+ end
85
+ ```
86
+
73
87
  ## Contributing
74
88
  Contribution directions go here.
75
89
 
data/lib/lockie.rb CHANGED
@@ -17,12 +17,14 @@ module Lockie
17
17
  attr_accessor :default_strategies
18
18
  attr_accessor :jwt_secret
19
19
  attr_accessor :hash_algorithm
20
+ attr_accessor :serialize_session
20
21
 
21
22
  def initialize
22
23
  @model_name = "User"
23
24
  @unauthenticated_path = "/login"
24
25
  @default_strategies = [:email_password, :jwt]
25
26
  @hash_algorithm = "HS256"
27
+ @serialize_session = true
26
28
  end
27
29
  end
28
30
 
@@ -33,11 +33,14 @@ module Lockie
33
33
  def html_response
34
34
  flash[type] = message if message
35
35
  self.status = 302
36
- redirect_to Lockie.config.unauthenticated_path
36
+ callback_url = request.base_url + request.original_fullpath
37
+ uri = URI(Lockie.config.unauthenticated_path)
38
+ uri.query = (uri.query.to_s.split("&") << "callback_url=#{ callback_url }").join("&")
39
+ redirect_to uri.to_s
37
40
  end
38
41
 
39
42
  def message
40
- @message ||= request.env['warden.message']
43
+ @message ||= request.env['warden.message'] || "Unauthorized"
41
44
  end
42
45
 
43
46
  def warden_options
data/lib/lockie/rails.rb CHANGED
@@ -7,11 +7,16 @@ module Lockie
7
7
  manager.default_strategies Lockie.config.default_strategies
8
8
  manager.failure_app = Lockie::FailureApp
9
9
 
10
- manager.serialize_into_session(&:id)
11
- manager.serialize_from_session do |id|
12
- Lockie.config.model_name.classify.constantize.find(id)
13
- end
10
+ if Lockie.config.serialize_session
11
+ manager.serialize_into_session(&:email)
12
+ manager.serialize_from_session do |email|
13
+ Lockie.config.model_name.classify.constantize.find_by_email(email)
14
+ end
15
+ end
14
16
 
15
17
  end
16
18
  end
17
19
  end
20
+
21
+ Warden::Manager.after_set_user do |record, warden, options|
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Lockie
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvin Sembrano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails