mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-27 17:19:39 +02:00
Add basic self hosted onboarding (#1177)
* Add basic self hosted onboarding * Lint fix * Normalize translations
This commit is contained in:
parent
0149ca4ea1
commit
d3d9af8bce
6 changed files with 37 additions and 3 deletions
|
@ -16,10 +16,14 @@ module Authentication
|
||||||
def authenticate_user!
|
def authenticate_user!
|
||||||
if user = User.find_by(id: session[:user_id])
|
if user = User.find_by(id: session[:user_id])
|
||||||
Current.user = user
|
Current.user = user
|
||||||
|
else
|
||||||
|
if self_hosted_first_login?
|
||||||
|
redirect_to new_registration_url
|
||||||
else
|
else
|
||||||
redirect_to new_session_url
|
redirect_to new_session_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def login(user)
|
def login(user)
|
||||||
Current.user = user
|
Current.user = user
|
||||||
|
@ -36,4 +40,8 @@ module Authentication
|
||||||
def set_last_login_at
|
def set_last_login_at
|
||||||
Current.user.update(last_login_at: DateTime.now)
|
Current.user.update(last_login_at: DateTime.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self_hosted_first_login?
|
||||||
|
Rails.application.config.app_mode.self_hosted? && User.count.zero?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,10 @@ module Invitable
|
||||||
|
|
||||||
private
|
private
|
||||||
def invite_code_required?
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,15 @@ module SelfHostable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
helper_method :self_hosted?
|
helper_method :self_hosted?, :self_hosted_first_login?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def self_hosted?
|
def self_hosted?
|
||||||
Rails.configuration.app_mode.self_hosted?
|
Rails.configuration.app_mode.self_hosted?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self_hosted_first_login?
|
||||||
|
self_hosted? && User.count.zero?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ class Demo::Generator
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_and_clear_data!
|
def reset_and_clear_data!
|
||||||
|
reset_settings!
|
||||||
clear_data!
|
clear_data!
|
||||||
create_user!
|
create_user!
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ class Demo::Generator
|
||||||
|
|
||||||
def reset_data!
|
def reset_data!
|
||||||
Family.transaction do
|
Family.transaction do
|
||||||
|
reset_settings!
|
||||||
clear_data!
|
clear_data!
|
||||||
create_user!
|
create_user!
|
||||||
|
|
||||||
|
@ -52,12 +54,17 @@ class Demo::Generator
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_data!
|
def clear_data!
|
||||||
|
InviteCode.destroy_all
|
||||||
User.find_by_email("user@maybe.local")&.destroy
|
User.find_by_email("user@maybe.local")&.destroy
|
||||||
ExchangeRate.destroy_all
|
ExchangeRate.destroy_all
|
||||||
Security.destroy_all
|
Security.destroy_all
|
||||||
Security::Price.destroy_all
|
Security::Price.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_settings!
|
||||||
|
Setting.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
def create_user!
|
def create_user!
|
||||||
family.users.create! \
|
family.users.create! \
|
||||||
email: "user@maybe.local",
|
email: "user@maybe.local",
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<%
|
<%
|
||||||
header_title t(".title")
|
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| %>
|
<%= styled_form_with model: @user, url: registration_path, class: "space-y-4" do |form| %>
|
||||||
<%= auth_messages form %>
|
<%= auth_messages form %>
|
||||||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: "required", placeholder: "you@example.com", label: true %>
|
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: "required", placeholder: "you@example.com", label: true %>
|
||||||
|
|
|
@ -14,3 +14,6 @@ en:
|
||||||
success: You have signed up successfully.
|
success: You have signed up successfully.
|
||||||
new:
|
new:
|
||||||
title: Create an account
|
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!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue