Skip to content

Commit

Permalink
chore: add logic for ALLOW_REGISTRATION
Browse files Browse the repository at this point in the history
  • Loading branch information
shafy authored Mar 12, 2022
1 parent 6da777c commit c48d207
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ jobs:
run: |
bundle exec rails test
env:
STRIPE_ENDPOINT_SECRET: ${{ secrets.STRIPE_ENDPOINT_SECRET }}
STRIPE_ENDPOINT_SECRET: ${{ secrets.STRIPE_ENDPOINT_SECRET }}
ALLOW_REGISTRATION: true
4 changes: 2 additions & 2 deletions SELFHOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ If you want to use a different `docker-compose` configuration, simply pass its f

## Tips

### ALLOW_NEW_ACCOUNTS
After you've created your own account on your self-hosted instance, we recommend to set the environment variable `ALLOW_NEW_ACCOUNTS` to `false`. Otherwise, random people who know your URL can create Fugu accounts on your instance.
### ALLOW_REGISTRATION
After you've created your own account on your self-hosted instance, we recommend to set the environment variable `ALLOW_REGISTRATION` to `false`. Otherwise, random people who know your URL can create Fugu accounts on your instance.

## Questions and help
If you have any questions, check out our [GitHub Discussions](https://github.com/shafy/fugu/discussions).
2 changes: 2 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def new
end

def create
return unless ENV["ALLOW_REGISTRATION"] == "true"

super do |resource|
FuguService.track("New User") if resource.persisted?

Expand Down
57 changes: 32 additions & 25 deletions app/views/users/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,46 @@
<h2>Sign up</h2>

<div class="flex flex-col justify-center items-center w-80">
<div class="my-4">
<% unless ENV["ALLOW_REGISTRATION"] == "true" %>
<div class="my-4">
<p>
Welcome to Fugu! To get started, create an account.
</p>
<p>
You can start tracking test events for free, but will need to subscribe for live mode.
The admin of this instance currently doesn't allow new registrations for Fugu.
</p>
</div>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), data: { turbo: false }) do |f| %>
<div class="mb-4 w-80">
<%= f.label :email %><br />
<%= f.email_field :email, autocomplete: "email", class: "mt-2 rounded-lg w-full" %>
<% else %>
<div class="my-4">
<p>
Welcome to Fugu! To get started, create an account.
</p>
<p>
You can start tracking test events for free, but will need to subscribe for live mode.
</p>
</div>

<div class="mb-4 w-80">
<%= f.label :password %>
<% if @minimum_password_length %>
<em class="text-sm text-gray-600">(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password", class: "mt-2 rounded-lg w-full" %>
</div>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), data: { turbo: false }) do |f| %>
<div class="mb-4 w-80">
<%= f.label :email %><br />
<%= f.email_field :email, autocomplete: "email", class: "mt-2 rounded-lg w-full" %>
</div>

<div class="mb-4 w-80">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "mt-2 rounded-lg w-full" %>
</div>
<div class="mb-4 w-80">
<%= f.label :password %>
<% if @minimum_password_length %>
<em class="text-sm text-gray-600">(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password", class: "mt-2 rounded-lg w-full" %>
</div>

<div class="mb-4 w-80">
<%= f.submit "Sign up", class: "main-button border-none" %>
</div>
<% end %>
<div class="mb-4 w-80">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "mt-2 rounded-lg w-full" %>
</div>

<div class="mb-4 w-80">
<%= f.submit "Sign up", class: "main-button border-none" %>
</div>
<% end %>
<% end %>
<%= render "devise/shared/links" %>
</div>
<% end %>
12 changes: 5 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
post "/webhooks/", to: "stripe#webhooks", as: "stripe_webhooks"
end

devise_for \
:users,
controllers: {
sessions: "users/sessions",
registrations: "users/registrations",
passwords: "users/passwords"
}
devise_for :users, controllers: {
sessions: "users/sessions",
registrations: "users/registrations",
passwords: "users/passwords"
}

namespace :api do
namespace :v1 do
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ services:
- DATABASE_NAME=${DATABASE_NAME}
- DATABASE_NAME_TEST=${DATABASE_NAME}
- SENTRY_DSN=${SENTRY_DSN}
- ALLOW_NEW_ACCOUNTS=${ALLOW_NEW_ACCOUNTS}
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION}
2 changes: 1 addition & 1 deletion docker-compose.prod-remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ services:
- SECRET_KEY_BASE=${SECRET_KEY_BASE}
- RAILS_LOG_TO_STDOUT=${RAILS_LOG_TO_STDOUT}
- SENTRY_DSN=${SENTRY_DSN}
- ALLOW_NEW_ACCOUNTS=${ALLOW_NEW_ACCOUNTS}
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION}

0 comments on commit c48d207

Please sign in to comment.