Organize everything under Signups

This commit is contained in:
Stanko K.R.
2025-11-29 11:46:09 +01:00
parent 5747445977
commit 658b5a07cf
9 changed files with 78 additions and 28 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/basecamp/fizzy-saas
revision: 4740eeaa3ac652bfb695282a963a79fa1a1409e3
revision: 0c6f9f6c7fa767fb83645286cdaf6705f9b753a5
ref: remove-unused-route
specs:
fizzy-saas (0.1.0)
@@ -53,7 +53,7 @@ GIT
GIT
remote: https://github.com/rails/rails.git
revision: 4f7ab01bb5d6be78c7447dbb230c55027d08ae34
revision: 690ec8898318b8f50714e86676353ebe1551261e
branch: main
specs:
actioncable (8.2.0.alpha)
@@ -424,7 +424,7 @@ GEM
rake-compiler-dock (1.9.1)
rb_sys (0.9.117)
rake-compiler-dock (= 1.9.1)
rdoc (6.15.1)
rdoc (6.16.1)
erb
psych (>= 4.0.0)
tsort
@@ -480,10 +480,10 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 4.0)
websocket (~> 1.0)
sentry-rails (6.1.1)
sentry-rails (6.2.0)
railties (>= 5.2.0)
sentry-ruby (~> 6.1.1)
sentry-ruby (6.1.1)
sentry-ruby (~> 6.2.0)
sentry-ruby (6.2.0)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
sniffer (0.5.0)
-9
View File
@@ -1,13 +1,4 @@
class SessionsController < ApplicationController
# FIXME: Remove this before launch!
unless Rails.env.local?
http_basic_authenticate_with \
name: Rails.application.credentials.account_signup_http_basic_auth.name,
password: Rails.application.credentials.account_signup_http_basic_auth.password,
realm: "Fizzy Signup",
only: :create, unless: -> { Identity.exists?(email_address: email_address) }
end
disallow_account_scope
require_unauthenticated_access except: :destroy
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
@@ -1,4 +1,4 @@
class Signup::CompletionsController < ApplicationController
class Signups::CompletionsController < ApplicationController
layout "public"
disallow_account_scope
+15 -6
View File
@@ -1,7 +1,16 @@
class SignupsController < ApplicationController
# FIXME: Remove this before launch!
unless Rails.env.local?
http_basic_authenticate_with \
name: Rails.application.credentials.account_signup_http_basic_auth.name,
password: Rails.application.credentials.account_signup_http_basic_auth.password,
realm: "Fizzy Signup"
end
disallow_account_scope
allow_unauthenticated_access
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_signup_path, alert: "Try again later." }
before_action :redirect_authenticated_user
layout "public"
@@ -10,15 +19,15 @@ class SignupsController < ApplicationController
end
def create
if Current.identity
Signup.new(signup_params).create_identity
redirect_to session_magic_link_path
else
redirect_to new_signup_completion_path
end
Signup.new(signup_params).create_identity
redirect_to session_magic_link_path
end
private
def redirect_authenticated_user
redirect_to new_signup_completion_path if authenticated?
end
def signup_params
params.expect signup: :email_address
end
+1 -1
View File
@@ -159,7 +159,7 @@ Rails.application.routes.draw do
resource :signup, only: %i[ new create ] do
collection do
scope module: :signup, as: :signup do
scope module: :signups, as: :signup do
resource :completion, only: %i[ new create ]
end
end
+3 -5
View File
@@ -23,11 +23,9 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
test "create for a new user" do
untenanted do
assert_difference -> { Identity.count }, +1 do
assert_difference -> { MagicLink.count }, +1 do
post session_path,
params: { email_address: "nonexistent-#{SecureRandom.hex(6)}@example.com" }
end
assert_no_difference -> { MagicLink.count } do
post session_path,
params: { email_address: "nonexistent-#{SecureRandom.hex(6)}@example.com" }
end
assert_redirected_to session_magic_link_path
@@ -0,0 +1,52 @@
require "test_helper"
class SignupsControllerTest < ActionDispatch::IntegrationTest
test "new" do
untenanted do
get new_signup_path
assert_response :success
end
end
test "new for an authenticated user" do
identity = identities(:kevin)
sign_in_as identity
untenanted do
get new_signup_path
assert_redirected_to new_signup_completion_path
end
end
test "create" do
email_address = "newuser-#{SecureRandom.hex(6)}@example.com"
untenanted do
assert_difference -> { Identity.count }, +1 do
assert_difference -> { MagicLink.count }, +1 do
post signup_path, params: { signup: { email_address: email_address } }
end
end
assert_redirected_to session_magic_link_path
end
end
test "create for an authenticated user" do
identity = identities(:kevin)
sign_in_as identity
untenanted do
assert_no_difference -> { Identity.count } do
assert_no_difference -> { MagicLink.count } do
post signup_path,
params: { signup: { email_address: identity.email_address } }
end
end
assert_redirected_to new_signup_completion_path
end
end
end