Enable Devise confirmable
This commit is contained in:
parent
c3722e7559
commit
3daf5ce67f
4
Gemfile
4
Gemfile
|
@ -141,6 +141,10 @@ group :development do
|
||||||
|
|
||||||
# YARD is a documentation generation tool for the Ruby programming language.
|
# YARD is a documentation generation tool for the Ruby programming language.
|
||||||
gem 'yard', '~> 0.9'
|
gem 'yard', '~> 0.9'
|
||||||
|
|
||||||
|
# When mail is sent from your application,
|
||||||
|
# Letter Opener will open a preview in the browser instead of sending.
|
||||||
|
gem 'letter_opener', '~> 1.6'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
|
|
@ -163,6 +163,8 @@ GEM
|
||||||
json (2.1.0)
|
json (2.1.0)
|
||||||
launchy (2.4.3)
|
launchy (2.4.3)
|
||||||
addressable (~> 2.3)
|
addressable (~> 2.3)
|
||||||
|
letter_opener (1.6.0)
|
||||||
|
launchy (~> 2.2)
|
||||||
libv8 (6.7.288.46.1)
|
libv8 (6.7.288.46.1)
|
||||||
listen (3.1.5)
|
listen (3.1.5)
|
||||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||||
|
@ -384,6 +386,7 @@ DEPENDENCIES
|
||||||
font-awesome-sass (~> 5.5.0)
|
font-awesome-sass (~> 5.5.0)
|
||||||
interactor (~> 3.1)
|
interactor (~> 3.1)
|
||||||
jquery-rails (~> 4.3)
|
jquery-rails (~> 4.3)
|
||||||
|
letter_opener (~> 1.6)
|
||||||
listen (>= 3.0.5, < 3.2)
|
listen (>= 3.0.5, < 3.2)
|
||||||
mini_racer
|
mini_racer
|
||||||
pg (>= 0.18, < 2.0)
|
pg (>= 0.18, < 2.0)
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Users::ConfirmationsController < Devise::ConfirmationsController
|
||||||
|
skip_after_action :verify_authorized
|
||||||
|
skip_after_action :verify_policy_scoped
|
||||||
|
|
||||||
|
# GET /resource/confirmation/new
|
||||||
|
# def new
|
||||||
|
# super
|
||||||
|
# end
|
||||||
|
|
||||||
|
# POST /resource/confirmation
|
||||||
|
# def create
|
||||||
|
# super
|
||||||
|
# end
|
||||||
|
|
||||||
|
# GET /resource/confirmation?confirmation_token=abcdef
|
||||||
|
# def show
|
||||||
|
# super
|
||||||
|
# end
|
||||||
|
|
||||||
|
# protected
|
||||||
|
|
||||||
|
# The path used after resending confirmation instructions.
|
||||||
|
# def after_resending_confirmation_instructions_path_for(resource_name)
|
||||||
|
# super(resource_name)
|
||||||
|
# end
|
||||||
|
|
||||||
|
# The path used after confirmation.
|
||||||
|
# def after_confirmation_path_for(resource_name, resource)
|
||||||
|
# super(resource_name, resource)
|
||||||
|
# end
|
||||||
|
end
|
|
@ -1,4 +1,16 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
def bootstrap_class_for_flash(flash_type)
|
||||||
|
case flash_type
|
||||||
|
when 'success'
|
||||||
|
'alert-success'
|
||||||
|
when 'error'
|
||||||
|
'alert-danger'
|
||||||
|
when 'alert'
|
||||||
|
'alert-warning'
|
||||||
|
else
|
||||||
|
'alert-info'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
devise(
|
devise(
|
||||||
# :confirmable,
|
:confirmable,
|
||||||
:database_authenticatable,
|
:database_authenticatable,
|
||||||
# :lockable,
|
# :lockable,
|
||||||
# :omniauthable,
|
# :omniauthable,
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<% unless flash.empty? %>
|
||||||
|
<div class="container mt-3">
|
||||||
|
<% flash.each do |type, msg| %>
|
||||||
|
<div class="alert <%= bootstrap_class_for_flash type %> alert-dismissable fade show">
|
||||||
|
<%= msg %>
|
||||||
|
<button class="close" data-dismiss="alert">x</button>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<%= render 'navbar' %>
|
<%= render 'navbar' %>
|
||||||
|
<%= render partial: 'flash', flash: flash %>
|
||||||
<%= yield :top %>
|
<%= yield :top %>
|
||||||
<div class="my-4">
|
<div class="my-4">
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<div class="container">
|
||||||
|
<h2><%= translate '.resend_confirmation_instructions' %></h2>
|
||||||
|
|
||||||
|
<%= simple_form_for resource, as: resource_name, url: confirmation_path(resource_name) do |f| %>
|
||||||
|
<%= f.error_notification %>
|
||||||
|
<%= f.full_error :confirmation_token %>
|
||||||
|
|
||||||
|
<div class="form-inputs">
|
||||||
|
<%= f.input :email,
|
||||||
|
required: true,
|
||||||
|
autofocus: true,
|
||||||
|
value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email),
|
||||||
|
input_html: { autocomplete: 'email' } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.button :submit, translate('.resend_confirmation_instructions') %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render 'users/shared/links' %>
|
||||||
|
</div>
|
|
@ -34,9 +34,12 @@ Rails.application.configure do
|
||||||
# (see config/storage.yml for options).
|
# (see config/storage.yml for options).
|
||||||
config.active_storage.service = :local
|
config.active_storage.service = :local
|
||||||
|
|
||||||
# Don't care if the mailer can't send.
|
# When mail is sent from your application,
|
||||||
config.action_mailer.raise_delivery_errors = false
|
# Letter Opener will open a preview in the browser instead of sending.
|
||||||
|
config.action_mailer.delivery_method = :letter_opener
|
||||||
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
||||||
|
config.action_mailer.perform_deliveries = true
|
||||||
|
config.action_mailer.raise_delivery_errors = true
|
||||||
config.action_mailer.perform_caching = false
|
config.action_mailer.perform_caching = false
|
||||||
|
|
||||||
# Print deprecation notices to the Rails logger.
|
# Print deprecation notices to the Rails logger.
|
||||||
|
|
|
@ -34,12 +34,12 @@ Rails.application.configure do
|
||||||
# Store uploaded files on the local file system in a temporary directory
|
# Store uploaded files on the local file system in a temporary directory
|
||||||
config.active_storage.service = :test
|
config.active_storage.service = :test
|
||||||
|
|
||||||
config.action_mailer.perform_caching = false
|
|
||||||
|
|
||||||
# Tell Action Mailer not to deliver emails to the real world.
|
# Tell Action Mailer not to deliver emails to the real world.
|
||||||
# The :test delivery method accumulates sent emails in the
|
# The :test delivery method accumulates sent emails in the
|
||||||
# ActionMailer::Base.deliveries array.
|
# ActionMailer::Base.deliveries array.
|
||||||
config.action_mailer.delivery_method = :test
|
config.action_mailer.delivery_method = :test
|
||||||
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
||||||
|
config.action_mailer.perform_caching = false
|
||||||
|
|
||||||
# Print deprecation notices to the stderr.
|
# Print deprecation notices to the stderr.
|
||||||
config.active_support.deprecation = :stderr
|
config.active_support.deprecation = :stderr
|
||||||
|
|
|
@ -132,7 +132,7 @@ Devise.setup do |config|
|
||||||
# able to access the website for two days without confirming their account,
|
# able to access the website for two days without confirming their account,
|
||||||
# access will be blocked just in the third day. Default is 0.days, meaning
|
# access will be blocked just in the third day. Default is 0.days, meaning
|
||||||
# the user cannot access the website without confirming their account.
|
# the user cannot access the website without confirming their account.
|
||||||
# config.allow_unconfirmed_access_for = 2.days
|
config.allow_unconfirmed_access_for = 0.days
|
||||||
|
|
||||||
# A period that the user is allowed to confirm their account before their
|
# A period that the user is allowed to confirm their account before their
|
||||||
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
||||||
|
@ -140,7 +140,7 @@ Devise.setup do |config|
|
||||||
# their account can't be confirmed with the token any more.
|
# their account can't be confirmed with the token any more.
|
||||||
# Default is nil, meaning there is no restriction on how long a user can take
|
# Default is nil, meaning there is no restriction on how long a user can take
|
||||||
# before confirming their account.
|
# before confirming their account.
|
||||||
# config.confirm_within = 3.days
|
config.confirm_within = 3.days
|
||||||
|
|
||||||
# If true, requires any email changes to be confirmed (exactly the same way as
|
# If true, requires any email changes to be confirmed (exactly the same way as
|
||||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||||
|
@ -149,7 +149,7 @@ Devise.setup do |config|
|
||||||
config.reconfirmable = true
|
config.reconfirmable = true
|
||||||
|
|
||||||
# Defines which key will be used when confirming an account
|
# Defines which key will be used when confirming an account
|
||||||
# config.confirmation_keys = [:email]
|
config.confirmation_keys = [:email]
|
||||||
|
|
||||||
# ==> Configuration for :rememberable
|
# ==> Configuration for :rememberable
|
||||||
# The time the user will be remembered without asking for credentials again.
|
# The time the user will be remembered without asking for credentials again.
|
||||||
|
|
|
@ -24,6 +24,7 @@ Rails.application.routes.draw do
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
sessions: 'users/sessions',
|
sessions: 'users/sessions',
|
||||||
registrations: 'users/registrations',
|
registrations: 'users/registrations',
|
||||||
|
confirmations: 'users/confirmations',
|
||||||
}
|
}
|
||||||
|
|
||||||
resources :membership_applications, only: %i[new create]
|
resources :membership_applications, only: %i[new create]
|
||||||
|
|
|
@ -5,5 +5,9 @@ FactoryBot.define do
|
||||||
email { Faker::Internet.email }
|
email { Faker::Internet.email }
|
||||||
password { Faker::Internet.password }
|
password { Faker::Internet.password }
|
||||||
password_confirmation { password }
|
password_confirmation { password }
|
||||||
|
|
||||||
|
after :create do |user, _evaluator|
|
||||||
|
user.confirm
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue