1
0
Fork 0

Enable Devise confirmable

This commit is contained in:
Alex Kotov 2018-12-03 22:58:39 +05:00
parent c3722e7559
commit 3daf5ce67f
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
13 changed files with 102 additions and 9 deletions

View File

@ -141,6 +141,10 @@ group :development do
# YARD is a documentation generation tool for the Ruby programming language.
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
group :test do

View File

@ -163,6 +163,8 @@ GEM
json (2.1.0)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.6.0)
launchy (~> 2.2)
libv8 (6.7.288.46.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
@ -384,6 +386,7 @@ DEPENDENCIES
font-awesome-sass (~> 5.5.0)
interactor (~> 3.1)
jquery-rails (~> 4.3)
letter_opener (~> 1.6)
listen (>= 3.0.5, < 3.2)
mini_racer
pg (>= 0.18, < 2.0)

View File

@ -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

View File

@ -1,4 +1,16 @@
# frozen_string_literal: true
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

View File

@ -2,7 +2,7 @@
class User < ApplicationRecord
devise(
# :confirmable,
:confirmable,
:database_authenticatable,
# :lockable,
# :omniauthable,

View File

@ -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 %>

View File

@ -16,6 +16,7 @@
<body>
<%= render 'navbar' %>
<%= render partial: 'flash', flash: flash %>
<%= yield :top %>
<div class="my-4">
<%= yield %>

View File

@ -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>

View File

@ -34,9 +34,12 @@ Rails.application.configure do
# (see config/storage.yml for options).
config.active_storage.service = :local
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# When mail is sent from your application,
# 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
# Print deprecation notices to the Rails logger.

View File

@ -34,12 +34,12 @@ Rails.application.configure do
# Store uploaded files on the local file system in a temporary directory
config.active_storage.service = :test
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
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.
config.active_support.deprecation = :stderr

View File

@ -132,7 +132,7 @@ Devise.setup do |config|
# 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
# 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
# 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.
# Default is nil, meaning there is no restriction on how long a user can take
# 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
# initial account confirmation) to be applied. Requires additional unconfirmed_email
@ -149,7 +149,7 @@ Devise.setup do |config|
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [:email]
config.confirmation_keys = [:email]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.

View File

@ -24,6 +24,7 @@ Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations',
confirmations: 'users/confirmations',
}
resources :membership_applications, only: %i[new create]

View File

@ -5,5 +5,9 @@ FactoryBot.define do
email { Faker::Internet.email }
password { Faker::Internet.password }
password_confirmation { password }
after :create do |user, _evaluator|
user.confirm
end
end
end