2010-02-17 11:25:20 +00:00
|
|
|
class Devise::RegistrationsController < ApplicationController
|
2010-07-15 19:58:35 +00:00
|
|
|
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
2010-03-26 11:26:51 +00:00
|
|
|
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
2010-01-24 00:26:06 +00:00
|
|
|
include Devise::Controllers::InternalHelpers
|
|
|
|
|
2010-02-24 10:12:51 +00:00
|
|
|
# GET /resource/sign_up
|
2010-02-08 18:07:24 +00:00
|
|
|
def new
|
2011-04-19 06:35:03 +00:00
|
|
|
resource = build_resource({})
|
|
|
|
respond_with_navigational(resource){ render_with_scope :new }
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
|
|
|
|
2011-01-02 22:17:48 +00:00
|
|
|
# POST /resource
|
2010-01-24 00:26:06 +00:00
|
|
|
def create
|
2010-02-08 18:07:24 +00:00
|
|
|
build_resource
|
2010-01-24 00:26:06 +00:00
|
|
|
|
|
|
|
if resource.save
|
2011-03-25 14:40:21 +00:00
|
|
|
if resource.active_for_authentication?
|
2011-01-16 12:06:16 +00:00
|
|
|
set_flash_message :notice, :signed_up if is_navigational_format?
|
|
|
|
sign_in(resource_name, resource)
|
2011-09-29 11:07:13 +00:00
|
|
|
respond_with resource, :location => after_sign_up_path_for(resource)
|
2010-09-30 07:12:00 +00:00
|
|
|
else
|
2011-08-02 08:18:23 +00:00
|
|
|
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
|
2010-10-14 22:44:21 +00:00
|
|
|
expire_session_data_after_sign_in!
|
2011-01-16 12:06:16 +00:00
|
|
|
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
|
2010-09-30 07:12:00 +00:00
|
|
|
end
|
2010-01-24 00:26:06 +00:00
|
|
|
else
|
2010-04-01 11:11:02 +00:00
|
|
|
clean_up_passwords(resource)
|
2011-03-30 12:09:12 +00:00
|
|
|
respond_with_navigational(resource) { render_with_scope :new }
|
2010-01-24 00:26:06 +00:00
|
|
|
end
|
|
|
|
end
|
2010-02-08 18:07:24 +00:00
|
|
|
|
|
|
|
# GET /resource/edit
|
|
|
|
def edit
|
|
|
|
render_with_scope :edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /resource
|
2011-04-22 16:08:09 +00:00
|
|
|
# We need to use a copy of the resource because we don't want to change
|
|
|
|
# the current user in place.
|
2010-02-08 18:07:24 +00:00
|
|
|
def update
|
2011-04-22 16:08:09 +00:00
|
|
|
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
|
|
|
|
2010-03-03 11:12:06 +00:00
|
|
|
if resource.update_with_password(params[resource_name])
|
2011-12-04 21:14:44 +00:00
|
|
|
if is_navigational_format?
|
|
|
|
if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
|
|
|
|
flash_key = :update_needs_confirmation
|
|
|
|
end
|
|
|
|
set_flash_message :notice, flash_key || :updated
|
|
|
|
end
|
2010-09-25 15:24:42 +00:00
|
|
|
sign_in resource_name, resource, :bypass => true
|
2011-01-16 12:06:16 +00:00
|
|
|
respond_with resource, :location => after_update_path_for(resource)
|
2010-02-08 18:07:24 +00:00
|
|
|
else
|
2010-04-01 11:11:02 +00:00
|
|
|
clean_up_passwords(resource)
|
2011-03-30 12:09:12 +00:00
|
|
|
respond_with_navigational(resource){ render_with_scope :edit }
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /resource
|
|
|
|
def destroy
|
2010-03-03 11:12:06 +00:00
|
|
|
resource.destroy
|
2011-01-16 12:06:16 +00:00
|
|
|
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
|
|
|
set_flash_message :notice, :destroyed if is_navigational_format?
|
2011-03-30 12:09:12 +00:00
|
|
|
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
|
|
|
|
2010-07-15 19:58:35 +00:00
|
|
|
# GET /resource/cancel
|
|
|
|
# Forces the session data which is usually expired after sign
|
2010-08-23 20:51:37 +00:00
|
|
|
# in to be expired now. This is useful if the user wants to
|
|
|
|
# cancel oauth signing in/up in the middle of the process,
|
|
|
|
# removing all OAuth session data.
|
2010-07-15 19:58:35 +00:00
|
|
|
def cancel
|
|
|
|
expire_session_data_after_sign_in!
|
|
|
|
redirect_to new_registration_path(resource_name)
|
|
|
|
end
|
|
|
|
|
2010-02-08 18:07:24 +00:00
|
|
|
protected
|
|
|
|
|
2010-07-15 16:13:55 +00:00
|
|
|
# Build a devise resource passing in the session. Useful to move
|
|
|
|
# temporary session data to the newly created user.
|
|
|
|
def build_resource(hash=nil)
|
|
|
|
hash ||= params[resource_name] || {}
|
|
|
|
self.resource = resource_class.new_with_session(hash, session)
|
|
|
|
end
|
|
|
|
|
2010-09-30 11:47:13 +00:00
|
|
|
# The path used after sign up. You need to overwrite this method
|
|
|
|
# in your own RegistrationsController.
|
2010-09-30 07:12:00 +00:00
|
|
|
def after_sign_up_path_for(resource)
|
|
|
|
after_sign_in_path_for(resource)
|
|
|
|
end
|
|
|
|
|
2011-08-02 08:18:23 +00:00
|
|
|
# Returns the inactive reason translated.
|
|
|
|
def inactive_reason(resource)
|
|
|
|
reason = resource.inactive_message.to_s
|
|
|
|
I18n.t("devise.registrations.reasons.#{reason}", :default => reason)
|
|
|
|
end
|
|
|
|
|
2010-09-30 07:12:00 +00:00
|
|
|
# The path used after sign up for inactive accounts. You need to overwrite
|
|
|
|
# this method in your own RegistrationsController.
|
|
|
|
def after_inactive_sign_up_path_for(resource)
|
|
|
|
root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
# The default url to be used after updating a resource. You need to overwrite
|
|
|
|
# this method in your own RegistrationsController.
|
|
|
|
def after_update_path_for(resource)
|
2011-09-29 11:07:13 +00:00
|
|
|
signed_in_root_path(resource)
|
2010-09-30 07:12:00 +00:00
|
|
|
end
|
|
|
|
|
2011-04-22 16:08:09 +00:00
|
|
|
# Authenticates the current scope and gets the current resource from the session.
|
2010-02-08 18:07:24 +00:00
|
|
|
def authenticate_scope!
|
2011-09-14 23:51:08 +00:00
|
|
|
send(:"authenticate_#{resource_name}!", :force => true)
|
2011-04-22 16:08:09 +00:00
|
|
|
self.resource = send(:"current_#{resource_name}")
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
2010-02-24 10:12:51 +00:00
|
|
|
end
|