2011-06-25 03:34:13 +08:00
|
|
|
class Devise::ConfirmationsController < DeviseController
|
2010-02-08 19:07:24 +01:00
|
|
|
# GET /resource/confirmation/new
|
|
|
|
def new
|
2013-04-13 23:21:46 -07:00
|
|
|
self.resource = resource_class.new
|
2010-02-08 19:07:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /resource/confirmation
|
|
|
|
def create
|
2012-05-15 18:07:02 +10:00
|
|
|
self.resource = resource_class.send_confirmation_instructions(resource_params)
|
2013-11-06 00:33:41 -03:00
|
|
|
yield resource if block_given?
|
2010-02-08 19:07:24 +01:00
|
|
|
|
2011-10-15 10:51:40 +02:00
|
|
|
if successfully_sent?(resource)
|
2014-02-25 22:12:55 +05:30
|
|
|
respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
|
2011-06-20 22:30:25 -03:00
|
|
|
else
|
2012-01-02 22:12:09 +01:00
|
|
|
respond_with(resource)
|
2010-02-08 19:07:24 +01:00
|
|
|
end
|
|
|
|
end
|
2009-10-08 00:53:04 -03:00
|
|
|
|
2009-11-10 18:55:13 -02:00
|
|
|
# GET /resource/confirmation?confirmation_token=abcdef
|
2009-10-08 00:53:04 -03:00
|
|
|
def show
|
2010-03-10 16:13:54 +01:00
|
|
|
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
|
2013-11-06 00:33:41 -03:00
|
|
|
yield resource if block_given?
|
2009-10-12 08:37:28 -03:00
|
|
|
|
2009-10-11 22:11:58 -03:00
|
|
|
if resource.errors.empty?
|
2013-11-01 21:47:40 +01:00
|
|
|
set_flash_message(:notice, :confirmed) if is_flashing_format?
|
2011-07-08 11:21:01 +02:00
|
|
|
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
2009-10-08 00:53:04 -03:00
|
|
|
else
|
2014-02-25 22:12:55 +05:30
|
|
|
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
2009-10-08 00:53:04 -03:00
|
|
|
end
|
|
|
|
end
|
2011-04-15 15:39:54 +08:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# The path used after resending confirmation instructions.
|
|
|
|
def after_resending_confirmation_instructions_path_for(resource_name)
|
2013-05-07 10:18:23 +02:00
|
|
|
new_session_path(resource_name) if is_navigational_format?
|
2011-04-15 15:39:54 +08:00
|
|
|
end
|
2011-07-08 11:21:01 +02:00
|
|
|
|
|
|
|
# The path used after confirmation.
|
|
|
|
def after_confirmation_path_for(resource_name, resource)
|
2013-09-16 10:12:15 -04:00
|
|
|
if signed_in?
|
|
|
|
signed_in_root_path(resource)
|
|
|
|
else
|
|
|
|
new_session_path(resource_name)
|
|
|
|
end
|
2011-07-08 11:21:01 +02:00
|
|
|
end
|
2009-10-08 00:53:04 -03:00
|
|
|
end
|