devise-otp 0.8.0 → 1.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 +4 -4
- data/.github/workflows/ci.yml +14 -3
- data/.gitignore +3 -3
- data/Appraisals +22 -0
- data/CHANGELOG.md +34 -1
- data/Gemfile +3 -1
- data/README.md +22 -7
- data/Rakefile +0 -11
- data/app/assets/stylesheets/devise-otp.css +4 -0
- data/app/controllers/devise_otp/devise/otp_credentials_controller.rb +4 -6
- data/app/controllers/devise_otp/devise/otp_tokens_controller.rb +1 -2
- data/config/locales/en.yml +0 -2
- data/devise-otp.gemspec +9 -5
- data/gemfiles/rails_7.1.gemfile +21 -0
- data/gemfiles/rails_7.2.gemfile +17 -0
- data/gemfiles/rails_8.0.gemfile +17 -0
- data/lib/devise-otp/version.rb +1 -1
- data/lib/devise_otp_authenticatable/controllers/helpers.rb +5 -28
- data/lib/devise_otp_authenticatable/hooks/refreshable.rb +3 -1
- data/test/dummy/app/assets/javascripts/application.js +0 -1
- data/test/dummy/app/assets/stylesheets/application.css +1 -0
- data/test/dummy/app/controllers/admin_posts_controller.rb +0 -72
- data/test/dummy/app/controllers/non_otp_posts_controller.rb +13 -0
- data/test/dummy/app/controllers/posts_controller.rb +8 -2
- data/test/dummy/app/models/admin.rb +1 -13
- data/test/dummy/app/models/non_otp_user.rb +4 -0
- data/test/dummy/app/models/post.rb +1 -1
- data/test/dummy/app/models/user.rb +1 -13
- data/test/dummy/app/views/admin_posts/index.html.erb +0 -7
- data/test/dummy/app/views/layouts/application.html.erb +7 -1
- data/test/dummy/app/views/non_otp_posts/index.html.erb +18 -0
- data/test/dummy/config/application.rb +0 -7
- data/test/dummy/config/database.yml +20 -13
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/migrate/20240604000001_create_admins.rb +1 -1
- data/test/dummy/db/migrate/20250718092451_create_non_otp_users.rb +9 -0
- data/test/dummy/db/migrate/20250718092536_add_devise_to_non_otp_users.rb +52 -0
- data/test/dummy/db/schema.rb +118 -0
- data/test/dummy/db/seeds.rb +24 -0
- data/test/integration/disable_token_test.rb +3 -0
- data/test/integration/enable_otp_form_test.rb +17 -0
- data/test/integration/non_otp_user_models_test.rb +21 -0
- data/test/integration/persistence_test.rb +3 -0
- data/test/integration/refresh_test.rb +9 -0
- data/test/integration/reset_token_test.rb +3 -0
- data/test/integration/sign_in_test.rb +30 -0
- data/test/integration_tests_helper.rb +11 -0
- data/test/test_helper.rb +0 -5
- metadata +39 -23
- data/app/assets/javascripts/devise-otp.js +0 -1
- data/app/assets/javascripts/qrcode.js +0 -609
- data/docs/QR_CODES.md +0 -9
- data/test/dummy/app/views/admin_posts/_form.html.erb +0 -25
- data/test/dummy/app/views/admin_posts/edit.html.erb +0 -6
- data/test/dummy/app/views/admin_posts/new.html.erb +0 -5
- data/test/dummy/app/views/admin_posts/show.html.erb +0 -15
- data/test/orm/active_record.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f329ff1fa9732961646ad4169f89921f3429a6aa86744486eafa21a891fd1628
|
4
|
+
data.tar.gz: 8a4797664986ea6c11e21a50a43d5aeda471000ce5610e91451ec37f3d231121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e42b34ea4259e698e75f6408b6d0a0021b39f934d960e039a305ee2f9dc7d443a8dbdc9f99e1df452b75602430e601bf7ece1214b11766ba558fb3806d07355c
|
7
|
+
data.tar.gz: 8c1bde0740a5f96dfc440e976c568a8ef0b7f0ac91e7af620d14aea1e8208811e6339384dc9d7b6363c6f4ed9de363c1637422a82b5f5f5c6696fa17c9879764
|
data/.github/workflows/ci.yml
CHANGED
@@ -12,10 +12,20 @@ jobs:
|
|
12
12
|
fail-fast: false
|
13
13
|
matrix:
|
14
14
|
ruby:
|
15
|
+
- '3.4'
|
15
16
|
- '3.3'
|
16
17
|
- '3.2'
|
17
|
-
- '3.1'
|
18
18
|
- 'head'
|
19
|
+
rails:
|
20
|
+
- rails_8.0
|
21
|
+
- rails_7.2
|
22
|
+
- rails_7.1
|
23
|
+
exclude:
|
24
|
+
- ruby: '3.1'
|
25
|
+
rails: 'rails_8.0'
|
26
|
+
|
27
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
28
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}.gemfile
|
19
29
|
|
20
30
|
steps:
|
21
31
|
- name: Checkout
|
@@ -27,7 +37,8 @@ jobs:
|
|
27
37
|
ruby-version: ${{ matrix.ruby }}
|
28
38
|
bundler-cache: true
|
29
39
|
|
40
|
+
- name: Create database
|
41
|
+
run: cd test/dummy && RAILS_ENV=test bundle exec rails db:create db:migrate --trace
|
42
|
+
|
30
43
|
- name: Run tests
|
31
|
-
env:
|
32
|
-
DEVISE_ORM: active_record
|
33
44
|
run: bundle exec rake test
|
data/.gitignore
CHANGED
@@ -34,11 +34,11 @@ lib/bundler/man
|
|
34
34
|
## PROJECT::SPECIFIC
|
35
35
|
test/dummy/log/**
|
36
36
|
test/dummy/tmp/**
|
37
|
-
test/dummy/
|
38
|
-
test/dummy/db/*.sqlite3-shm
|
39
|
-
test/dummy/db/*.sqlite3-wal
|
37
|
+
test/dummy/storage/**
|
40
38
|
|
39
|
+
# Ignore Gemfile.lock
|
41
40
|
Gemfile.lock
|
41
|
+
gemfiles/*.lock
|
42
42
|
|
43
43
|
# Generated test files
|
44
44
|
tmp/*
|
data/Appraisals
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'rails_7.1' do
|
4
|
+
gem 'rails', '~> 7.1.0'
|
5
|
+
gem 'sqlite3', '~> 1.5.0'
|
6
|
+
|
7
|
+
# Fix:
|
8
|
+
# warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0.
|
9
|
+
# Add logger to your Gemfile or gemspec.
|
10
|
+
install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do
|
11
|
+
gem 'logger'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise 'rails_7.2' do
|
16
|
+
gem 'rails', '~> 7.2.0'
|
17
|
+
gem 'sqlite3', '~> 1.5.0'
|
18
|
+
end
|
19
|
+
|
20
|
+
appraise 'rails_8.0' do
|
21
|
+
gem 'rails', '~> 8.0.0'
|
22
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,40 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
-
|
5
|
+
## 1.1.0
|
6
|
+
|
7
|
+
Bug fixes:
|
8
|
+
- Update refreshable hook to ensure that user models without Devise OTP can still sign in
|
9
|
+
- Add tests for non-OTP user models to confirm resolution
|
10
|
+
|
11
|
+
Improvements:
|
12
|
+
- Remove references to MongoDB from test suite
|
13
|
+
- Standardize test application's database configuration
|
14
|
+
- Add Development Instructions to README
|
15
|
+
|
16
|
+
## 1.0.1
|
17
|
+
- Add support for Ruby 3.4
|
18
|
+
- Set minimum Ruby version to 3.2
|
19
|
+
- Set miminum Rails version to 7.1
|
20
|
+
- Add MIT license type to gemspec
|
21
|
+
- Correct Devise spelling error in README
|
22
|
+
|
23
|
+
## 1.0.0
|
24
|
+
- Add support for Rails 8
|
25
|
+
- Generate QR Codes as SVG
|
26
|
+
- Fix Issue with Invalid Token Message
|
27
|
+
- Simplify OTP Credentials Controller
|
28
|
+
- Expand Flash Message Tests
|
29
|
+
- Use Appraisal gem to against older Rails versions
|
30
|
+
|
31
|
+
## 0.8.0
|
32
|
+
- Add support for Rails 7.2 and drop support for Rails 6.1
|
33
|
+
- Fix issue with scoped redirects for non-default resources
|
34
|
+
- Add migration version numbers
|
35
|
+
- Cleanup old docs
|
36
|
+
|
37
|
+
## 0.7.1
|
38
|
+
- Fix host and port for 3rd-party tests
|
6
39
|
|
7
40
|
## 0.7.0
|
8
41
|
|
data/Gemfile
CHANGED
@@ -3,6 +3,8 @@ source "https://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in devise-otp.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git"
|
7
|
+
|
6
8
|
gem "capybara"
|
7
9
|
gem "minitest-reporters", ">= 0.5.0"
|
8
10
|
gem "puma"
|
@@ -10,5 +12,5 @@ gem "rake"
|
|
10
12
|
gem "rdoc"
|
11
13
|
gem "shoulda"
|
12
14
|
gem "sprockets-rails"
|
13
|
-
gem "sqlite3", "~> 1
|
15
|
+
gem "sqlite3", "~> 2.1"
|
14
16
|
gem "standardrb"
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Some of the compatible token devices are:
|
|
13
13
|
* [Google Authenticator](https://code.google.com/p/google-authenticator/)
|
14
14
|
* [FreeOTP](https://fedorahosted.org/freeotp/)
|
15
15
|
|
16
|
-
|
16
|
+
Devise OTP was recently updated to work with Rails 7+ and Turbo.
|
17
17
|
|
18
18
|
## Sponsor
|
19
19
|
|
@@ -58,10 +58,13 @@ Don't forget to migrate:
|
|
58
58
|
|
59
59
|
rake db:migrate
|
60
60
|
|
61
|
-
|
61
|
+
### Default CSS
|
62
62
|
|
63
|
-
|
63
|
+
To use the default CSS for devise-otp, just require the devise-otp.css file as usual in your application.css file (or equivalent):
|
64
64
|
|
65
|
+
*= require devise-otp
|
66
|
+
|
67
|
+
It might be even easier to just copy the styles to your project.
|
65
68
|
|
66
69
|
### Custom views
|
67
70
|
|
@@ -77,9 +80,7 @@ The install generator also installs an english copy of a Devise OTP i18n file. T
|
|
77
80
|
|
78
81
|
### QR codes
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
If you need something more, have a look at [QR codes](/docs/QR_CODES.md) documentation file.
|
83
|
+
Devise OTP generates QR Codes directly as SVG's via the [rqrcode](https://github.com/whomwah/rqrcode), so there are no JavaScript (or Sprockets) dependencies.
|
83
84
|
|
84
85
|
## Configuration
|
85
86
|
|
@@ -100,9 +101,23 @@ Enforcing mandatory OTP requires adding the ensure\_mandatory\_{scope}\_otp! met
|
|
100
101
|
before_action :authenticate_user!
|
101
102
|
before_action :ensure_mandatory_user_otp!
|
102
103
|
|
104
|
+
## Development Instructions
|
105
|
+
WARNING: Make sure to use the latest Ruby/Rails versions for development. If using older versions of Ruby/Rails, you will need to install all gems for all versions via Appraisal ("bundle exec appraisal install").
|
106
|
+
|
107
|
+
To run the devise-otp dummy application in the development environment:
|
108
|
+
- Navigate to the dummy app directory ("cd test/dummy")
|
109
|
+
- Create and seed the database ("rails db:reset")
|
110
|
+
- Run the rails console or server (e.g. "rails c")
|
111
|
+
|
112
|
+
To run the tests for devise-otp against your current Ruby/Rails configuration:
|
113
|
+
- Navigate to the dummy app directory ("cd test/dummy")
|
114
|
+
- Create and migrate the database for the test environment ("RAILS\_ENV=test rails db:drop db:create db:migrate")
|
115
|
+
- Return to the root directory of devise-otp
|
116
|
+
- Run "rake test"
|
117
|
+
|
103
118
|
## Authors
|
104
119
|
|
105
|
-
The project was originally started by Lele Forzani by forking [devise_google_authenticator](https://github.com/AsteriskLabs/devise_google_authenticator) and still contains some devise_google_authenticator code. It's now maintained by [Josef Strzibny](https://github.com/strzibny/).
|
120
|
+
The project was originally started by Lele Forzani by forking [devise_google_authenticator](https://github.com/AsteriskLabs/devise_google_authenticator) and still contains some devise_google_authenticator code. It's now maintained by [Josef Strzibny](https://github.com/strzibny/) and [Laney Stroup](https://github.com/strouptl).
|
106
121
|
|
107
122
|
Contributions are welcome!
|
108
123
|
|
data/Rakefile
CHANGED
@@ -28,14 +28,3 @@ Rake::TestTask.new(:test) do |test|
|
|
28
28
|
test.pattern = "test/**/*_test.rb"
|
29
29
|
test.verbose = true
|
30
30
|
end
|
31
|
-
|
32
|
-
desc "Run Devise tests for all ORMs."
|
33
|
-
task :tests do
|
34
|
-
Dir[File.join(File.dirname(__FILE__), "test", "orm", "*.rb")].each do |file|
|
35
|
-
orm = File.basename(file).split(".").first
|
36
|
-
system "rake test DEVISE_ORM=#{orm}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "Default: run tests for all ORMs."
|
41
|
-
task default: :tests
|
@@ -26,17 +26,15 @@ module DeviseOtp
|
|
26
26
|
# signs the resource in, if the OTP token is valid and the user has a valid challenge
|
27
27
|
#
|
28
28
|
def update
|
29
|
-
if @token
|
30
|
-
otp_set_flash_message(:alert, :token_blank)
|
31
|
-
redirect_to otp_credential_path_for(resource_name, challenge: @challenge, recovery: @recovery)
|
32
|
-
elsif resource.otp_challenge_valid? && resource.validate_otp_token(@token, @recovery)
|
29
|
+
if resource.otp_challenge_valid? && resource.validate_otp_token(@token, @recovery)
|
33
30
|
sign_in(resource_name, resource)
|
34
31
|
|
35
32
|
otp_set_trusted_device_for(resource) if params[:enable_persistence] == "true"
|
36
33
|
otp_refresh_credentials_for(resource)
|
37
34
|
respond_with resource, location: after_sign_in_path_for(resource)
|
38
35
|
else
|
39
|
-
|
36
|
+
kind = (@token.blank? ? :token_blank : :token_invalid)
|
37
|
+
otp_set_flash_message :alert, kind, :now => true
|
40
38
|
render :show
|
41
39
|
end
|
42
40
|
end
|
@@ -103,7 +101,7 @@ module DeviseOtp
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def failed_refresh
|
106
|
-
otp_set_flash_message :alert, :invalid_refresh
|
104
|
+
otp_set_flash_message :alert, :invalid_refresh, :now => true
|
107
105
|
render :refresh
|
108
106
|
end
|
109
107
|
|
@@ -35,7 +35,7 @@ module DeviseOtp
|
|
35
35
|
otp_set_flash_message :success, :successfully_updated
|
36
36
|
redirect_to otp_token_path_for(resource)
|
37
37
|
else
|
38
|
-
otp_set_flash_message :danger, :could_not_confirm
|
38
|
+
otp_set_flash_message :danger, :could_not_confirm, :now => true
|
39
39
|
render :edit
|
40
40
|
end
|
41
41
|
end
|
@@ -109,7 +109,6 @@ module DeviseOtp
|
|
109
109
|
ensure_resource!
|
110
110
|
|
111
111
|
if needs_credentials_refresh?(resource)
|
112
|
-
otp_set_flash_message :notice, :need_to_refresh_credentials
|
113
112
|
redirect_to refresh_otp_credential_path_for(resource)
|
114
113
|
end
|
115
114
|
end
|
data/config/locales/en.yml
CHANGED
@@ -14,7 +14,6 @@ en:
|
|
14
14
|
otp_session_invalid: Session invalid. Please start again.
|
15
15
|
token_invalid: 'The token you provided was invalid.'
|
16
16
|
token_blank: 'You need to type in the token you generated with your device.'
|
17
|
-
need_to_refresh_credentials: 'We need to check your credentials before you can change these settings.'
|
18
17
|
valid_refresh: 'Thank you, your credentials were accepted.'
|
19
18
|
invalid_refresh: 'Sorry, you provided the wrong credentials.'
|
20
19
|
credentials_refresh:
|
@@ -41,7 +40,6 @@ en:
|
|
41
40
|
successfully_set_persistence: 'Your device is now trusted.'
|
42
41
|
successfully_cleared_persistence: 'Your device has been removed from the list of trusted devices.'
|
43
42
|
successfully_reset_persistence: 'Your list of trusted devices has been cleared.'
|
44
|
-
need_to_refresh_credentials: 'We need to check your credentials before you can change these settings.'
|
45
43
|
recovery:
|
46
44
|
title: 'Your Emergency Recovery Codes'
|
47
45
|
explain: 'Take note or print these recovery codes. The will allow you to log back in in case your token device is lost, stolen, or unavailable.'
|
data/devise-otp.gemspec
CHANGED
@@ -5,16 +5,20 @@ require_relative "lib/devise-otp/version"
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "devise-otp"
|
7
7
|
gem.version = Devise::OTP::VERSION
|
8
|
-
gem.authors = ["Lele Forzani", "Josef Strzibny"]
|
9
|
-
gem.email = ["lele@windmill.it", "strzibny@strzibny.name"]
|
10
|
-
gem.description = "
|
8
|
+
gem.authors = ["Lele Forzani", "Josef Strzibny", "Laney Stroup"]
|
9
|
+
gem.email = ["lele@windmill.it", "strzibny@strzibny.name", "laney@stroupsolutions.com"]
|
10
|
+
gem.description = "OTP authentication for Devise"
|
11
11
|
gem.summary = "Time Based OTP/rfc6238 compatible authentication for Devise"
|
12
|
-
gem.homepage = "
|
12
|
+
gem.homepage = "https://github.com/wmlele/devise-otp"
|
13
|
+
gem.license = "MIT"
|
13
14
|
|
14
15
|
gem.files = `git ls-files`.split($/)
|
15
16
|
gem.require_paths = ["lib"]
|
16
17
|
|
17
|
-
gem.
|
18
|
+
gem.required_ruby_version = ">= 3.2.0"
|
19
|
+
|
20
|
+
gem.add_dependency "rails", ">= 7.1"
|
18
21
|
gem.add_dependency "devise", ">= 4.8.0", "< 5.0"
|
19
22
|
gem.add_dependency "rotp", ">= 2.0.0"
|
23
|
+
gem.add_dependency "rqrcode", "~> 2.0"
|
20
24
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git"
|
6
|
+
gem "capybara"
|
7
|
+
gem "minitest-reporters", ">= 0.5.0"
|
8
|
+
gem "puma"
|
9
|
+
gem "rake"
|
10
|
+
gem "rdoc"
|
11
|
+
gem "shoulda"
|
12
|
+
gem "sprockets-rails"
|
13
|
+
gem "sqlite3", "~> 1.5.0"
|
14
|
+
gem "standardrb"
|
15
|
+
gem "rails", "~> 7.1.0"
|
16
|
+
|
17
|
+
install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do
|
18
|
+
gem "logger"
|
19
|
+
end
|
20
|
+
|
21
|
+
gemspec path: "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git"
|
6
|
+
gem "capybara"
|
7
|
+
gem "minitest-reporters", ">= 0.5.0"
|
8
|
+
gem "puma"
|
9
|
+
gem "rake"
|
10
|
+
gem "rdoc"
|
11
|
+
gem "shoulda"
|
12
|
+
gem "sprockets-rails"
|
13
|
+
gem "sqlite3", "~> 1.5.0"
|
14
|
+
gem "standardrb"
|
15
|
+
gem "rails", "~> 7.2.0"
|
16
|
+
|
17
|
+
gemspec path: "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git"
|
6
|
+
gem "capybara"
|
7
|
+
gem "minitest-reporters", ">= 0.5.0"
|
8
|
+
gem "puma"
|
9
|
+
gem "rake"
|
10
|
+
gem "rdoc"
|
11
|
+
gem "shoulda"
|
12
|
+
gem "sprockets-rails"
|
13
|
+
gem "sqlite3", "~> 2.1"
|
14
|
+
gem "standardrb"
|
15
|
+
gem "rails", "~> 8.0.0"
|
16
|
+
|
17
|
+
gemspec path: "../"
|
data/lib/devise-otp/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "rqrcode"
|
2
|
+
|
1
3
|
module DeviseOtpAuthenticatable
|
2
4
|
module Controllers
|
3
5
|
module Helpers
|
@@ -12,11 +14,8 @@ module DeviseOtpAuthenticatable
|
|
12
14
|
#
|
13
15
|
def otp_set_flash_message(key, kind, options = {})
|
14
16
|
options[:scope] ||= "devise.otp.#{controller_name}"
|
15
|
-
|
16
|
-
|
17
|
-
options = devise_i18n_options(options) if respond_to?(:devise_i18n_options, true)
|
18
|
-
message = I18n.t("#{options[:resource_name]}.#{kind}", **options)
|
19
|
-
flash[key] = message if message.present?
|
17
|
+
|
18
|
+
set_flash_message(key, kind, options)
|
20
19
|
end
|
21
20
|
|
22
21
|
def otp_t
|
@@ -122,33 +121,11 @@ module DeviseOtpAuthenticatable
|
|
122
121
|
# returns the URL for the QR Code to initialize the Authenticator device
|
123
122
|
#
|
124
123
|
def otp_authenticator_token_image(resource)
|
125
|
-
otp_authenticator_token_image_js(resource.otp_provisioning_uri)
|
126
|
-
end
|
127
|
-
|
128
|
-
private
|
129
|
-
|
130
|
-
def otp_authenticator_token_image_js(otp_url)
|
131
124
|
content_tag(:div, class: "qrcode-container") do
|
132
|
-
|
133
|
-
javascript_tag(%[
|
134
|
-
new QRCode("qrcode", {
|
135
|
-
text: "#{otp_url}",
|
136
|
-
width: 256,
|
137
|
-
height: 256,
|
138
|
-
colorDark : "#000000",
|
139
|
-
colorLight : "#ffffff",
|
140
|
-
correctLevel : QRCode.CorrectLevel.H
|
141
|
-
});
|
142
|
-
])
|
143
|
-
end
|
125
|
+
raw RQRCode::QRCode.new(resource.otp_provisioning_uri).as_svg(:module_size => 5, :viewbox => true, :use_path => true)
|
144
126
|
end
|
145
127
|
end
|
146
128
|
|
147
|
-
def otp_authenticator_token_image_google(otp_url)
|
148
|
-
otp_url = Rack::Utils.escape(otp_url)
|
149
|
-
url = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=#{otp_url}"
|
150
|
-
image_tag(url, alt: "OTP Url QRCode")
|
151
|
-
end
|
152
129
|
end
|
153
130
|
end
|
154
131
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# After each sign in, update credentials refreshed at time
|
2
2
|
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
3
|
-
|
3
|
+
if defined?(record.class.otp_credentials_refresh)
|
4
|
+
warden.session(options[:scope])["credentials_refreshed_at"] = (Time.now + record.class.otp_credentials_refresh)
|
5
|
+
end
|
4
6
|
end
|
5
7
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class AdminPostsController < ApplicationController
|
2
2
|
before_action :authenticate_admin!
|
3
3
|
|
4
|
-
# GET /posts
|
5
|
-
# GET /posts.json
|
6
4
|
def index
|
7
5
|
@posts = Post.all
|
8
6
|
|
@@ -12,74 +10,4 @@ class AdminPostsController < ApplicationController
|
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
|
-
# GET /posts/1
|
16
|
-
# GET /posts/1.json
|
17
|
-
def show
|
18
|
-
@post = Post.find(params[:id])
|
19
|
-
|
20
|
-
respond_to do |format|
|
21
|
-
format.html # show.html.erb
|
22
|
-
format.json { render json: @post }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# GET /posts/new
|
27
|
-
# GET /posts/new.json
|
28
|
-
def new
|
29
|
-
@post = Post.new
|
30
|
-
|
31
|
-
respond_to do |format|
|
32
|
-
format.html # new.html.erb
|
33
|
-
format.json { render json: @post }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# GET /posts/1/edit
|
38
|
-
def edit
|
39
|
-
@post = Post.find(params[:id])
|
40
|
-
end
|
41
|
-
|
42
|
-
# POST /posts
|
43
|
-
# POST /posts.json
|
44
|
-
def create
|
45
|
-
@post = Post.new(params[:post])
|
46
|
-
|
47
|
-
respond_to do |format|
|
48
|
-
if @post.save
|
49
|
-
format.html { redirect_to @post, notice: "Post was successfully created." }
|
50
|
-
format.json { render json: @post, status: :created, location: @post }
|
51
|
-
else
|
52
|
-
format.html { render action: "new" }
|
53
|
-
format.json { render json: @post.errors, status: :unprocessable_entity }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# PUT /posts/1
|
59
|
-
# PUT /posts/1.json
|
60
|
-
def update
|
61
|
-
@post = Post.find(params[:id])
|
62
|
-
|
63
|
-
respond_to do |format|
|
64
|
-
if @post.update_attributes(params[:post])
|
65
|
-
format.html { redirect_to @post, notice: "Post was successfully updated." }
|
66
|
-
format.json { head :ok }
|
67
|
-
else
|
68
|
-
format.html { render action: "edit" }
|
69
|
-
format.json { render json: @post.errors, status: :unprocessable_entity }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# DELETE /posts/1
|
75
|
-
# DELETE /posts/1.json
|
76
|
-
def destroy
|
77
|
-
@post = Post.find(params[:id])
|
78
|
-
@post.destroy
|
79
|
-
|
80
|
-
respond_to do |format|
|
81
|
-
format.html { redirect_to posts_url }
|
82
|
-
format.json { head :ok }
|
83
|
-
end
|
84
|
-
end
|
85
13
|
end
|
@@ -42,7 +42,7 @@ class PostsController < ApplicationController
|
|
42
42
|
# POST /posts
|
43
43
|
# POST /posts.json
|
44
44
|
def create
|
45
|
-
@post = Post.new(
|
45
|
+
@post = Post.new(post_params)
|
46
46
|
|
47
47
|
respond_to do |format|
|
48
48
|
if @post.save
|
@@ -61,7 +61,7 @@ class PostsController < ApplicationController
|
|
61
61
|
@post = Post.find(params[:id])
|
62
62
|
|
63
63
|
respond_to do |format|
|
64
|
-
if @post.update_attributes(
|
64
|
+
if @post.update_attributes(post_params)
|
65
65
|
format.html { redirect_to @post, notice: "Post was successfully updated." }
|
66
66
|
format.json { head :ok }
|
67
67
|
else
|
@@ -82,4 +82,10 @@ class PostsController < ApplicationController
|
|
82
82
|
format.json { head :ok }
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def post_params
|
89
|
+
params.require(:post).permit(:title, :body)
|
90
|
+
end
|
85
91
|
end
|
@@ -1,16 +1,4 @@
|
|
1
|
-
class Admin <
|
2
|
-
if DEVISE_ORM == :mongoid
|
3
|
-
include Mongoid::Document
|
4
|
-
|
5
|
-
## Database authenticatable
|
6
|
-
field :email, type: String, null: false, default: ""
|
7
|
-
field :encrypted_password, type: String, null: false, default: ""
|
8
|
-
|
9
|
-
## Recoverable
|
10
|
-
field :reset_password_token, type: String
|
11
|
-
field :reset_password_sent_at, type: Time
|
12
|
-
end
|
13
|
-
|
1
|
+
class Admin < ActiveRecord::Base
|
14
2
|
devise :otp_authenticatable, :database_authenticatable, :registerable,
|
15
3
|
:trackable, :validatable
|
16
4
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class Post <
|
1
|
+
class Post < ActiveRecord::Base
|
2
2
|
end
|
@@ -1,16 +1,4 @@
|
|
1
|
-
class User <
|
2
|
-
if DEVISE_ORM == :mongoid
|
3
|
-
include Mongoid::Document
|
4
|
-
|
5
|
-
## Database authenticatable
|
6
|
-
field :email, type: String, null: false, default: ""
|
7
|
-
field :encrypted_password, type: String, null: false, default: ""
|
8
|
-
|
9
|
-
## Recoverable
|
10
|
-
field :reset_password_token, type: String
|
11
|
-
field :reset_password_sent_at, type: Time
|
12
|
-
end
|
13
|
-
|
1
|
+
class User < ActiveRecord::Base
|
14
2
|
devise :otp_authenticatable, :database_authenticatable, :registerable,
|
15
3
|
:trackable, :validatable
|
16
4
|
|
@@ -13,13 +13,6 @@
|
|
13
13
|
<tr>
|
14
14
|
<td><%= post.title %></td>
|
15
15
|
<td><%= post.body %></td>
|
16
|
-
<td><%= link_to 'Show', post %></td>
|
17
|
-
<td><%= link_to 'Edit', edit_admin_post_path(post) %></td>
|
18
|
-
<td><%= link_to 'Destroy', [:admin, post], confirm: 'Are you sure?', method: :delete %></td>
|
19
16
|
</tr>
|
20
17
|
<% end %>
|
21
18
|
</table>
|
22
|
-
|
23
|
-
<br />
|
24
|
-
|
25
|
-
<%= link_to 'New Post', new_admin_post_path %>
|