lockie 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -6
- data/lib/lockie/controller_helper.rb +2 -2
- data/lib/lockie/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5611c39c34639b730d1e727ac9d19d9606e54a34a289f3dedf863a83d71175c5
|
4
|
+
data.tar.gz: f25907b964058f449210ace1e8b1d91cc7ea35f7b0972fc2ffb358c004aa7c58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08027dfcd40444551b9a561634dc9f192facea3d496d5a144b6c62840c45e781d56fba32f213d14eb99ffbbba7d1c7aef43ae96529c8032a4faa7360027ab679'
|
7
|
+
data.tar.gz: 2007a0a5ecb0c78f732db3c9875dd0419c5e18242b2431e265d9cf9e3be8f45cd3f40a9e1c563c5c4be264102f0809bdc771d32ab49b187ea0c025e5e11b2e65
|
data/README.md
CHANGED
@@ -2,10 +2,8 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/lockie.svg)](https://badge.fury.io/rb/lockie)
|
3
3
|
|
4
4
|
# Lockie
|
5
|
-
|
5
|
+
A drop-in, none assuming warden based Password and JWT authentication for Rails 5.2++
|
6
6
|
|
7
|
-
## Usage
|
8
|
-
How to use my plugin.
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
Add this line to your application's Gemfile:
|
@@ -19,9 +17,57 @@ And then execute:
|
|
19
17
|
$ bundle
|
20
18
|
```
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
## Usage
|
21
|
+
Add the following lines to your authenticaiton model e.g. `User`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
has_secure_password
|
25
|
+
include Lockie::ModelHelper
|
26
|
+
```
|
27
|
+
|
28
|
+
Add the following lines to your base controller e.g. `ApplicationController`:
|
29
|
+
```ruby
|
30
|
+
include Lockie::ControllerHelper
|
31
|
+
before_action :authenticate!
|
32
|
+
```
|
33
|
+
That's it! All your controllers that inherits `ApplicationController` are now protected.
|
34
|
+
|
35
|
+
|
36
|
+
## Adding a session controller
|
37
|
+
Creating a session controller is simple as:
|
38
|
+
|
39
|
+
Session controller
|
40
|
+
```ruby
|
41
|
+
class SessionController < ApplicationController
|
42
|
+
skip_before_action :authenticate!, only: [:new]
|
43
|
+
|
44
|
+
def create
|
45
|
+
# on successful login redirect to your user's page
|
46
|
+
redirect_to root_url
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
logout
|
51
|
+
redirect_to login_url
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
routes.rb
|
58
|
+
```ruby
|
59
|
+
get 'login' => 'session#new'
|
60
|
+
post 'login' => 'session#create'
|
61
|
+
get 'logout' => 'session#destroy'
|
62
|
+
```
|
63
|
+
|
64
|
+
session/new.html.erb view:
|
65
|
+
```ruby
|
66
|
+
<%= form_tag(login_url) do -%>
|
67
|
+
<%= email_field_tag 'email' %>
|
68
|
+
<%= password_field_tag 'password' %>
|
69
|
+
<%= submit_tag "Login" %>
|
70
|
+
<% end -%>
|
25
71
|
```
|
26
72
|
|
27
73
|
## Contributing
|
@@ -4,7 +4,7 @@ module Lockie
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
if respond_to?(:helper_method)
|
7
|
-
helper_method
|
7
|
+
helper_method "current_#{ Lockie.config.model_name.underscore }".to_sym
|
8
8
|
helper_method :logged_in?
|
9
9
|
helper_method :authenticated?
|
10
10
|
end
|
@@ -14,7 +14,7 @@ module Lockie
|
|
14
14
|
env['warden']
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
define_method "current_#{ Lockie.config.model_name.underscore }".to_sym do |*args|
|
18
18
|
warden.user(*args)
|
19
19
|
end
|
20
20
|
|
data/lib/lockie/version.rb
CHANGED