2014-09-02 18:07:02 +05:30
|
|
|
class PasswordsController < Devise::PasswordsController
|
2015-10-24 18:46:33 +05:30
|
|
|
before_action :resource_from_email, only: [:create]
|
2017-09-10 17:25:29 +05:30
|
|
|
before_action :prevent_ldap_reset, only: [:create]
|
2015-10-24 18:46:33 +05:30
|
|
|
before_action :throttle_reset, only: [:create]
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
def edit
|
|
|
|
super
|
|
|
|
reset_password_token = Devise.token_generator.digest(
|
|
|
|
User,
|
|
|
|
:reset_password_token,
|
|
|
|
resource.reset_password_token
|
|
|
|
)
|
|
|
|
|
|
|
|
unless reset_password_token.nil?
|
|
|
|
user = User.where(
|
|
|
|
reset_password_token: reset_password_token
|
|
|
|
).first_or_initialize
|
|
|
|
|
|
|
|
unless user.reset_password_period_valid?
|
|
|
|
flash[:alert] = 'Your password reset token has expired.'
|
|
|
|
redirect_to(new_user_password_url(user_email: user['email']))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def update
|
|
|
|
super do |resource|
|
2017-09-10 17:25:29 +05:30
|
|
|
if resource.valid? && resource.require_password_creation?
|
2016-06-02 11:05:42 +05:30
|
|
|
resource.update_attribute(:password_automatically_set, false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
protected
|
|
|
|
|
|
|
|
def resource_from_email
|
|
|
|
email = resource_params[:email]
|
|
|
|
self.resource = resource_class.find_by_email(email)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prevent_ldap_reset
|
2017-09-10 17:25:29 +05:30
|
|
|
return unless resource&.ldap_user?
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
redirect_to after_sending_reset_password_instructions_path_for(resource_name),
|
|
|
|
alert: "Cannot reset password for LDAP user."
|
|
|
|
end
|
|
|
|
|
|
|
|
def throttle_reset
|
|
|
|
return unless resource && resource.recently_sent_password_reset?
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
# Throttle reset attempts, but return a normal message to
|
|
|
|
# avoid user enumeration attack.
|
|
|
|
redirect_to new_user_session_path,
|
|
|
|
notice: I18n.t('devise.passwords.send_paranoid_instructions')
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|