无法在Ruby on Rails 4中完成密码重置

时间:2015-07-09 04:11:36

标签: ruby-on-rails ruby passwords rails-activerecord forgot-password

我正在尝试为我的Rails应用程序完成密码重置功能。我已经完成了所有的路线和视图,但它们都解决了问题。当用户单击使用密码重置令牌生成的系统发送的电子邮件时,它们将进入密码重置视图。但是,当用户提交表单(有效或无效)以使用新密码更新用户记录时,视图只会重新加载而不会出现错误。我尝试了多种配置而没有运气。我觉得这与我的强大参数有关,但我似乎无法发挥作用。

这是为密码重置视图生成的网址

http://localhost:3000/password_resets/X6hrhVsJX2nB8-U7Zp9-7Q/edit

这就是我的密码重设控制器:

def edit
    @user = User.find_by_password_reset_token!(params[:id])
end

def update
    @user = User.find_by_password_reset_token!(params[:id])

    if @user.password_reset_sent_at < 2.hours.ago
        flash[:notice] = "Password reset has expired."
        redirect_to(:action => 'new')
    elseif @user.update_attributes(user_params)
        flash[:success] = "Password reset was successful. Please sign in."
        redirect_to(:controller => 'auth', :action => 'get_sign_in')
    else
        render(:edit)
    end
end

private

    def user_params
        params.require(:user).permit(:password, :password_confirmation)
    end

这就是我的表格

<%= form_for @user, :url => password_reset_path(params[:id]) do |f| %>
<div class="row">
    <div class="input-field col s12">
        <%= f.password_field(:password, class: 'validate') %>
        <%= f.label :password %>
    </div>
</div>
<div class="row">
    <div class="input-field col s12">
        <%= f.password_field(:password_confirmation, class: 'validate') %>
        <label for="password_confirmation">Password Confirmation</label>
    </div>
</div>
<div class="row">
    <div class="col s12">
        <button class="btn waves-effect waves-light blue" type="submit" name="action">Update Password
        </button>
    </div>
</div>

以下是我正在使用的路线

resources :password_resets

match ':controller(/:action(/:id))', :via => [:get, :post]

以下是我在行动中获得的服务器日志

Started PUT "/password_resets/82o6bWWIdpUg4jAnMcJqNQ" for ::1 at 2015-07-09 06:10:49 -0500
Processing by PasswordResetsController#update as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"NuwgHyhpeYE+fhPM8Cl6tTJPTTAGeFGYnsAlvVN4tg0utO3795qTRZno7bNdDUDL9rIrki5v8VF2zP3UC2auCQ==", "user"=>{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "id"=>"82o6bWWIdpUg4jAnMcJqNQ"}
User Load (0.4ms)  SELECT  `users`.* FROM `users` WHERE `users`.`password_reset_token` = '82o6bWWIdpUg4jAnMcJqNQ' LIMIT 1
Rendered partials/_user_errors.html.erb (0.2ms)
Rendered layouts/application.html.erb (86.4ms)
Rendered password_resets/edit.html.erb within layouts/application (92.3ms)
Completed 200 OK in 188ms (Views: 186.2ms | ActiveRecord: 0.4ms)

任何信息都会有所帮助。

0 个答案:

没有答案