Last active
May 18, 2016 14:03
-
-
Save Ikera/bd1912330a23e0238459dcc8f30d05ce to your computer and use it in GitHub Desktop.
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
In overrides/confirmations_controller.rb: | |
module Overrides | |
class ConfirmationsController < DeviseTokenAuth::ConfirmationsController | |
def create | |
unless params[:email] | |
return render json: { | |
success: false, | |
errors: ['You must provide an email address.'] | |
}, status: 400 | |
end | |
unless params[:redirect_url] | |
return render json: { | |
success: false, | |
errors: ['Missing redirect url.'] | |
}, status: 400 | |
end | |
if resource_class.case_insensitive_keys.include?(:email) | |
email = params[:email].downcase | |
else | |
email = params[:email] | |
end | |
q = "uid = ? AND provider='email'" | |
# fix for mysql default case insensitivity | |
if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql' | |
q = "BINARY uid = ? AND provider='email'" | |
end | |
@resource = resource_class.where(q, email).first | |
errors = nil | |
if @resource && @resource.confirmed? | |
return render json: { | |
success: false, | |
errors: ['You email address is already confirmed.'] | |
}, status: 400 | |
end | |
if @resource | |
@resource.send_confirmation_instructions({ | |
redirect_url: params[:confirm_success_url], | |
client_config: params[:config_name] | |
}) | |
else | |
errors = ["Unable to find user with email '#{email}'."] | |
end | |
if errors | |
render json: { | |
success: false, | |
errors: errors | |
}, status: 400 | |
else | |
render json: { | |
status: 'success', | |
data: @resource.as_json | |
} | |
end | |
end | |
end | |
end | |
In route: | |
mount_devise_token_auth_for 'User', at: 'auth', skip: [:omniauth_callbacks], :controllers => { confirmations: "overrides/confirmations", passwords: "overrides/passwords" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment