Created
May 22, 2009 03:07
-
-
Save brapse/115897 to your computer and use it in GitHub Desktop.
debug with pp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
#VIEW | |
########################## | |
<h1>Request password reset</h1> | |
<%= flash[:notice] %> | |
<%= flash[:error] %> | |
<%= error_messages_for :user %> | |
<p>Have you forgotten your password? Don't worry, simply enter your email address below and we will send you a link to enable you to reset your password.</p> | |
<% form_for :user do |f| -%> | |
<p><%= f.label :email %><br /> | |
<%= f.text_field :email %></p> | |
<p><%= submit_tag 'Submit' %></p> | |
<% end -%> | |
########################### | |
#controller | |
########################## | |
#forget this -> | |
class UsersController < ApplicationController | |
# Be sure to include AuthenticationSystem in Application Controller instead | |
#before_filter :login_required | |
active_scaffold :user do |config| | |
config.columns = [:id, :firstname, :lastname, :address, :city, :postal_code, :telephone, :telephone1, :cellulaire, | |
:email, :notes, :password] | |
config.create.link.label = "Ajouter un nouvel étudiant" | |
config.columns[:firstname].label = "Prénom" | |
config.columns[:lastname].label = "Nom" | |
config.columns[:address].label = "Adresse" | |
config.columns[:city].label = "Ville" | |
config.columns[:postal_code].label = "Code Postal" | |
config.label = "Gestion des étudiants" | |
config.columns[:password].description = "(facultatif: spécifier un password)" | |
config.create.columns.exclude :id, :is_admin | |
config.update.columns.exclude :id, :is_admin, :password | |
config.list.columns.exclude :address, :city, :postal_code, :telephone, :telephone1, :cellulaire, :password | |
config.list.sorting = {:email => 'ASC'} | |
config.nested.add_link("Inscriptions",[:inscriptions]) | |
config.list.per_page = 25 | |
end | |
#<- stop forgetting :D | |
def forgot | |
require 'pp' | |
pp params | |
if request.post? | |
user = User.find_by_email("[email protected]")#params[:email] #<--here | |
if (user) | |
user.reset_password_code_until = 1.day.from_now | |
user.reset_password_code = Digest::SHA1.hexdigest( "#{user.email}#{Time.now.to_s.split(//).sort_by {rand}.join}" ) | |
user.save | |
UserMailer.deliver_forgot(user) | |
flash[:notice] = "Reset Password link emailed to #{user.email}." | |
else | |
flash[:error] = "User not found: #{params[:email]}" | |
end | |
end | |
end | |
def reset | |
if request.post? | |
print params[:email] | |
@user = User.find_by_email_and_reset_password_code(params[:user][:email], params[:reset_code]) | |
# print params[:password] | |
@user.new_password = params[:password] | |
@user.save_new_password | |
# print @new_password, @user.password | |
if @user.save | |
# print @user.new_password, @user.password | |
# @user.clear_reset_code! | |
flash[:notice] = "Password reset successfully for #{@user.email}" | |
redirect_back_or_default("/") | |
else | |
render :action => :reset | |
flash[:notice] = "Un problème est survenu" | |
print "not saved" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment