-
Notifications
You must be signed in to change notification settings - Fork 2
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 #327 from debtcollective/od/email-confirmation
Send email confirmation if there's a user with the same email on Discourse
- Loading branch information
Showing
20 changed files
with
352 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserConfirmationsController < ApplicationController | ||
layout "minimal" | ||
|
||
# GET /user_confirmations?confirmation_token=abcdef | ||
def index | ||
@confirmation_token = params[:confirmation_token] | ||
@user = User.find_by_confirmation_token(@confirmation_token) | ||
|
||
respond_to do |format| | ||
if @user | ||
format.html { render :index, status: :ok } | ||
else | ||
format.html { render :index, status: :not_found } | ||
end | ||
end | ||
end | ||
|
||
# POST /user_confirmations | ||
def create | ||
user = User.send_confirmation_instructions(email: current_user&.email || params[:email]) | ||
|
||
respond_to do |format| | ||
if user.errors.empty? | ||
format.json { render json: {status: "success", message: "Confirmation email sent"}, status: :ok } | ||
else | ||
format.json { render json: {status: "failed", message: "Invalid confirmation token"}, status: :not_found } | ||
end | ||
end | ||
end | ||
|
||
# POST /user_confirmations/confirm | ||
def confirm | ||
@user = User.confirm_by_token(user_confirmation_params[:confirmation_token]) | ||
@user_confirmed = @user.errors.empty? | ||
|
||
respond_to do |format| | ||
if @user_confirmed | ||
# run the Discourse link account job to fetch and link with a Discourse account | ||
LinkDiscourseAccountJob.perform_later(@user) | ||
|
||
format.html { render :confirm, notice: "Email confirmed", status: :ok } | ||
format.json { render json: {status: "success", message: "Email confirmed"}, status: :ok } | ||
else | ||
format.html { render :confirm, notice: "Invalid confirmation token", status: :not_found } | ||
format.json { render json: {status: "failed", message: "Invalid confirmation token"}, status: :not_found } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_confirmation_params | ||
params.require(:user_confirmation).permit(:confirmation_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
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,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Membership</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<%= csrf_meta_tags %> | ||
<%= csp_meta_tag %> | ||
<%= content_for?(:head) ? yield(:head) : '' %> | ||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> | ||
<link href="https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@300;400;500;700&display=swap" rel="stylesheet" /> | ||
|
||
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon.png" /> | ||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" /> | ||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" /> | ||
<link rel="manifest" href="/site.webmanifest" /> | ||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" /> | ||
<meta name="msapplication-TileColor" content="#da532c" /> | ||
<meta name="theme-color" content="#ffffff" /> | ||
|
||
<%= render 'layouts/sentry' %> | ||
<%= render 'shared/analytics_scripts'%> | ||
</head> | ||
|
||
<body> | ||
<div class="content"> | ||
<%= yield %> | ||
</div> | ||
</body> | ||
</html> |
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 @@ | ||
<% if @user_confirmed %> | ||
<p>Your account is now confirmed. Please visit your personalized hub by clicking the link below.</p> | ||
|
||
<a href="<%= ENV["MEMBER_HUB_URL"]%>" class="button primary">Go to Member Hub</a> | ||
<% else %> | ||
<p>Your email is not confirmed.</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,19 @@ | ||
<% if @user %> | ||
<% if @user.confirmed?%> | ||
<p>This email has been already confirmed</p> | ||
<% else %> | ||
<p>Please click the button below to confirm your email</p> | ||
|
||
<%= form_with(url: confirm_user_confirmations_path, method: 'post', local: true) do %> | ||
<%= fields_for(:user_confirmation) do |f|%> | ||
<%= f.hidden_field(:confirmation_token, value: @confirmation_token) %> | ||
|
||
<div class="form-row"> | ||
<button id="submit-payment" type="submit" class="button primary">Confirm my email</button> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<p>Invalid confirmation token</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,34 @@ | ||
<container> | ||
<row> | ||
<columns large="12"> | ||
<spacer size="24"></spacer> | ||
<h5>Hello <strong><%= @user.name %></strong></h5> | ||
|
||
<p> | ||
We need to confirm your email address. Please click the button below. | ||
</p> | ||
|
||
<spacer size="12"></spacer> | ||
|
||
<button | ||
target="_blank" | ||
href="<%= confirm_user_confirmations_url(confirmation_token: @confirmation_token) %>" | ||
class="expanded" | ||
> | ||
Confirm your email | ||
</button> | ||
|
||
<spacer size="12"></spacer> | ||
|
||
<p> | ||
If you have any questions, please feel free to reach out to us at | ||
admin@debtcollective.org. | ||
</p> | ||
|
||
<p> | ||
In solidarity,<br /> | ||
Debt Collective | ||
</p> | ||
</columns> | ||
</row> | ||
</container> |
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,7 @@ | ||
class AddUserConfirmation < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :users, :confirmation_token, :string, index: true | ||
add_column :users, :confirmed_at, :datetime | ||
add_column :users, :confirmation_sent_at, :datetime | ||
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
Oops, something went wrong.