Last active
December 29, 2015 20:48
-
-
Save ArunGupta25/7725689 to your computer and use it in GitHub Desktop.
overriding the registrations controller
This file contains hidden or 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
# Sample localization file for English. Add more files in this directory for other locales. | |
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. | |
en: | |
hello: "Hello world" | |
mailboxer: | |
message_mailer: | |
subject_new: "new %{type} from %{sender}" | |
subject_reply: "new %{type} from %{sender}" | |
en: | |
devise: | |
registrations: | |
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." | |
signed_up: "" | |
signed_in: "" | |
signed_out: "" | |
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." | |
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." | |
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." | |
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." | |
updated: "You updated your account successfully." | |
sessions: | |
signed_in: "" | |
signed_out: "" |
This file contains hidden or 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
class RegistrationsController < Devise::RegistrationsController | |
prepend_before_filter :allow_params_authentication!, :only => :create | |
def create | |
user_exists = User.exists?(email: params[:user][:email]) | |
if user_exists | |
build_resource(sign_up_params) | |
self.resource = warden.authenticate!(auth_options) | |
set_flash_message(:notice, :signed_in) if is_flashing_format? | |
sign_in(resource_name, resource) | |
yield resource if block_given? | |
respond_with resource, :location => after_sign_in_path_for(resource) | |
else | |
build_resource(sign_up_params) | |
if resource.save | |
yield resource if block_given? | |
if resource.active_for_authentication? | |
set_flash_message :notice, :signed_up if is_flashing_format? | |
sign_up(resource_name, resource) | |
respond_with resource, :location => after_sign_up_path_for(resource) | |
else | |
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? | |
expire_data_after_sign_in! | |
respond_with resource, :location => after_inactive_sign_up_path_for(resource) | |
end | |
else | |
clean_up_passwords resource | |
respond_with resource | |
end | |
end | |
end | |
protected | |
def sign_in_params | |
devise_parameter_sanitizer.sanitize(:sign_in) | |
end | |
def serialize_options(resource) | |
methods = resource_class.authentication_keys.dup | |
methods = methods.keys if methods.is_a?(Hash) | |
methods << :password if resource.respond_to?(:password) | |
{ :methods => methods, :only => [:password] } | |
end | |
def auth_options | |
{ :scope => resource_name, :recall => "#{controller_path}#new" } | |
end | |
end |
This file contains hidden or 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
devise_for :users, :controllers => { :registrations => "registrations"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
helpful discussion found here: heartcombo/devise#1230