implement /setup and /admin

This commit is contained in:
2026-01-23 02:52:53 +01:00
parent e4e5a1c294
commit a9c70a7883
21 changed files with 1124 additions and 13 deletions
+45
View File
@@ -0,0 +1,45 @@
class SetupController < ApplicationController
before_action :check_setup_allowed
def show
@user = User.new(role: :admin)
end
def create
@user = User.new(user_params)
@user.role = :admin
@user.invitation_accepted_at = Time.current
if @user.save
create_installed_marker
session[:user_id] = @user.id
redirect_to admin_root_path, notice: "Setup complete! Welcome to Sanasto Wiki."
else
render :show, status: :unprocessable_entity
end
end
private
def check_setup_allowed
if setup_completed?
redirect_to root_path, alert: "Setup has already been completed."
end
end
def setup_completed?
File.exist?(installed_marker_path)
end
def installed_marker_path
Rails.root.join(".installed")
end
def create_installed_marker
FileUtils.touch(installed_marker_path)
end
def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation, :primary_language)
end
end