Class: BBMB::Html::State::ChangePassword

Inherits:
Global
  • Object
show all
Defined in:
lib/bbmb/html/state/change_password.rb

Constant Summary collapse

DIRECT_EVENT =
:change_pass
VIEW =
Html::View::ChangePassword

Instance Method Summary collapse

Methods inherited from Global

#direct_argument_keys, #direct_arguments, #direct_request?, #initialize, #logout, mandatory, #requested_event, #trigger, #user_input

Constructor Details

This class inherits a constructor from BBMB::Html::State::Global

Instance Method Details

#saveObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bbmb/html/state/change_password.rb', line 14

def save
  keys = mandatory
  input = user_input(keys, keys)
  if(error?)
    @errors.dup.each { |key, val|
      if(/^e_(empty|missing)_/.match val.message)
        @errors.store(key, create_error(:e_need_all_fields, key, nil))
      end
    }
  else
    update_user input
    unless(error?)
      BBMB.persistence.save(@model)
      return State::Info.new(@session, :message => :login_data_saved,
                                       :event => :home)
    end
  end
  self
end

#update_user(input) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bbmb/html/state/change_password.rb', line 33

def update_user(input)
  email = input.delete(:email)
  @model.email = email
  @model.protect!(:email)
  if(passhash = input.delete(:confirm_pass))
    begin
      @session.auth_session.set_password(email, passhash)
    rescue Yus::YusError => e
      @errors.store(:pass, create_error(:e_pass_not_set, :email, email))
    end
  end
rescue Yus::YusError => e
  @errors.store(:email, create_error(:e_duplicate_email, :email, email))
end