devise_code_authenticatable 0.0.7 → 0.1.0

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
  SHA256:
3
- metadata.gz: 1d59c09da1f30b55c31bebdefc644bface2a0368967e34d42359e148259f3516
4
- data.tar.gz: fbae74bca964a26b673a51ed3093ad9bcc729fec3d439c8ca0d537b7da9454ab
3
+ metadata.gz: d5b5e44ba5833b455ffd654e935463a2596ae87326875e727c2d883f9983c272
4
+ data.tar.gz: 7ef83bb888e39e7fce3cb8aa3bc0d9a54000d75fc2449c7c11f2463fe086030c
5
5
  SHA512:
6
- metadata.gz: 79ee709e8042b39336ca4ec6f3bf8aa25850aad59ffd915686348d4e7256fca027988ab5cda806e81f8f2ba4cffa4cc36c643e2e75da7f90fb1e1c623fbff8a3
7
- data.tar.gz: f65055c2bbb8c1ce2a15bb64313ea93886c16cdcd1183185fccca731347b4644fc8c80b385677f2dddfd5ab05ebf2dd1800b35b1cf3fa7b781fb7c78fc5a7ad8
6
+ metadata.gz: 84c616b0a1ddc8722c7d6c102a6259ec6a598974d7f0cf2588ba58f032dee866e92e2de266b668f23e96e3be1615bb1c4570960a59d3a9a0b244dde4e13b4216
7
+ data.tar.gz: e3f720d265c3ee899a712b649115b619c0f66b0e3e680c7838ebbdf83d9ba636f5ca454bbfd388f00013c4657606e08a3336179b398c09522b4a129ea796c6a5
data/README.md CHANGED
@@ -1,28 +1,47 @@
1
1
  # DeviseCodeAuthenticatable
2
- Short description and motivation.
2
+ A Devise plugin for two-factor authenticatable.
3
3
 
4
- ## Usage
5
- How to use my plugin.
4
+ ## Demo
5
+ An example rails app to use this plugin is setup in [demo](https://github.com/vincentying15/demo_for_devise_code_authenticatable)
6
6
 
7
7
  ## Installation
8
- Add this line to your application's Gemfile:
8
+ Add this line to your Rails Gemfile:
9
9
 
10
10
  ```ruby
11
11
  gem 'devise_code_authenticatable'
12
12
  ```
13
13
 
14
- And then execute:
14
+ ### Automatic installation
15
+ Run:
16
+
15
17
  ```bash
16
- $ bundle
18
+ rails generate devise_code_authenticatable:install
19
+ ```
20
+
21
+ This will create a migration file name in your <tt>db/migrate</tt> folder, then
22
+
23
+
24
+ ```ruby
25
+ rails db:migrate
17
26
  ```
27
+ ### Devise Configuration
28
+ Add <tt>:authenticatable</tt> to the model you want to enable code_authenticatable
29
+
30
+ ```ruby
31
+ class User < ActiveRecord::Base
32
+ devise :database_authenticatable, :confirmable, :code_authenticatable
33
+ end
34
+ ```
35
+ ## Usage
36
+ ### Customize views
37
+ This plugin is included with basic views, to customize the views you need to run
18
38
 
19
- Or install it yourself as:
20
39
  ```bash
21
- $ gem install devise_code_authenticatable
40
+ rails generate devise_code_authenticatable:views
22
41
  ```
23
42
 
24
- ## Contributing
25
- Contribution directions go here.
43
+ ### Login by password
44
+ The existing <tt>Devise::SessionsController</tt> would be override, so you can not login by your password
26
45
 
27
46
  ## License
28
47
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module DeviseCodeAuthenticatable
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,32 @@
1
+ require "rails/generators"
2
+ require "rails/generators/active_record"
3
+
4
+ module DeviseCodeAuthenticatable
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include ::Rails::Generators::Migration
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def copy_locale
12
+ copy_file '../../../../config/locales/en.yml', 'config/locales/devise_code_authenticatable.en.yml'
13
+ end
14
+
15
+ def copy_devise_migration
16
+ migration_template 'migration.rb', "db/migrate/create_login_codes.rb", migration_version: migration_version
17
+ end
18
+
19
+ def migration_version
20
+ major = ActiveRecord::VERSION::MAJOR
21
+ if major >= 6
22
+ "[#{major}.#{ActiveRecord::VERSION::MINOR}]"
23
+ end
24
+ end
25
+
26
+ def self.next_migration_number(dirname)
27
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ class CreateLoginCodes < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :login_codes do |t|
4
+ t.string :code
5
+ t.integer :retry_times
6
+ t.boolean :expired
7
+ t.references :resource, polymorphic: true, index: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ <h2><%= t(".sign_in") %></h2>
2
+ <%= simple_form_for resource, url: verify_user_login_code_path(@login_code) do |f| %>
3
+ <%= f.input :email, placeholder: "email" %>
4
+ <%= f.input :login_code, placeholder: "code" %>
5
+ <%= f.submit t(".sign_in") %>
6
+ <% end %>
7
+ <%= link_to t(".resend_code"), resend_user_login_code_path(@login_code) %>
@@ -0,0 +1,5 @@
1
+ <h2><%= t(".sign_in") %></h2>
2
+ <%= form_for resource, url: new_session_path(resource_name) do |f| %>
3
+ <%= f.input :email, placeholder: "email" %>
4
+ <%= f.submit t(".send_code") %>
5
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_code_authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vincentying15
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -60,6 +60,10 @@ files:
60
60
  - lib/devise_code_authenticatable/routes.rb
61
61
  - lib/devise_code_authenticatable/strategies/code_authenticatable.rb
62
62
  - lib/devise_code_authenticatable/version.rb
63
+ - lib/generators/devise_code_authenticatable/install_generator.rb
64
+ - lib/generators/devise_code_authenticatable/templates/migration.rb
65
+ - lib/generators/devise_code_authenticatable/templates/simple_form_for/login_codes/show.html.erb
66
+ - lib/generators/devise_code_authenticatable/templates/simple_form_for/sessions/new.html.erb
63
67
  homepage: https://rubygems.org/gems/devise_code_authenticatable
64
68
  licenses:
65
69
  - MIT