I previously had a page as settings to update the user details in rails. On that time the password gets updated without any issue. But now I used a password reset option for the users who forgot their password. They will receive a mail and then they reset the password. After adding this feature both the updating inside the account and via mail does not happen.
password_reset controller:
def update
@user = User.find_by_password_reset_token!(params[:id])
if @user.password_reset_sent_at < 2.hour.ago
flash[:notice] = 'Password reset has expired'
redirect_to new_password_reset_path
elsif @user.update_attributes(params[:user])// this condition fails. I don't know why it fails.
flash[:notice] = 'Password has been reset!'
redirect_to new_session_path
else
redirect_to new_session_path
end
user.rb
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
before_save { |user| user.email = email.downcase }
before_save :create_remember_token
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
These filters I used in user controller
before_filter :signed_in_user, only: [:edit, :update, :requestuser]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy
I am new to rails and learning. Need help. The same filter I used before password reset I dont know why it fails. It first worked for few days now it fails.
Aucun commentaire:
Enregistrer un commentaire