Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable devise lockable. #467

Merged
merged 2 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gem 'fontello_rails_converter'
gem 'bootstrap-datepicker-rails'
gem 'public_suffix'
gem 'devise-security'
gem 'rails_email_validator'
gem 'email_validator', require: 'email_validator/strict'

gem 'doorkeeper-jwt', git: 'https://github.com/rubykube/doorkeeper-jwt.git'
gem 'memoist', '~> 0.16'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ GEM
unf (>= 0.0.5, < 1.0.0)
doorkeeper (4.2.6)
railties (>= 4.2)
email_validator (1.6.0)
activemodel
equalizer (0.0.11)
erubi (1.7.0)
excon (0.60.0)
Expand Down Expand Up @@ -281,8 +283,6 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails_email_validator (0.1.4)
activemodel (>= 3.0.0)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
Expand Down Expand Up @@ -410,6 +410,7 @@ DEPENDENCIES
discard (~> 1.0)
doorkeeper (~> 4.2.6)
doorkeeper-jwt!
email_validator
factory_bot_rails (~> 4.8)
faker (~> 1.8)
figaro
Expand All @@ -436,7 +437,6 @@ DEPENDENCIES
rack-cors (~> 1.0.2)
rails (~> 5.1.4)
rails-controller-testing
rails_email_validator
rspec-rails (~> 3.7.1)
sassc-rails (~> 1.3)
selenium-webdriver (~> 3.8)
Expand Down
3 changes: 3 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def as_json_for_event_api
reset_password_token: reset_password_token,
reset_password_sent_at: format_iso8601_time(reset_password_sent_at),
state: state,
failed_attempts: failed_attempts,
unlock_token: unlock_token,
locked_at: locked_at,
created_at: format_iso8601_time(created_at),
updated_at: format_iso8601_time(updated_at)
}
Expand Down
12 changes: 6 additions & 6 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,27 @@
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
config.lock_strategy = :failed_attempts

# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [:email]
config.unlock_keys = [:email]

# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both
config.unlock_strategy = :both

# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
config.maximum_attempts = 5

# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
config.unlock_in = 1.hour

# Warn on the last attempt before the account is locked.
# config.last_attempt_warning = true
config.last_attempt_warning = false

# ==> Configuration for :recoverable
#
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

admin = Account.new(seed['account'])
admin.password ||= SecureRandom.hex(20)
admin.password ||= SecureRandom.base64(30)

if admin.save
logger.info "Created account for '#{admin.email}'"
Expand Down