Pre-fill login credentials in PikaPods demo site (#288)

* Gate demo credential prefills by host

* Business logic in controller

* Store demo config in Rails

* Proper check for demo settings

* Add demo banner

* Support hosts array

* Add demo.sure.am

* Nice rescue addition by CodeRabbit

---------

Co-authored-by: sokie <sokysrm@gmail.com>
This commit is contained in:
Juan José Mata
2025-11-13 23:03:16 +01:00
committed by GitHub
parent 3f1d1c0238
commit 61fe75f06c
4 changed files with 70 additions and 3 deletions

View File

@@ -5,6 +5,22 @@ class SessionsController < ApplicationController
layout "auth"
def new
begin
demo = Rails.application.config_for(:demo)
@prefill_demo_credentials = demo_host_match?(demo)
if @prefill_demo_credentials
@email = params[:email].presence || demo["email"]
@password = params[:password].presence || demo["password"]
else
@email = params[:email]
@password = params[:password]
end
rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError
# Demo config file missing or malformed - disable demo credential prefilling
@prefill_demo_credentials = false
@email = params[:email]
@password = params[:password]
end
end
def create
@@ -75,4 +91,10 @@ class SessionsController < ApplicationController
def set_session
@session = Current.user.sessions.find(params[:id])
end
def demo_host_match?(demo)
return false unless demo.present? && demo["hosts"].present?
demo["hosts"].include?(request.host)
end
end