ref: master
app/helpers/forgot_password_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
module ForgotPasswordHelper def plugins_options @plugins.dispatch(:change_password_fields) end def user_fields %w[login email] + plugins_options.select {|options| options[:model].to_sym == :user }.map { |options| options[:field].to_s } end def person_fields %w[] + plugins_options.select {|options| options[:model].to_sym == :person }.map { |options| options[:field].to_s } end def fields user_fields + person_fields end def fields_label labels = [ _('Username'), _('Email'), ] + plugins_options.map { |options| options[:name] } last = labels.pop label = labels.join(', ') "#{label} #{_('or')} #{last}" end def build_query(fields, value) fields.map {|field| "#{field} = '#{value}'"}.join(' OR ') end def fetch_requestors(value) requestors = [] person_query = build_query(person_fields, value) user_query = build_query(user_fields, value) requestors += Person.where(person_query).where(:environment_id => environment.id) if person_fields.present? requestors += User.where(user_query).where(:environment_id => environment.id).map(&:person) if user_fields.present? requestors end end |