Wenn ein Benutzer auf dem Anmeldebildschirm auf "Passwort vergessen" klickt, wird er zu einer Route "/ password-reset" umgeleitet. Im Moment versuche ich zu verstehen, wie ich das Formular für die Eingabe Ihrer E-Mail korrigieren und mit einem Code SMS von Twilio erhalten kann.Twilio SMS Password Rails vergessen
<div class="form-group", style="width:50%;">
<%= form_for @user, url: password_patch_path(current_user) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: "form-control" %>
</div>
<%= f.submit "Get Confirmation Code", class: "btn btn-default" %>
<% end %>
</div>
Das Problem, das ich in laufende bin ist, dass @user Null ist, und ich bin nicht sicher, ob die URL am Anfang des Formulars korrekt ist. Es macht für mich Sinn, dass @user null ist, weil niemand eingeloggt ist, also bin ich mir nicht sicher, was das sein soll.
Meine Strecken sind
get '/password-reset', :to => 'passwords#edit', as: :password_reset
post '/password-reset', :to => 'passwords#reset', as: :password_edit
patch '/password-confirmation', :to => 'passwords#update', as: :password_patch
und meine Passwörter Controller sieht aus wie
class PasswordsController < ApplicationController
before_action :authenticated?, only: [:edit, :update]
def reset
ConfirmationSender.send_confirmation_to(current_user)
redirect_to new_confirmation_path
end
def edit
@user = current_user
end
def update
if passwords_not_empty? && passwords_equal?
current_user.update(password_params)
redirect_to users_dashboard_path(current_user.username), success: "Password Updated"
session[:authenticated] = false
else
redirect_to password_edit_path(current_user.username), warning: "Error, please try again."
end
end
private
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
def passwords_not_empty?
params[:user][:password].length > 0 && params[:user][:password_confirmation].length > 0
end
def passwords_equal?
params[:user][:password] == params[:user][:password_confirmation]
end
def authenticated?
render :file => "#{Rails.root}/public/404.html", :status => 404 unless session[:authenticated]
end
end
Danke Tom! Ich schätze die schnelle Hilfe sehr. – Sam
Kein Problem. Haben Sie keine Angst, Antworten zu wählen, die Sie hilfreich finden. –