Commit cf8a5bca authored by Brett Walker's avatar Brett Walker

add verified/unverified labels to profile emails.

added "Resend confirmation email" for unverified emails
parent c56208f9
...@@ -24,6 +24,16 @@ class Profiles::EmailsController < Profiles::ApplicationController ...@@ -24,6 +24,16 @@ class Profiles::EmailsController < Profiles::ApplicationController
end end
end end
def resend_confirmation_instructions
@email = current_user.emails.find(params[:id])
if @email && Emails::ConfirmService.new(current_user, email: @email.email).execute
flash[:notice] = "Confirmation email sent to #{@email.email}"
else
flash[:alert] = "There was a problem sending the confirmation email"
end
redirect_to profile_emails_url
end
private private
def email_params def email_params
......
module Emails
class ConfirmService < ::Emails::BaseService
def execute
Email.find_by_email!(@email).resend_confirmation_instructions
end
end
end
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
All email addresses will be used to identify your commits. All email addresses will be used to identify your commits.
%ul.well-list %ul.well-list
%li %li
= @primary = render partial: 'shared/email_with_badge', locals: { email: @primary, verified: current_user.confirmed? }
%span.pull-right %span.pull-right
%span.label.label-success Primary email %span.label.label-success Primary email
- if @primary === current_user.public_email - if @primary === current_user.public_email
...@@ -41,12 +41,17 @@ ...@@ -41,12 +41,17 @@
%span.label.label-info Notification email %span.label.label-info Notification email
- @emails.each do |email| - @emails.each do |email|
%li %li
= email.email = render partial: 'shared/email_with_badge', locals: { email: email.email, verified: email.confirmed? }
%span.pull-right %span.pull-right
- if email.email === current_user.public_email - if email.email === current_user.public_email
%span.label.label-info Public email %span.label.label-info Public email
- if email.email === current_user.notification_email - if email.email === current_user.notification_email
%span.label.label-info Notification email %span.label.label-info Notification email
- unless email.confirmed? - unless email.confirmed?
%span.label.label-warning Unconfirmed - confirm_title = "#{email.confirmation_sent_at ? 'Resend' : 'Send'} confirmation email"
= link_to 'Remove', profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-warning prepend-left-10' = link_to confirm_title, resend_confirmation_instructions_profile_email_path(email), method: :put, class: 'btn btn-sm btn-warning prepend-left-10'
= link_to profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-danger prepend-left-10' do
%span.sr-only Remove
= icon('trash')
...@@ -28,7 +28,11 @@ resource :profile, only: [:show, :update] do ...@@ -28,7 +28,11 @@ resource :profile, only: [:show, :update] do
put :revoke put :revoke
end end
end end
resources :emails, only: [:index, :create, :destroy] resources :emails, only: [:index, :create, :destroy] do
member do
put :resend_confirmation_instructions
end
end
resources :chat_names, only: [:index, :new, :create, :destroy] do resources :chat_names, only: [:index, :new, :create, :destroy] do
collection do collection do
delete :deny delete :deny
......
...@@ -17,4 +17,19 @@ describe Profiles::EmailsController do ...@@ -17,4 +17,19 @@ describe Profiles::EmailsController do
expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions" expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
end end
end end
describe '#resend_confirmation_instructions' do
let(:email_params) { {email: "add_email@example.com" } }
it 'resends an email confirmation' do
email = user.emails.create(email: 'add_email@example.com')
expect {put(:resend_confirmation_instructions, { id: email })}.to change { ActionMailer::Base.deliveries.size }
expect(ActionMailer::Base.deliveries.last.to).to eq [email_params[:email]]
expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
end
it 'unable to resend an email confirmation' do
expect {put(:resend_confirmation_instructions, { id: 1 })}.to_not change { ActionMailer::Base.deliveries.size }
end
end
end end
...@@ -17,8 +17,8 @@ feature 'Profile > Emails' do ...@@ -17,8 +17,8 @@ feature 'Profile > Emails' do
click_button('Add email address') click_button('Add email address')
expect(page).to have_content('my@email.com Unverified') expect(page).to have_content('my@email.com Unverified')
expect(page).to have_content('user1@example.org Verified') expect(page).to have_content("#{user.email} Verified")
expect(page).to have_content('Resend Confirmation Email') expect(page).to have_content('Resend confirmation email')
end end
scenario 'does not add a duplicate email' do scenario 'does not add a duplicate email' do
...@@ -43,14 +43,30 @@ feature 'Profile > Emails' do ...@@ -43,14 +43,30 @@ feature 'Profile > Emails' do
scenario 'User confirms email' do scenario 'User confirms email' do
email = user.emails.create(email: 'my@email.com') email = user.emails.create(email: 'my@email.com')
visit profile_emails_path visit profile_emails_path
expect(page).to have_content("my@email.com Unverified") expect(page).to have_content("#{email.email} Unverified")
email.confirm email.confirm
expect(email.confirmed?).to be_truthy expect(email.confirmed?).to be_truthy
visit profile_emails_path visit profile_emails_path
expect(page).to have_content("my@email.com Verified") expect(page).to have_content("#{email.email} Verified")
end
scenario 'User re-sends confirmation email' do
email = user.emails.create(email: 'my@email.com')
visit profile_emails_path
expect { click_link("Resend confirmation email") }.to change { ActionMailer::Base.deliveries.size }
expect(page).to have_content("Confirmation email sent to #{email.email}")
end
scenario 'old unconfirmed emails show Send Confirmation button' do
email = user.emails.create(email: 'my@email.com')
email.update_attribute(:confirmation_sent_at, nil)
visit profile_emails_path
expect(page).to_not have_content('Resend confirmation email')
expect(page).to have_content('Send confirmation email')
end end
scenario ''
end end
require 'spec_helper'
describe Emails::ConfirmService do
let(:user) { create(:user) }
let(:opts) { { email: 'new@email.com' } }
subject(:service) { described_class.new(user, opts) }
describe '#execute' do
it 'sends a confirmation email again' do
email = user.emails.create(email: opts[:email])
mail = service.execute
expect(mail.subject).to eq('Confirmation instructions')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment