Class: Droom::UserConfirmationsController

Inherits:
Devise::ConfirmationsController
  • Object
show all
Defined in:
app/controllers/droom/user_confirmations_controller.rb

Instance Method Summary collapse

Instance Method Details

#after_confirmation_path_for(resource_name, resource) ⇒ Object



42
43
44
# File 'app/controllers/droom/user_confirmations_controller.rb', line 42

def after_confirmation_path_for(resource_name, resource)
  dashboard_url
end

#showObject

If user not yet confirmed, show password form (rather than just confirming, as is normal) If already confirmed, allow devise to do whatever a devise does.



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/droom/user_confirmations_controller.rb', line 7

def show
  if self.resource = resource_class.find_by_id_and_confirmation_token(params[:id], params[:confirmation_token])
    redirect_to (resource) if resource.confirmed?
    # or we render user_confirmations/show
  elsif user_signed_in?
    redirect_to (current_user)
  else
    render :template => "devise/confirmations/failure" 
  end
end

#updateObject

the purpose of this is to add another step between user creation and user confirmation, such that we perform the confirmation only if a password is supplied and validates.

NB. in the tortured RESTfulness of devise, that means turning confirmation#show into a password form and using confirmations#update to update the user object accordingly.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/droom/user_confirmations_controller.rb', line 24

def update
  if self.resource = resource_class.where(id: params[:id], confirmation_token: params[resource_name][:confirmation_token]).first
    result = resource.update_attributes(permitted_params)
    if result && resource.password_match?
      set_flash_message :notice, :confirmed
      resource.confirm!
      (resource_name, resource)
      respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
    else
      # back to the password form
      set_flash_message :error, :password_error
      render :action => "show"
    end
  else
    render :template => "devise/confirmations/failure"
  end
end