Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShawn Wilson
iOS Development Techdegree Student 7,049 PointsPassword not Reseting from Forgot Password Feature.. Please help..!
So I have a bit of a problem.. I have followed Jason along in the password Reset (RUBY) track.. however when i go to the password reset form ask it to send an email and i copy and paset the link from the server log as shown here:
Sent mail to swilson@taurenltd.com (9.2ms) Date: Mon, 13 Apr 2015 23:41:39 -0600 From: support@taurenltd.ca To: Shawn Wislon swilson@taurenltd.com Message-ID: <552ca893ed53f_23153fc7b13a4b94829f7@Shawns-MacBook-Pro.local.mail> Subject: Request To Reset Your Password Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit
Hi Shawn
You can reset your password here:
Redirected to http://localhost:3000/user_session/new Completed 302 Found in 223ms (ActiveRecord: 3.2ms)
The link works fine in the browser and when i open it i can see the password and password confirm fields I created in the edit.html.erb file.. ill post these below. when i fill it out and submit it, it is supposed to redirect me to my users index page.. but it dosnt... it just reloads the form. the server dosnt show it changed or committed the passwords and i cant seem to find any errors on the server log to indicate an issue.
SERVER LOG FOR WHOLE TRANSACTION: Started GET "/password_resets/new" for ::1 at 2015-04-13 23:51:49 -0600 Processing by PasswordResetsController#new as HTML Rendered password_resets/new.html.erb within layouts/application (0.9ms) Completed 200 OK in 52ms (Views: 51.1ms | ActiveRecord: 0.0ms)
Started POST "/password_resets" for ::1 at 2015-04-13 23:51:58 -0600
Processing by PasswordResetsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NbTOol1Cr6qgvzJwzp3xr/KDFYG8Ls79UYE/BQ2wyPQPcjPakyuTRZrFFt9WHwmczqvYJB9tdH36m+Zh8pxQwg==", "email"=>"swilson@taurenltd.com", "commit"=>"Reset Password"}
User Load (0.2ms) SELECT users
.* FROM users
WHERE users
.email
= 'swilson@taurenltd.com' LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) UPDATE users
SET password_reset_token
= 'zgs8OQNKFF1c6kLpBeDkOgw8tbqNgEM2KLPyupAXwE89m5pw-0tU7G8gwxo4Ix6h', updated_at
= '2015-04-14 05:51:58.847063' WHERE users
.id
= 1
(0.4ms) COMMIT
DEPRECATION WARNING: #deliver
is deprecated and will be removed in Rails 5. Use #deliver_now
to deliver immediately or #deliver_later
to deliver through Active Job. (called from create at /Users/TaurenLTD1/Desktop/Security Information Center/S.I.C/app/controllers/password_resets_controller.rb:11)
Rendered notifier/password_reset.text.erb within layouts/mailer (0.2ms)
Notifier#password_reset: processed outbound mail in 14.4ms
Sent mail to swilson@taurenltd.com (3.5ms) Date: Mon, 13 Apr 2015 23:51:58 -0600 From: support@taurenltd.ca To: Shawn Wislon swilson@taurenltd.com Message-ID: <552caafed32fb_23153fc7b48dc1cc831b4@Shawns-MacBook-Pro.local.mail> Subject: Request To Reset Your Password Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit
Hi Shawn
You can reset your password here:
Redirected to http://localhost:3000/user_session/new Completed 302 Found in 23ms (ActiveRecord: 0.9ms)
Started GET "/user_session/new" for ::1 at 2015-04-13 23:51:58 -0600 Processing by UserSessionController#new as HTML Rendered user_session/new.html.erb within layouts/application (0.4ms) Completed 200 OK in 56ms (Views: 55.5ms | ActiveRecord: 0.0ms)
Started GET "/password_resets/zgs8OQNKFF1c6kLpBeDkOgw8tbqNgEM2KLPyupAXwE89m5pw-0tU7G8gwxo4Ix6h/edit" for ::1 at 2015-04-13 23:52:17 -0600
Processing by PasswordResetsController#edit as HTML
Parameters: {"id"=>"zgs8OQNKFF1c6kLpBeDkOgw8tbqNgEM2KLPyupAXwE89m5pw-0tU7G8gwxo4Ix6h"}
User Load (0.3ms) SELECT users
.* FROM users
WHERE users
.password_reset_token
= 'zgs8OQNKFF1c6kLpBeDkOgw8tbqNgEM2KLPyupAXwE89m5pw-0tU7G8gwxo4Ix6h' LIMIT 1
Rendered password_resets/edit.html.erb within layouts/application (0.7ms)
Completed 200 OK in 39ms (Views: 37.9ms | ActiveRecord: 0.3ms)
Here is my edit.html.erb file:
<h1>Change Your Password</h1> <%= form_for @user, url: password_resets_path(@user.password_reset_token), html: { method: :path } do |form| %>
New Password: <%= form.password_field :password %>
<br />
Confirm Password: <%= form.password_field :password_confirmation %>
<br />
<%= form.submit "Change Password" %>
<% end %>
Here is my password_resets_controller file:
class PasswordResetsController < ApplicationController
def new
end
def create user = User.find_by(email: params[:email]) if user user.generate_password_reset_token! Notifier.password_reset(user).deliver redirect_to new_user_session_path else flash.now[:notice] = "Email address not found" render action: 'new' end end
def edit @user = User.find_by(password_reset_token: params[:id]) if @user else render file: 'public/404.html', status: :not_found end end
def update user = User.find_by(password_reset_token: params[:id]) if @user && @user.update_attributes(user_params) @user.update_attributes(:password_reset_token, nil) session[:user_id] = @user.id redirect_to login_path, success: "Password successfully updated." else flash.now[:notice] = "Password reset token not found." render action: 'edit' end end
private
def user_params params.require(:user).permit(:password, :password_confirmation) end
end
alternatly you can find all this code on my git hub account so you can reference anything else you may need to... or ask and ill post.
2 Answers
Shawn Wilson
iOS Development Techdegree Student 7,049 Pointsi am now using devise... great gem! all seems to be functioning at this time..
Shawn Wilson
iOS Development Techdegree Student 7,049 Pointsi just followed the tutorial and it was from scratch.. unless i blatently missed something. but ive re watched the entire series of that segment to see if i did miss anything. my code is exact to jasons except im doing it in a personal app.
Kester Browne
24,414 PointsKester Browne
24,414 PointsAre you using Devise or are you building user authentication form scratch?