Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign in user after confimation success #1282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions app/controllers/devise_token_auth/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

module DeviseTokenAuth
class ConfirmationsController < DeviseTokenAuth::ApplicationController
def create
return head :bad_request if params[:email].blank?

@resource = resource_class.dta_find_by(uid: params[:email].downcase, provider: provider)

return head :not_found unless @resource

@resource.send_confirmation_instructions({
redirect_url: redirect_url,
client_config: params[:config_name]
})

head :ok
end

def show
@resource = resource_class.confirm_by_token(params[:confirmation_token])
Expand All @@ -11,39 +25,21 @@ def show

redirect_header_options = { account_confirmation_success: true }

if signed_in?(resource_name)
client_id, token = signed_in_resource.create_token
client_id, token = @resource.create_token
Copy link
Collaborator

@MaicolBen MaicolBen May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this as http://blog.plataformatec.com.br/2013/08/devise-3-1-now-with-more-secure-defaults/, we weren't doing anything with the tokens previously, so it doesn't make sense to create new tokens here.


redirect_headers = build_redirect_headers(token,
client_id,
redirect_header_options)
sign_in(:user, @resource, store: false, bypass: false)
@resource.save!

redirect_to_link = signed_in_resource.build_auth_url(redirect_url, redirect_headers)
else
redirect_to_link = DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
end
redirect_headers = build_redirect_headers(token,
client_id,
redirect_header_options)

redirect_to(redirect_to_link)
redirect_to(@resource.build_auth_url(redirect_url, redirect_headers))
else
raise ActionController::RoutingError, 'Not Found'
end
end

def create
return head :bad_request if params[:email].blank?

@resource = resource_class.dta_find_by(uid: params[:email].downcase, provider: provider)

return head :not_found unless @resource

@resource.send_confirmation_instructions({
redirect_url: redirect_url,
client_config: params[:config_name]
})

head :ok
end

private

# give redirect value from params priority or fall back to default value if provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,6 @@ def token_and_client_config_from(body)
end
end

describe 'when unauthenticated' do
before do
sign_out(@new_user)
get :show,
params: { confirmation_token: @token,
redirect_url: @redirect_url },
xhr: true
@resource = assigns(:resource)
end

test 'user should now be confirmed' do
assert @resource.confirmed?
end

test 'should redirect to success url' do
assert_redirected_to(/^#{@redirect_url}/)
end

test 'redirect url does not include token params' do
refute @token_params.any? { |param| response.body.include?(param) }
assert response.body.include?('account_confirmation_success')
end
end

describe 'resend confirmation' do
before do
post :create,
Expand Down