2011-06-25 03:34:13 +08:00
|
|
|
class Devise::UnlocksController < DeviseController
|
2010-03-26 08:26:51 -03:00
|
|
|
prepend_before_filter :require_no_authentication
|
2010-02-08 19:07:24 +01:00
|
|
|
|
|
|
|
# GET /resource/unlock/new
|
|
|
|
def new
|
2010-07-13 19:46:44 +02:00
|
|
|
build_resource({})
|
2010-02-08 19:07:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /resource/unlock
|
|
|
|
def create
|
2012-05-15 18:07:02 +10:00
|
|
|
self.resource = resource_class.send_unlock_instructions(resource_params)
|
2010-02-08 19:07:24 +01:00
|
|
|
|
2011-10-15 10:51:40 +02:00
|
|
|
if successfully_sent?(resource)
|
2012-04-22 10:05:26 -03:00
|
|
|
respond_with({}, :location => after_sending_unlock_instructions_path_for(resource))
|
2011-06-20 23:03:01 -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-12-30 15:19:33 -02:00
|
|
|
|
|
|
|
# GET /resource/unlock?unlock_token=abcdef
|
|
|
|
def show
|
2010-03-10 16:13:54 +01:00
|
|
|
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
2009-12-30 15:19:33 -02:00
|
|
|
|
|
|
|
if resource.errors.empty?
|
2011-01-16 19:20:19 +07:00
|
|
|
set_flash_message :notice, :unlocked if is_navigational_format?
|
2012-04-17 13:38:50 +02:00
|
|
|
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
2009-12-30 15:19:33 -02:00
|
|
|
else
|
2012-01-02 22:01:28 +01:00
|
|
|
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
2009-12-30 15:19:33 -02:00
|
|
|
end
|
|
|
|
end
|
2012-04-17 10:04:06 +02:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# The path used after sending unlock password instructions
|
2012-04-22 10:05:26 -03:00
|
|
|
def after_sending_unlock_instructions_path_for(resource)
|
2012-04-17 10:04:06 +02:00
|
|
|
new_session_path(resource)
|
|
|
|
end
|
|
|
|
|
2012-04-17 13:38:50 +02:00
|
|
|
# The path used after unlocking the resource
|
|
|
|
def after_unlock_path_for(resource)
|
|
|
|
new_session_path(resource)
|
|
|
|
end
|
|
|
|
|
2009-12-30 15:19:33 -02:00
|
|
|
end
|