Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Add basic self hosted onboarding (#1177)

Zach Gollwitzerd3d9af8bce0f
diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb
index d1a70299..9041f5c9 100644
--- a/app/controllers/concerns/authentication.rb
+++ b/app/controllers/concerns/authentication.rb
@@ -17,7 +17,11 @@ module Authentication
if user = User.find_by(id: session[:user_id])
Current.user = user
else
- redirect_to new_session_url
+ if self_hosted_first_login?
+ redirect_to new_registration_url
+ else
+ redirect_to new_session_url
+ end
end
end
@@ -36,4 +40,8 @@ module Authentication
def set_last_login_at
Current.user.update(last_login_at: DateTime.now)
end
+
+ def self_hosted_first_login?
+ Rails.application.config.app_mode.self_hosted? && User.count.zero?
+ end
end
diff --git a/app/controllers/concerns/invitable.rb b/app/controllers/concerns/invitable.rb
index 397c7a68..1e0dfed8 100644
--- a/app/controllers/concerns/invitable.rb
+++ b/app/controllers/concerns/invitable.rb
@@ -7,6 +7,10 @@ module Invitable
private
def invite_code_required?
- ENV["REQUIRE_INVITE_CODE"] == "true"
+ self_hosted? ? Setting.require_invite_for_signup : ENV["REQUIRE_INVITE_CODE"] == "true"
+ end
+
+ def self_hosted?
+ Rails.application.config.app_mode.self_hosted?
end
end
diff --git a/app/controllers/concerns/self_hostable.rb b/app/controllers/concerns/self_hostable.rb
index b0af8d6a..a863f170 100644
--- a/app/controllers/concerns/self_hostable.rb
+++ b/app/controllers/concerns/self_hostable.rb
@@ -2,11 +2,15 @@ module SelfHostable
extend ActiveSupport::Concern
included do
- helper_method :self_hosted?
+ helper_method :self_hosted?, :self_hosted_first_login?
end
private
def self_hosted?
Rails.configuration.app_mode.self_hosted?
end
+
+ def self_hosted_first_login?
+ self_hosted? && User.count.zero?
+ end
end
diff --git a/app/models/demo/generator.rb b/app/models/demo/generator.rb
index 952aca95..76b54918 100644
--- a/app/models/demo/generator.rb
+++ b/app/models/demo/generator.rb
@@ -6,6 +6,7 @@ class Demo::Generator
end
def reset_and_clear_data!
+ reset_settings!
clear_data!
create_user!
@@ -14,6 +15,7 @@ class Demo::Generator
def reset_data!
Family.transaction do
+ reset_settings!
clear_data!
create_user!
@@ -52,12 +54,17 @@ class Demo::Generator
end
def clear_data!
+ InviteCode.destroy_all
User.find_by_email("[email protected]")&.destroy
ExchangeRate.destroy_all
Security.destroy_all
Security::Price.destroy_all
end
+ def reset_settings!
+ Setting.destroy_all
+ end
+
def create_user!
family.users.create! \
diff --git a/app/views/registrations/new.html.erb b/app/views/registrations/new.html.erb
index a5714243..cbcad3d7 100644
--- a/app/views/registrations/new.html.erb
+++ b/app/views/registrations/new.html.erb
@@ -1,6 +1,14 @@
<%
header_title t(".title")
%>
+
+<% if self_hosted_first_login? %>
+ <div class="fixed inset-0 w-full h-fit bg-gray-25 p-5 border-b border-alpha-black-200 flex flex-col gap-3 items-center text-center mb-12">
+ <h2 class="font-bold text-xl"><%= t(".welcome_title") %></h2>
+ <p class="text-gray-500 text-sm"><%= t(".welcome_body") %></p>
+ </div>
+<% end %>
+
<%= styled_form_with model: @user, url: registration_path, class: "space-y-4" do |form| %>
<%= auth_messages form %>
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: "required", placeholder: "[email protected]", label: true %>
diff --git a/config/locales/views/registrations/en.yml b/config/locales/views/registrations/en.yml
index a3ea5b52..b091fc3a 100644
--- a/config/locales/views/registrations/en.yml
+++ b/config/locales/views/registrations/en.yml
@@ -14,3 +14,6 @@ en:
success: You have signed up successfully.
new:
title: Create an account
+ welcome_body: To get started, you must sign up for a new account. You will
+ then be able to configure additional settings within the app.
+ welcome_title: Welcome to Self Hosted Maybe!