adopt-a-hydrant/app/controllers/passwords_controller.rb

34 lines
965 B
Ruby
Raw Normal View History

2011-03-07 02:40:29 +00:00
class PasswordsController < Devise::PasswordsController
def create
2012-06-18 17:49:28 +00:00
self.resource = resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given?
if successfully_sent?(resource)
2014-03-25 09:47:44 +00:00
render(json: {success: true})
2011-03-07 02:40:29 +00:00
else
2014-03-25 09:47:44 +00:00
render(json: {errors: resource.errors}, status: 500)
2011-03-07 02:40:29 +00:00
end
end
def edit
self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token]
2014-04-01 08:15:29 +00:00
render('edit', layout: 'info_window')
2011-03-07 02:40:29 +00:00
end
def update
2012-06-18 17:49:28 +00:00
self.resource = resource_class.reset_password_by_token(resource_params)
yield resource if block_given?
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
sign_in(resource_name, resource)
end
2014-04-01 08:15:29 +00:00
redirect_to(controller: 'main', action: 'index')
2011-03-07 02:40:29 +00:00
end
private
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation, :reset_password_token)
end
2011-03-07 02:40:29 +00:00
end