.circleci
.github
app
chewy
controllers
activitypub
admin
api
auth
concerns
account_controller_concern.rb
account_owned_concern.rb
accountable_concern.rb
authorization.rb
cache_concern.rb
challengable_concern.rb
export_controller_concern.rb
localized.rb
rate_limit_headers.rb
registration_spam_concern.rb
session_tracking_concern.rb
sign_in_token_authentication_concern.rb
signature_authentication.rb
signature_verification.rb
status_controller_concern.rb
two_factor_authentication_concern.rb
user_tracking_concern.rb
oauth
settings
well_known
about_controller.rb
account_follow_controller.rb
account_unfollow_controller.rb
accounts_controller.rb
application_controller.rb
authorize_interactions_controller.rb
custom_css_controller.rb
directories_controller.rb
emojis_controller.rb
filters_controller.rb
follower_accounts_controller.rb
following_accounts_controller.rb
home_controller.rb
instance_actors_controller.rb
intents_controller.rb
invites_controller.rb
manifests_controller.rb
media_controller.rb
media_proxy_controller.rb
public_timelines_controller.rb
relationships_controller.rb
remote_follow_controller.rb
remote_interaction_controller.rb
shares_controller.rb
statuses_controller.rb
tags_controller.rb
helpers
javascript
lib
mailers
models
policies
presenters
serializers
services
validators
views
workers
bin
chart
config
db
dist
lib
log
nanobox
public
spec
streaming
vendor
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.js
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.profile
.rspec
.rubocop.yml
.ruby-version
.sass-lint.yml
.slugignore
.yarnclean
AUTHORS.md
Aptfile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
SECURITY.md
Vagrantfile
app.json
babel.config.js
boxfile.yml
config.ru
crowdin.yml
docker-compose.yml
ide-helper.js
package.json
postcss.config.js
priv-config
scalingo.json
yarn.lock
If someone tries logging in to an account and is prompted for a 2FA code or sign-in token, even if the account's password or e-mail is updated in the meantime, the session will show the prompt and allow the login process to complete with a valid 2FA code or sign-in token
54 lines
1.5 KiB
Ruby
54 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module SignInTokenAuthenticationConcern
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
prepend_before_action :authenticate_with_sign_in_token, if: :sign_in_token_required?, only: [:create]
|
|
end
|
|
|
|
def sign_in_token_required?
|
|
find_user&.suspicious_sign_in?(request.remote_ip)
|
|
end
|
|
|
|
def valid_sign_in_token_attempt?(user)
|
|
Devise.secure_compare(user.sign_in_token, user_params[:sign_in_token_attempt])
|
|
end
|
|
|
|
def authenticate_with_sign_in_token
|
|
user = self.resource = find_user
|
|
|
|
if user.present? && session[:attempt_user_id].present? && session[:attempt_user_updated_at] != user.updated_at.to_s
|
|
restart_session
|
|
elsif user_params.key?(:sign_in_token_attempt) && session[:attempt_user_id]
|
|
authenticate_with_sign_in_token_attempt(user)
|
|
elsif user.present? && user.external_or_valid_password?(user_params[:password])
|
|
prompt_for_sign_in_token(user)
|
|
end
|
|
end
|
|
|
|
def authenticate_with_sign_in_token_attempt(user)
|
|
if valid_sign_in_token_attempt?(user)
|
|
clear_attempt_from_session
|
|
remember_me(user)
|
|
sign_in(user)
|
|
else
|
|
flash.now[:alert] = I18n.t('users.invalid_sign_in_token')
|
|
prompt_for_sign_in_token(user)
|
|
end
|
|
end
|
|
|
|
def prompt_for_sign_in_token(user)
|
|
if user.sign_in_token_expired?
|
|
user.generate_sign_in_token && user.save
|
|
UserMailer.sign_in_token(user, request.remote_ip, request.user_agent, Time.now.utc.to_s).deliver_later!
|
|
end
|
|
|
|
set_attempt_session(user)
|
|
|
|
@body_classes = 'lighter'
|
|
|
|
set_locale { render :sign_in_token }
|
|
end
|
|
end
|