2017-12-21 17:36:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-24 19:34:13 +00:00
|
|
|
class Devise::UnlocksController < DeviseController
|
2015-08-18 23:42:56 +00:00
|
|
|
prepend_before_action :require_no_authentication
|
2010-02-08 18:07:24 +00:00
|
|
|
|
|
|
|
# GET /resource/unlock/new
|
|
|
|
def new
|
2013-04-14 06:21:46 +00:00
|
|
|
self.resource = resource_class.new
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /resource/unlock
|
|
|
|
def create
|
2012-05-15 08:07:02 +00:00
|
|
|
self.resource = resource_class.send_unlock_instructions(resource_params)
|
2013-11-06 03:33:41 +00:00
|
|
|
yield resource if block_given?
|
2010-02-08 18:07:24 +00:00
|
|
|
|
2011-10-15 08:51:40 +00:00
|
|
|
if successfully_sent?(resource)
|
2014-02-25 16:42:55 +00:00
|
|
|
respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
|
2011-06-21 02:03:01 +00:00
|
|
|
else
|
2012-01-02 21:12:09 +00:00
|
|
|
respond_with(resource)
|
2010-02-08 18:07:24 +00:00
|
|
|
end
|
|
|
|
end
|
2009-12-30 17:19:33 +00:00
|
|
|
|
|
|
|
# GET /resource/unlock?unlock_token=abcdef
|
|
|
|
def show
|
2010-03-10 15:13:54 +00:00
|
|
|
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
2013-11-06 03:33:41 +00:00
|
|
|
yield resource if block_given?
|
2009-12-30 17:19:33 +00:00
|
|
|
|
|
|
|
if resource.errors.empty?
|
2016-02-11 00:45:18 +00:00
|
|
|
set_flash_message! :notice, :unlocked
|
2012-04-17 11:38:50 +00:00
|
|
|
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
2009-12-30 17:19:33 +00:00
|
|
|
else
|
2014-02-25 16:42:55 +00:00
|
|
|
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
2009-12-30 17:19:33 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-17 08:04:06 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# The path used after sending unlock password instructions
|
2012-04-22 13:05:26 +00:00
|
|
|
def after_sending_unlock_instructions_path_for(resource)
|
2013-05-07 08:18:23 +00:00
|
|
|
new_session_path(resource) if is_navigational_format?
|
2012-04-17 08:04:06 +00:00
|
|
|
end
|
|
|
|
|
2012-04-17 11:38:50 +00:00
|
|
|
# The path used after unlocking the resource
|
|
|
|
def after_unlock_path_for(resource)
|
2013-05-07 08:18:23 +00:00
|
|
|
new_session_path(resource) if is_navigational_format?
|
2012-04-17 11:38:50 +00:00
|
|
|
end
|
|
|
|
|
2015-01-07 13:35:45 +00:00
|
|
|
def translation_scope
|
|
|
|
'devise.unlocks'
|
|
|
|
end
|
2009-12-30 17:19:33 +00:00
|
|
|
end
|