Signup::AccountsController suppports signing up with a new identity
This commit is contained in:
@@ -19,6 +19,7 @@ module Authentication
|
||||
end
|
||||
|
||||
def require_untenanted_access(**options)
|
||||
skip_before_action :set_current_account, **options
|
||||
skip_before_action :require_authentication, **options
|
||||
before_action :redirect_tenanted_request, **options
|
||||
end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class Signup::AccountsController < ApplicationController
|
||||
require_untenanted_access
|
||||
|
||||
def new
|
||||
@signup = Signup.new
|
||||
end
|
||||
|
||||
def create
|
||||
@signup = Signup.new(signup_params)
|
||||
|
||||
if @signup.process
|
||||
redirect_to_account(@signup.account)
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def signup_params
|
||||
params.require(:signup).permit(:full_name, :email_address, :password, :company_name)
|
||||
end
|
||||
|
||||
def redirect_to_account(account)
|
||||
redirect_to account.signal_account.owner.remote_login_url(proceed_to: root_path),
|
||||
allow_other_host: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,58 @@
|
||||
<% @page_title = "Sign up for Fizzy" %>
|
||||
|
||||
<div class="panel shadow center margin-block-double <%= "shake" if flash[:alert] %>" style="--panel-size: 65ch;">
|
||||
<h1 class="txt-xx-large margin-block-end-double">Fizzy</h1>
|
||||
<h2 class="txt-large margin-block-end-double">Create your account</h2>
|
||||
|
||||
<%= form_with model: @signup, url: signup_accounts_path, scope: "signup", class: "flex flex-column gap txt-large", data: { turbo: false } do |form| %>
|
||||
<div class="flex align-center gap">
|
||||
<label class="flex align-center gap input input--actor txt-large">
|
||||
<%= form.text_field :full_name, class: "input", autocomplete: "name", placeholder: "Your name", autofocus: true, required: true %>
|
||||
<%= icon_tag "person", class: "txt-large" %>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex align-center gap">
|
||||
<label class="flex align-center gap input input--actor txt-large">
|
||||
<%= form.email_field :email_address, class: "input", autocomplete: "username", placeholder: "Your email address", required: true %>
|
||||
<%= icon_tag "email", class: "txt-large" %>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex align-center gap">
|
||||
<label class="flex align-center gap input input--actor txt-large">
|
||||
<%= form.text_field :company_name, class: "input", autocomplete: "organization", placeholder: "Your organization's name", required: true %>
|
||||
<%= icon_tag "building", class: "txt-large" %>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex align-center gap">
|
||||
<label class="flex align-center gap input input--actor txt-large">
|
||||
<%= form.password_field :password, class: "input", autocomplete: "new-password", placeholder: "Password (at least 12 characters)", required: true, maxlength: 72, minlength: 12 %>
|
||||
<%= icon_tag "password", class: "txt-large" %>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<% if @signup.errors.any? %>
|
||||
<div class="alert alert--error">
|
||||
<ul class="margin-block-none">
|
||||
<% @signup.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<button type="submit" class="btn btn--reversed center">
|
||||
<%= icon_tag "arrow-right" %>
|
||||
<span>Create your account</span>
|
||||
</button>
|
||||
<% end %>
|
||||
|
||||
<footer class="margin-block-start-double txt-center">
|
||||
<p class="txt-small txt-muted">
|
||||
Already have an account?
|
||||
<%= link_to "Sign in", Launchpad.login_url(product: true), class: "decorated" %>
|
||||
</p>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -2,10 +2,17 @@ Rails.application.config.after_initialize do
|
||||
# in production and staging, we're using a two-level subdomain like "tenant.fizzy.37signals.com".
|
||||
# in development and beta it's only a single-level subdomain.
|
||||
Rails.application.config.active_record_tenanted.tenant_resolver = ->(request) do
|
||||
next nil if request.path == "/up"
|
||||
|
||||
tld_length = [ "37signals.com", "37signals-staging.com" ].include?(request.domain) ? 2 : 1
|
||||
request.subdomain(tld_length).presence || "return-404" # this is a quick fix for now
|
||||
|
||||
if request.path == "/up"
|
||||
nil
|
||||
elsif subdomain = request.subdomain(tld_length).presence
|
||||
subdomain
|
||||
elsif optional = request.path =~ %r{^/signup\b}
|
||||
nil
|
||||
else
|
||||
"return-404" # this is a quick fix for now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -88,6 +88,11 @@ Rails.application.routes.draw do
|
||||
get "launchpad", to: "sessions/launchpad#show"
|
||||
end
|
||||
|
||||
namespace :signup do
|
||||
get "/" => "accounts#new"
|
||||
resources :accounts, only: %i[ new create ]
|
||||
end
|
||||
|
||||
resources :users do
|
||||
scope module: :users do
|
||||
resource :avatar
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
require "test_helper"
|
||||
|
||||
class Signup::AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "new at a tenanted domain" do
|
||||
get new_signup_account_url
|
||||
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
test "new at an untenanted domain" do
|
||||
integration_session.host = "example.com" # no subdomain
|
||||
|
||||
get new_signup_account_url
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create with invalid params" do
|
||||
integration_session.host = "example.com" # no subdomain
|
||||
|
||||
post signup_accounts_url, params: { signup: { full_name: "Jim", email_address: "jim@example.com", password: "", company_name: "" } }
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_select "div.alert--error", text: /you need to choose a password/i
|
||||
end
|
||||
|
||||
test "create for a new " do
|
||||
integration_session.host = "example.com" # no subdomain
|
||||
|
||||
assert_difference -> { SignalId::Identity.count }, +1 do
|
||||
assert_difference -> { SignalId::Account.count }, +1 do
|
||||
post signup_accounts_url, params: { signup: { full_name: "Jim", email_address: "jim@example.com", password: SecureRandom.hex(12), company_name: "signup-accounts-controller-test-1" } }
|
||||
end
|
||||
end
|
||||
|
||||
signal_account = SignalId::Account.last
|
||||
assert_redirected_to(/#{signal_account.login_url}/)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user