Skip to content

Commit

Permalink
Create User Registration Logic
Browse files Browse the repository at this point in the history
 - Change the user model by setting devise confrimable
 - add confirmation fields to the database
  • Loading branch information
demesameneshoa committed Dec 19, 2023
1 parent 0229999 commit 8ecd8e7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end
end
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
:recoverable, :rememberable, :validatable, :confirmable

has_many :recipes

validates :name, presence: true
end
5 changes: 5 additions & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autocomplete: "name" %>
</div>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'b0a624c7987f9f7b948328d3628cc18f1dfa0ecaf19670d4afac00f34a25d3f95f6902602e8c6a36825f262b0c24c4d59646a66db5bf4d8dcc629fd9c664ca43'
# config.secret_key = 'd21917bf1c93328cf178ee11655b51988e59f91faf1c5197272af90c443ed840f18c693c21f9a5f9d325918316d739e3af8f22e9e4b5afbfd5f2664e6dd4b963'

# ==> Controller configuration
# Configure the parent class to the devise controllers.
Expand Down Expand Up @@ -126,7 +126,7 @@
config.stretches = Rails.env.test? ? 1 : 12

# Set up a pepper to generate the hashed password.
# config.pepper = '3744a9e96514b19a468c01ac76c9971acd68813f3b648f6c18c1029a644caa3434b32eca2cf7c10603600fed3e6eada53c962eb2e79fbf716d48bb1a0881de1a'
# config.pepper = '9e248af07ed8b30a8f7b4e864c9731ca922cbcce0465a6c76b09d29ee8bb4cb2a4fbf456d0a7109393f232577651aeac91a008576bf1738821f92f515b174db9'

# Send a notification to the original email when the user's email is changed.
# config.send_email_changed_notification = false
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20231219114224_add_confirmable_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddConfirmableToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at, :datetime
add_column :users, :unconfirmed_email, :string
end
end
6 changes: 5 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ecd8e7

Please sign in to comment.