mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- SSO via OmniAuth OpenID Connect (Authentik, Keycloak, …): link by stable subject, by verified email, or from the profile; optional auto-create, admin-group sync, and turning password sign-in off - Current password required to change email or password; password changes and resets sign out other sessions; idle sessions expire after 30 days; "sign out everywhere else"; session reset on sign-in - Rate-limit password resets; scope squawk components to the aircraft - Strict Content Security Policy with nonces (inline handlers removed), Permissions-Policy and COOP headers; file links expire after an hour Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.5 KiB
Ruby
42 lines
1.5 KiB
Ruby
class PasswordsController < ApplicationController
|
|
allow_unauthenticated_access
|
|
before_action :require_password_login
|
|
before_action :set_user_by_token, only: %i[ edit update ]
|
|
rate_limit to: 5, within: 15.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
|
|
rate_limit to: 10, within: 15.minutes, only: :update, with: -> { redirect_to new_session_path, alert: "Try again later." }
|
|
|
|
def new
|
|
end
|
|
|
|
def create
|
|
if user = User.find_by(email_address: params[:email_address])
|
|
PasswordsMailer.reset(user).deliver_later
|
|
end
|
|
|
|
redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if params[:password].present? && @user.update(params.permit(:password, :password_confirmation))
|
|
@user.sessions.destroy_all # a reset signs out every device
|
|
redirect_to new_session_path, notice: "Password has been reset."
|
|
else
|
|
redirect_to edit_password_path(params[:token]), alert: "Passwords did not match."
|
|
end
|
|
end
|
|
|
|
private
|
|
def require_password_login
|
|
redirect_to new_session_path, alert: "Sign in with #{Sso.label}." unless Sso.password_login?
|
|
end
|
|
|
|
def set_user_by_token
|
|
@user = User.find_by_password_reset_token!(params[:token])
|
|
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
|
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
|
|
end
|
|
end
|