Merge pull request #4767 from techAPJ/activate-account

FIX: send activation email if user have unconfirmed email address
This commit is contained in:
Arpit Jalan 2017-03-21 09:44:23 +05:30 committed by GitHub
commit 82c0f5f587
2 changed files with 18 additions and 2 deletions

View File

@ -585,7 +585,7 @@ class UsersController < ApplicationController
session.delete(SessionController::ACTIVATE_USER_KEY)
if @user.active
if @user.active && @user.email_confirmed?
render_json_error(I18n.t('activation.activated'), status: 409)
else
@email_token = @user.email_tokens.unconfirmed.active.first

View File

@ -1424,9 +1424,11 @@ describe UsersController do
context 'for an existing user' do
let(:user) { Fabricate(:user, active: false) }
context 'for an activated account' do
context 'for an activated account with email confirmed' do
it 'fails' do
active_user = Fabricate(:user, active: true)
email_token = active_user.email_tokens.create(email: active_user.email).token
EmailToken.confirm(email_token)
session[SessionController::ACTIVATE_USER_KEY] = active_user.id
xhr :post, :send_activation_email, username: active_user.username
@ -1440,6 +1442,20 @@ describe UsersController do
end
end
context 'for an activated account with unconfirmed email' do
it 'should send an email' do
unconfirmed_email_user = Fabricate(:user, active: true)
unconfirmed_email_user.email_tokens.create(email: unconfirmed_email_user.email)
session[SessionController::ACTIVATE_USER_KEY] = unconfirmed_email_user.id
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
xhr :post, :send_activation_email, username: unconfirmed_email_user.username
expect(response.status).to eq(200)
expect(session[SessionController::ACTIVATE_USER_KEY]).to eq(nil)
end
end
describe 'when user does not have a valid session' do
it 'should not be valid' do
user = Fabricate(:user)