This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class RegistrationsController < ApplicationController | ||
allow_unauthenticated_access(only: %i[new create]) | ||
before_action :resume_session, only: [:new] | ||
Check failure on line 3 in app/controllers/registrations_controller.rb GitHub Actions / lint
|
||
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." } | ||
|
||
def new | ||
redirect_to root_url if authenticated? | ||
end | ||
|
||
def create | ||
user = User.new(params.permit(:email_address, :password)) | ||
if user.save | ||
start_new_session_for user | ||
redirect_to after_authentication_url, notice: "Signed up." | ||
else | ||
redirect_to new_session_url, alert: user.errors.full_messages.to_sentence | ||
end | ||
end | ||
|
||
def destroy | ||
terminate_session | ||
redirect_to new_session_url, notice: "Signed out." | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class User < ApplicationRecord | ||
has_secure_password validations: false | ||
has_many :sessions, dependent: :destroy | ||
|
||
validates :email_address, uniqueness: true, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h1>Create an account</h1> | ||
|
||
<%= form_with url: registration_url do |form| %> | ||
<div> | ||
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %> | ||
</div> | ||
|
||
<div> | ||
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %> | ||
</div> | ||
|
||
<%= form.submit "Sign up" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters