2010-02-17 06:25:20 -05:00
|
|
|
class Devise::RegistrationsController < ApplicationController
|
2010-07-15 15:58:35 -04:00
|
|
|
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
2010-03-26 07:26:51 -04:00
|
|
|
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
2010-01-23 19:26:06 -05:00
|
|
|
include Devise::Controllers::InternalHelpers
|
|
|
|
|
2010-02-24 05:12:51 -05:00
|
|
|
# GET /resource/sign_up
|
2010-02-08 13:07:24 -05:00
|
|
|
def new
|
2010-04-01 07:11:02 -04:00
|
|
|
build_resource({})
|
2010-02-08 13:07:24 -05:00
|
|
|
render_with_scope :new
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /resource/sign_up
|
2010-01-23 19:26:06 -05:00
|
|
|
def create
|
2010-02-08 13:07:24 -05:00
|
|
|
build_resource
|
2010-01-23 19:26:06 -05:00
|
|
|
|
|
|
|
if resource.save
|
2010-09-30 03:12:00 -04:00
|
|
|
if resource.active?
|
|
|
|
set_flash_message :notice, :signed_up
|
|
|
|
sign_in_and_redirect(resource_name, resource)
|
|
|
|
else
|
|
|
|
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
|
2010-10-14 18:44:21 -04:00
|
|
|
expire_session_data_after_sign_in!
|
2010-09-30 03:12:00 -04:00
|
|
|
redirect_to after_inactive_sign_up_path_for(resource)
|
|
|
|
end
|
2010-01-23 19:26:06 -05:00
|
|
|
else
|
2010-04-01 07:11:02 -04:00
|
|
|
clean_up_passwords(resource)
|
2010-01-23 19:26:06 -05:00
|
|
|
render_with_scope :new
|
|
|
|
end
|
|
|
|
end
|
2010-02-08 13:07:24 -05:00
|
|
|
|
|
|
|
# GET /resource/edit
|
|
|
|
def edit
|
|
|
|
render_with_scope :edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /resource
|
|
|
|
def update
|
2010-03-03 06:12:06 -05:00
|
|
|
if resource.update_with_password(params[resource_name])
|
2010-02-08 13:07:24 -05:00
|
|
|
set_flash_message :notice, :updated
|
2010-09-25 11:24:42 -04:00
|
|
|
sign_in resource_name, resource, :bypass => true
|
2010-05-24 16:50:25 -04:00
|
|
|
redirect_to after_update_path_for(resource)
|
2010-02-08 13:07:24 -05:00
|
|
|
else
|
2010-04-01 07:11:02 -04:00
|
|
|
clean_up_passwords(resource)
|
2010-02-08 13:07:24 -05:00
|
|
|
render_with_scope :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /resource
|
|
|
|
def destroy
|
2010-03-03 06:12:06 -05:00
|
|
|
resource.destroy
|
2010-02-08 13:07:24 -05:00
|
|
|
sign_out_and_redirect(self.resource)
|
2010-10-10 10:45:55 -04:00
|
|
|
set_flash_message :notice, :destroyed
|
2010-02-08 13:07:24 -05:00
|
|
|
end
|
|
|
|
|
2010-07-15 15:58:35 -04:00
|
|
|
# GET /resource/cancel
|
|
|
|
# Forces the session data which is usually expired after sign
|
2010-08-23 16:51:37 -04: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 15:58:35 -04:00
|
|
|
def cancel
|
|
|
|
expire_session_data_after_sign_in!
|
|
|
|
redirect_to new_registration_path(resource_name)
|
|
|
|
end
|
|
|
|
|
2010-02-08 13:07:24 -05:00
|
|
|
protected
|
|
|
|
|
2010-07-15 12:13:55 -04: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 07:47:13 -04:00
|
|
|
# The path used after sign up. You need to overwrite this method
|
|
|
|
# in your own RegistrationsController.
|
2010-09-30 03:12:00 -04:00
|
|
|
def after_sign_up_path_for(resource)
|
|
|
|
after_sign_in_path_for(resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
|
|
|
|
def redirect_for_sign_in(scope, resource) #:nodoc:
|
|
|
|
redirect_to stored_location_for(scope) || after_sign_up_path_for(resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
if defined?(super)
|
|
|
|
ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
|
|
|
|
"is deprecated. Please add a RegistrationsController to your application and define it there."
|
|
|
|
super
|
|
|
|
else
|
|
|
|
after_sign_in_path_for(resource)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-03 06:12:06 -05:00
|
|
|
# Authenticates the current scope and gets a copy of the current resource.
|
|
|
|
# We need to use a copy because we don't want actions like update changing
|
|
|
|
# the current user in place.
|
2010-02-08 13:07:24 -05:00
|
|
|
def authenticate_scope!
|
|
|
|
send(:"authenticate_#{resource_name}!")
|
2010-10-10 11:51:12 -04:00
|
|
|
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
2010-02-08 13:07:24 -05:00
|
|
|
end
|
2010-02-24 05:12:51 -05:00
|
|
|
end
|