diff --git a/app/controllers/first_runs_controller.rb b/app/controllers/first_runs_controller.rb new file mode 100644 index 000000000..64bd78cba --- /dev/null +++ b/app/controllers/first_runs_controller.rb @@ -0,0 +1,23 @@ +class FirstRunsController < ApplicationController + allow_unauthenticated_access + + before_action :prevent_repeats + + def show + end + + def create + user = FirstRun.create!(user_params) + start_new_session_for user + redirect_to root_url + end + + private + def prevent_repeats + redirect_to root_url unless Account.none? + end + + def user_params + params.require(:user).permit(:name, :email_address, :password) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 3c18b47ed..357e70a98 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,6 +2,8 @@ class SessionsController < ApplicationController allow_unauthenticated_access only: %i[ new create ] rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." } + before_action :require_first_run_completion + def new end @@ -18,4 +20,9 @@ class SessionsController < ApplicationController terminate_session redirect_to new_session_url end + + private + def require_first_run_completion + redirect_to first_run_url if Account.none? + end end diff --git a/app/helpers/first_runs_helper.rb b/app/helpers/first_runs_helper.rb new file mode 100644 index 000000000..48a2e6739 --- /dev/null +++ b/app/helpers/first_runs_helper.rb @@ -0,0 +1,2 @@ +module FirstRunsHelper +end diff --git a/app/models/first_run.rb b/app/models/first_run.rb new file mode 100644 index 000000000..ad010a37f --- /dev/null +++ b/app/models/first_run.rb @@ -0,0 +1,6 @@ +class FirstRun + def self.create!(user_attributes) + account = Account.create!(name: "Fizzy") + account.users.create!(user_attributes) + end +end diff --git a/app/views/first_runs/show.html.erb b/app/views/first_runs/show.html.erb new file mode 100644 index 000000000..0aa48f667 --- /dev/null +++ b/app/views/first_runs/show.html.erb @@ -0,0 +1,45 @@ +<% @page_title = "Set up Fizzy" %> + +
" style="--panel-size: 55ch;"> +
+ + + + + +         +     +
+ +

Fizzy

+ + <%= form_with model: User.new, url: first_run_path, class: "flex flex-column gap txt-large" do |form| %> +
+ <%= translation_button :user_name %> + +
+ +
+ <%= translation_button :email_address %> + +
+ +
+ <%= translation_button :password %> + +
+ + <% end %> +
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 75500f5a7..1ef09f9c4 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -15,7 +15,7 @@ <%= form_with url: session_path, class: "flex flex-column gap txt-large" do |form| %>
- <%= translation_button(:email_address) %> + <%= translation_button :email_address %>
- <%= translation_button(:password) %> + <%= translation_button :password %>