Created
June 28, 2010 20:13
-
-
Save frankjmattia/456297 to your computer and use it in GitHub Desktop.
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
# app/controllers/users/registrations_controller.rb | |
class Users::RegistrationsController < Devise::RegistrationsController | |
def create | |
build_resource | |
if resource.save | |
if resource.respond_to?(:confirm!) && !resource.confirmed? | |
confirmation_hash = Digest::SHA2.hexdigest(resource.password_salt + resource.confirmation_token) | |
redirect_to awaiting_confirmation_path(resource, confirmation_hash) | |
else | |
set_flash_message :notice, :signed_up | |
sign_in_and_redirect(resource_name, resource) | |
end | |
else | |
clean_up_passwords(resource) | |
render_with_scope :new | |
end | |
end | |
end | |
# app/controllers/users/confirmations_controller | |
class Users::ConfirmationsController < Devise::ConfirmationsController | |
def awaiting | |
confirmation_hash = params[:confirmation_hash] | |
resource = User.find(params[:id]) | |
expected_confirmation_hash = Digest::SHA2.hexdigest(resource.password_salt + resource.confirmation_token) | |
if confirmation_hash != expected_confirmation_hash | |
redirect_to new_user_session_path | |
else | |
render :awaiting | |
end | |
end | |
end | |
# app/config/routes.rb | |
devise_for :users, :controllers => { | |
:registrations => "users/registrations", | |
:confirmations => "users/confirmations" | |
} | |
as :user do | |
get "users/confirmation/awaiting/:id/:confirmation_hash" => "users/confirmations#awaiting", :as => "awaiting_confirmation" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment