hanami-authentication 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b10f080ce3f404155ac3587c85b888ad678a21a
4
- data.tar.gz: 43441401575e80b96f300cead6fe346fe63d17c2
3
+ metadata.gz: 9bd3070e629eced5a93c261e5fd540d9e79ffb08
4
+ data.tar.gz: aed73bc00b44b5a4bb5850a6c5196818295a0e9c
5
5
  SHA512:
6
- metadata.gz: 183dcd04ce198d45cc797252f1a18971bd6fcebbb7d4f18ee2b03dd313ff217072612c100a44d703f63d0a7b4d6258717ab260a3d53bbd9de29b9eef1825ec2f
7
- data.tar.gz: b87f623a4b60bec0727850cd3a5be0b818939086c42f2e6de59bb7ecbdfb41d1fff7d9c954e5c023796837b566cf414e8b4c890e43b58bc65201fd7a24399766
6
+ metadata.gz: 67e0f8d355cbfca31744b0b8c45c7d964016d07c3d0bc7ab59ca5952dc413106468adcfca279fbe71aaffca7d9285e146729ad48dfd352f11fe566a3b8f354a2
7
+ data.tar.gz: 218e572f9a9ac0d5f15ef1787670c936ff8fd4967fc0390c5e29f39909f13a7f2196b1eb1f823a0bbe701c83cf2ca21f1d5b08e1dfd6c67c132a80a3441eaed3
data/README.md CHANGED
@@ -20,15 +20,16 @@ gem 'hanami-authentication'
20
20
  # application.rb
21
21
  controller.prepare do
22
22
  include Hanami::Authentication
23
- # before authenticate >> This will use callbacks if authentication is failed.
24
- # before authenticate! >> This forced to halt by 401 if authentication is failed.
23
+
24
+ before authenticate # This will use callbacks if authentication is failed.
25
+ before authenticate! # This will force to halt by 401 if authentication is failed.
25
26
 
26
27
  after_session_expired do # This will be called if authenticate method is called when session is expired.
27
28
  flash[:error] = 'The session is expired.'
28
29
  redirect_to routes.root_path
29
30
  end
30
31
 
31
- after_session_failed do # This will be called if authenticate method is called when user has not logged in.
32
+ after_authentication_failed do # This will be called if authenticate method is called when user has not logged in.
32
33
  flash[:error] = 'Please login'
33
34
  redirect_to routes.root_path
34
35
  end
@@ -38,7 +39,34 @@ end
38
39
 
39
40
  ### Methods
40
41
 
41
- TBD
42
+ #### Login example
43
+ ```ruby
44
+ # in_your_login_action.rb
45
+ def call(params)
46
+ email = params[:email]
47
+ password = params[:password]
48
+ remember_me = params[:remember_me]
49
+
50
+ @current_user = @repository.find_by_email(email)
51
+
52
+ if match_password?(@current_user, password)
53
+ login(@current_user, remember_me: remember_me)
54
+ flash[:success] = 'Successful logged in'
55
+ redirect_to routes.root_path
56
+ else
57
+ flash[:error] = 'Email or password is incorrect'
58
+ redirect_to routes.root_path
59
+ end
60
+ end
61
+ ```
62
+
63
+ #### Logout example
64
+ ```ruby
65
+ # in_your_login_action.rb
66
+ def call(params)
67
+ logout
68
+ end
69
+ ```
42
70
 
43
71
  ## Contributing
44
72
 
@@ -56,6 +56,7 @@ module Hanami
56
56
 
57
57
  def self.included(base)
58
58
  base.class_eval do
59
+ _expose :current_user
59
60
  extend ClassMethods
60
61
  end
61
62
  end
@@ -1,5 +1,5 @@
1
1
  module Hanami
2
2
  module Authentication
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LegalForce Inc.