回復可能な機能に関するいくつかのディスカッションやトピックを見つけましたが、直面した問題を修正できませんでした。Devise(API経由)recoverable:reset_password_tokenを空白にすることはできません。
私はそれが(ポストマンで)のJSON resonseを送信し、パスワードを更新しようとすると、すべてのルートがうまく働いたがされている(工夫2.2.4で)レール3.2バックエンド を使用してフロントエンドAPIを持っています。
の1- POST#POST /リソース/パスワードを(パラメータとして使用)電子メールへのリセットパスワードその後、 2 - 私はGET /リソース/パスワード/編集を行うことを送信します。私は、機能を理解していれば
"reset_password_token" : "can't be blank"
?reset_password_token = abcdefパスワード入力を使ってFrontEndページに移動します。 パスワードが変更されたとき#PUT/resource/passwordを起動します
ここでエラーが発生します。ここで
はpassword_controller.rbファイルです:class Devise::PasswordsController < DeviseController
prepend_before_filter :require_no_authentication
# Render the #edit only if coming from a reset password email link
append_before_filter :assert_reset_token_passed, :only => [:edit, :update]
# GET /resource/password/new
def new
build_resource({})
end
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(resource_params)
if successfully_sent?(resource)
#respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
render json: { message: "mail sent"}, status: 200
else
#respond_with(resource)
render json: { :status }
end
end
# GET /resource/password/edit?reset_password_token=abcdef
def edit
self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token]
end
# PUT /resource/password
def update
self.resource = resource_class.reset_password_by_token(params[:reset_password_token])
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
#sign_in(resource_name, resource)
#respond_with resource, :location => after_resetting_password_path_for(resource)
render json: { message: "password updated"}, status: 200
else
respond_with resource
end
end
protected
def after_resetting_password_path_for(resource)
after_sign_in_path_for(resource)
end
# The path used after sending reset password instructions
def after_sending_reset_password_instructions_path_for(resource_name)
new_session_path(resource_name) if is_navigational_format?
end
# Check if a reset_password_token is provided in the request
def assert_reset_token_passed
if params[:reset_password_token].blank?
#set_flash_message(:error, :no_token)
#redirect_to new_session_path(resource_name)
render json: { message: "reset password is not blank"}, status: 200
end
end
# Check if proper Lockable module methods are present & unlock strategy
# allows to unlock resource on password reset
def unlockable?(resource)
resource.respond_to?(:unlock_access!) &&
resource.respond_to?(:unlock_strategy_enabled?) &&
resource.unlock_strategy_enabled?(:email)
end
end
recoverable.rb法reset_password_by_token:私は方法でいくつかのプットを追加しようとしましたし、彼らはバックログでスローされていない
def reset_password_by_token(attributes={})
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
if recoverable.persisted?
if recoverable.reset_password_period_valid?
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
else
recoverable.errors.add(:reset_password_token, :expired)
end
end
recoverable
end
Devise::Models.config(self, :reset_password_keys, :reset_password_within)
。
EDIT
=====
Started PUT "https://stackoverflow.com/users/password" for 192.168.0.18 at 2016-04-06 09:35:11 +0200
Processing by Devise::PasswordsController#update as JSON
Parameters: {"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]"}
, :options=>{:count=>1, :default=>["User"]}, :description=>"User"}, {:key=>"activerecord.attributes.user.confirmation_token", :locale=>:en, :options=>{:count=>1, :default=>[:"attributes.confirmation_token", "Confirmation token"]}, :description=>"Confirmation token"}, {:key=>"activerecord.attributes.user.unconfirmed_email", :locale=>:en, :options=>{:count=>1, :default=>[:"attributes.unconfirmed_email", "Unconfirmed email"]}, :description=>"Unconfirmed email"}, {:key=>"activerecord.attributes.user.email", :locale=>:en, :options=>{:count=>1, :default=>[:"attributes.email", "Email"]}, :description=>"Email"}, {:key=>"activerecord.attributes.user.reset_password_token", :locale=>:en, :options=>{:count=>1, :default=>[:"attributes.reset_password_token", "Reset password token"]}, :description=>"Reset password token"}]}
Completed 422 Unprocessable Entity in 2174ms (Views: 0.4ms | ActiveRecord: 1.6ms)
===================: はここに私のレールのログです==============要求は、Iどこから来るのか理解する
は角/フロントエンド部分のPUT要求の下に追加します。
users.newPassword = function (token, password) {
var putData = {
user:{
reset_password_token: token,
password: password
}
};
return Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setFullResponse(true);
}).one('/users/password').customPUT(putData);
};
にそれを修正:それは '' reset_password_tokenをconfirmation_token'butていません「私はポストを更新した。今私はあなたの提案をしようとしています。 – user1713964
更新メソッドを 'resource_class.reset_password_by_token(params [:password]、params [:reset_password_token])'で変更しましたが、 "can not be blank"という422のエラーがあります。サーバログには、2つのパラメータがあります: '' reset_password_token "=>" [FILTERED] "、"パスワード "=>" [FILTERED] "}' – user1713964
実際、私はすべてのこのコントローラーのメソッドがログにポップします。私は、更新メソッドを呼び出す前にエラーをキャッチする何かがあると思います。しかし、私はDeviseがどのように管理されているのか分かりません。 – user1713964