breath 0.1.1 → 0.1.3

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: 50ebd07a8e36d441f618c760f7a5a24fa18d9ac94ddb4a6bdc900cfdb3e359ca
4
- data.tar.gz: d260c09a3bee03dc94022e6b579b344c26cc297ccede0dfd858ab12952d67690
3
+ metadata.gz: 1cf89b5445e113d7198d4a9a9aa4ddfc1af8a09c0faec9eb4af344ad151b2af1
4
+ data.tar.gz: 3efb2e128154bc6e7c0ecbfad3997d338f15d871f7c898d3ab943d53e7aecd91
5
5
  SHA512:
6
- metadata.gz: 4714402fea80ecc8cb5f3d1a1462ef7f28a36d8c6b3abea415aca82b71ae460f5537f931441dd80d3c67064313c63c0ab564f069050011d129f39a2ec91e4561
7
- data.tar.gz: 24ff2a754e289c97a9953a29f42b88a311e886b80c2f97a7c5a879bb3939c981c2ad432c75d77255b851a11503ac4e9b72b7edb3fef67a8ee3ae7119ecb5021d
6
+ metadata.gz: 1e267a0b8ec0aee65ad28e47d3c3e58daceddb9f37e019c6ea548e61906af86d413ab266c64b35a444c3bac4876c67cb27578a737984d79b8e9161dfdbc9f4d8
7
+ data.tar.gz: 1b2d1fbbb58ac30cd6e7a3dd3283ba33f807724cf962e96f1cbc1b0c228bb7fcda18854ee27a368173616fc5bb46b373ab0162e3f3e401ee4e31c32c7ff88efc
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Breath
2
- Short description and motivation.
3
-
4
- ## Usage
5
- How to use my plugin.
2
+ Rails authentication plugin with API mode.<br />
3
+ Easy introducing login, logout.<br/>
4
+ Compact features set.
6
5
 
7
6
  ## Installation
8
7
  Add this line to your application's Gemfile:
@@ -21,6 +20,101 @@ Or install it yourself as:
21
20
  $ gem install breath
22
21
  ```
23
22
 
23
+ ## Usage
24
+ ### Introduce
25
+
26
+ #### Model
27
+ If you want to introduce a authentication to `User` model.<br/>
28
+ Add these lines to `user.rb` like bellow.
29
+ ```ruby
30
+ class User < ApplicationRecord
31
+ include Breath::Model
32
+
33
+ attr_breath :email
34
+ end
35
+ ```
36
+ Here, with `attr_breath`, you need to specify the user's attribute with authentication.
37
+
38
+ #### Migration
39
+ In migration file, you need to add `password_digest`, and `remember_digest` attributes.<br/>
40
+ And if you specify the email attribute within `attr_breath`, you need to add `email` attribute in migration file.
41
+ ```ruby
42
+ class CreateUsers < ActiveRecord::Migration[7.0]
43
+ def change
44
+ create_table :users do |t|
45
+ t.string :email
46
+ t.string :password_digest
47
+ t.string :remember_digest
48
+
49
+ t.timestamps
50
+ end
51
+ end
52
+ end
53
+ ```
54
+ After these lines you added, excute `bundle exec rails db:migrate`.
55
+
56
+
57
+ #### Controller
58
+ You need to construct the directory like bellow.
59
+ ```
60
+ /app/controllers
61
+ - application_controller.rb
62
+
63
+ /users
64
+ - application_controller.rb
65
+ - sessions_controller.rb
66
+ ```
67
+
68
+ - app/contorllers/users/application_controller.rb
69
+ ```ruby
70
+ class Users::ApplicationController < ApplicationController
71
+ include Breath::ApplicationControllerHelper
72
+ before_action :authenticate!
73
+
74
+ crsf_protect true
75
+ end
76
+ ```
77
+ Here, if `csrf_protect` is `true`, CSRF protection is enabled.<br/>
78
+
79
+ - app/controllers/users/sessions_controller.rb
80
+ ```ruby
81
+ class Users::SessionsController < Users::ApplicationController
82
+ include Breath::SessionsControllerHelper
83
+ end
84
+ ```
85
+
86
+ `Breath::ApplicationControllerHelper` intoroduce the user's authorization.<br/>
87
+ `Breath::SessionsControllerHelper` introduce the actions `login`, and `logout`.
88
+
89
+ After you added these lines, show `bundle exec rails routes` command.<br/>
90
+ You can see these routes are added.
91
+ ```
92
+ GET /users/login
93
+ POST /users/login
94
+ DELETE /users/logout
95
+ ```
96
+
97
+ Then, you don't need write the codes to introduce authorizations.
98
+
99
+ #### Config
100
+ This plugin need cookie, and you can configure the cookie expires like bellow.<br/>
101
+ ```ruby
102
+ module YourApp
103
+ class Application < Rails::Application
104
+ ...
105
+
106
+ config.breath_expires = 3.days
107
+ end
108
+ end
109
+ ```
110
+ If you don't configure this, cookie is set permanently.
111
+
112
+ #### Last Work
113
+ You need to create view side.<br/>
114
+ In view side, you have remaining works.<br/>
115
+ if you `csrf_protect true`, you need to introduce `withCredentials: true` option in client side.<br/>
116
+ And, write csrf token into the cookie with `csrf_token` key.
117
+
24
118
  ## Contributing
25
119
  Contribution directions go here.
26
120
 
@@ -7,14 +7,14 @@ module Breath
7
7
  included do
8
8
  target_class = to_s.split("::")[-2].singularize.constantize
9
9
  target_name = target_class.to_s.underscore
10
- current_target_name = "current_#{target_name}"
10
+ current_target = "current_#{target_name}"
11
11
 
12
12
  include ActionController::Cookies
13
13
 
14
14
  define_method :authenticate! do
15
15
  raise AuthenticationError unless cookies.key?("#{target_name}_id".to_sym)
16
- raise AuthenticationError if send(current_target_name).nil?
17
- raise AuthenticationError unless send(current_target_name).remember?(cookies[:remember_token])
16
+ raise AuthenticationError if send(current_target).nil?
17
+ raise AuthenticationError unless send(current_target).remember?(cookies[:remember_token])
18
18
 
19
19
  target = target_class.enabled.find_by(id: cookies.signed["#{target_name}_id".to_sym])
20
20
 
@@ -44,7 +44,7 @@ module Breath
44
44
  end
45
45
 
46
46
  define_method :sessions_params do
47
- params.require(:sessions).permit(target_class.auth_attribute.to_sym, :password, :password_confirmation)
47
+ params.require(:sessions).permit(target_class.auth_attribute.to_sym, :password)
48
48
  end
49
49
  end
50
50
 
@@ -1,3 +1,3 @@
1
1
  module Breath
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01