-
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.
Merge pull request #196 from Sun-Mountain/91-feature-confirmation-on-…
…registration 91 - User confirmation
- Loading branch information
Showing
43 changed files
with
426 additions
and
71 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
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
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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
# require './lib/redis_store/mail_throttle_store' | ||
|
||
class ConfirmationsController < Devise::ConfirmationsController | ||
skip_before_action :authenticate_user | ||
before_action :token | ||
respond_to :json | ||
|
||
def create | ||
if token | ||
return render json: { status: 403, message: 'There was an issue.' }, status: :forbidden unless find_user_by_token | ||
if @user.confirm | ||
render json: { status: 201 }, status: :ok | ||
else | ||
render json: { err: @event.errors.full_messages }, status: 503 | ||
end | ||
elsif find_user_by_email | ||
return render json: { status: 403, message: 'There was an issue.' }, status: :forbidden if @user.confirmed? | ||
@user.send_confirmation_instructions | ||
else | ||
render json: { err: @event.errors.full_messages }, status: 503 | ||
end | ||
end | ||
|
||
private | ||
|
||
def after_confirmation_path_for(resource_name, resource) | ||
sign_in(resource) | ||
end | ||
|
||
def confirmation_params | ||
params.require(:confirmation).permit(:token, :email) | ||
end | ||
|
||
def token | ||
@token = confirmation_params[:token] | ||
end | ||
|
||
def find_user_by_email | ||
@user = User.find_by_email(confirmation_params[:email]) | ||
end | ||
|
||
def find_user_by_token | ||
@user = User.find_by_confirmation_token(@token) | ||
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
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module MailerHelper | ||
def last_email | ||
ActionMailer::Base.deliveries.last | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationMailer < ActionMailer::Base | ||
default from: '[email protected]' | ||
default from: '[email protected]' | ||
layout 'mailer' | ||
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
5 changes: 5 additions & 0 deletions
5
api/app/views/devise/mailer/confirmation_instructions.html.erb
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,5 @@ | ||
<p>Welcome <%= @email %>!</p> | ||
|
||
<p>You can confirm your account email through the link below:</p> | ||
|
||
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p> |
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,7 @@ | ||
<p>Hello <%= @email %>!</p> | ||
|
||
<% if @resource.try(:unconfirmed_email?) %> | ||
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p> | ||
<% else %> | ||
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p>Hello <%= @resource.email %>!</p> | ||
|
||
<p>We're contacting you to notify you that your password has been changed.</p> |
8 changes: 8 additions & 0 deletions
8
api/app/views/devise/mailer/reset_password_instructions.html.erb
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,8 @@ | ||
<p>Hello <%= @resource.email %>!</p> | ||
|
||
<p>Someone has requested a link to change your password. You can do this through the link below.</p> | ||
|
||
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p> | ||
|
||
<p>If you didn't request this, please ignore this email.</p> | ||
<p>Your password won't change until you access the link above and create a new one.</p> |
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,7 @@ | ||
<p>Hello <%= @resource.email %>!</p> | ||
|
||
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p> | ||
|
||
<p>Click the link below to unlock your account:</p> | ||
|
||
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p> |
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
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 |
---|---|---|
|
@@ -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 = '4cecc8861ba24d331afadba33aa48de813c7821fb5cee779fb8fe0b70698467e49148d31df264f1d300f1a9ccb667e928c493e7932ab18fcf267735296f5592b' | ||
# config.secret_key = '4cecc8861ba24d331afadba33aa48de813c7821fb5cee779fb8fe0b70698467e49148d31df264f1d300f1a9ccb667e928c493e7932ab18fcf267735296f5592b' | ||
|
||
# ==> Controller configuration | ||
# Configure the parent class to the devise controllers. | ||
|
@@ -24,7 +24,7 @@ | |
# Configure the e-mail address which will be shown in Devise::Mailer, | ||
# note that it will be overwritten if you use your own mailer class | ||
# with default "from" parameter. | ||
config.mailer_sender = '[email protected]' | ||
config.mailer_sender = '[email protected]' | ||
|
||
# Configure the class responsible to send e-mails. | ||
# config.mailer = 'Devise::Mailer' | ||
|
@@ -143,7 +143,7 @@ | |
# without confirming their account. | ||
# 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 = nil | ||
|
||
# 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 | ||
|
@@ -157,7 +157,7 @@ | |
# initial account confirmation) to be applied. Requires additional unconfirmed_email | ||
# db field (see migrations). Until confirmed, new email is stored in | ||
# unconfirmed_email column, and copied to email column on successful confirmation. | ||
config.reconfirmable = true | ||
config.reconfirmable = false | ||
|
||
# Defines which key will be used when confirming an account | ||
# config.confirmation_keys = [:email] | ||
|
@@ -167,7 +167,7 @@ | |
# config.remember_for = 2.weeks | ||
|
||
# Invalidates all the remember me tokens when the user signs out. | ||
config.expire_all_remember_me_on_sign_out = true | ||
# config.expire_all_remember_me_on_sign_out = true | ||
|
||
# If true, extends the user's remember period when remembered via cookie. | ||
# config.extend_remember_period = false | ||
|
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
Oops, something went wrong.