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 +4 -4
- data/README.md +32 -4
- data/lib/hanami/authentication.rb +1 -0
- data/lib/hanami/authentication/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd3070e629eced5a93c261e5fd540d9e79ffb08
|
4
|
+
data.tar.gz: aed73bc00b44b5a4bb5850a6c5196818295a0e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
24
|
-
|
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
|
-
|
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
|
-
|
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
|
|