I want to override Password controller to different create action. So I could generate random password and save with user then send that password to user e-mail.
I have like this. routes.rb
devise_for :users, :controllers => { :passwords => "passwords" }
Password controller.
class PasswordsController < Devise::PasswordsController
def create
size = 6
charset = %w{ 2 3 4 6 7 9 a v n A j C u D q E i F p G m H J K M N P Q R T V W X Y Z}
self.resource.password = (0...size).map{ charset.to_a[rand(charset.size)] }.join
if self.resource.save(:validate => false)
self.resource = resource_class.send_reset_password_instructions(resource_params)
else
#do nothing yet
end
end
end
This code sends e-mail to user but expected password isn't there.
resset_password_instructions.html.erb
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p>Your new password is <%= @resource.password %></p>
<p>Your password won't change until you access the link above and create a new one.</p>
What I am doing wrong?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire