Class: Gringotts::SettingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/gringotts/settings_controller.rb

Instance Method Summary collapse

Instance Method Details

#disableObject



60
61
62
63
64
65
66
# File 'app/controllers/gringotts/settings_controller.rb', line 60

def disable
  @gringotts.update_attributes!(confirmed_at: nil)
  @gringotts.settings.destroy

  redirect_to gringotts_engine.root_path, notice: "Phone Verification is OFF"
  return true
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/gringotts/settings_controller.rb', line 10

def index
  # since we always redirect from here, keep the flash (rails-3.2 bug fix'd!)
  flash.keep

  if @gringotts.confirmed? && @gringotts.verified?(session)
    redirect_to gringotts_engine.success_path
  elsif @gringotts.phone_number.present?
    redirect_to gringotts_engine.verification_path
  else
    redirect_to gringotts_engine.setup_path
  end
  return true
end

#promptObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/gringotts/settings_controller.rb', line 32

def prompt
  # see if we have a url saved (we should, but for safety, if missing, just redirect to root)
  @next_url = gringotts_next_url || main_app.root_url
  
  if @gringotts.show_prompt?
    # going to show prompt
    # need to remember that have shown, so not show twice
    @gringotts.prompt_shown!
  else
    # should not see it twice
    redirect_to @next_url
  end
end

#setupObject



24
25
26
27
28
29
30
# File 'app/controllers/gringotts/settings_controller.rb', line 24

def setup
  if @gringotts.confirmed? && !@gringotts.verified?(session)
    # since this is not covered by gringotts_protego! we need to manually check some things
    # namely, that if a user is supposed to be verifying, they can't edit their settings...
    redirect_to gringotts_engine.verification_path
  end  
end

#updateObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/gringotts/settings_controller.rb', line 46

def update
  if accepts_strong_params?
    @settings.assign_attributes(settings_params)
  else
    @settings.update_attributes(phone_number: params[:settings][:phone_number])
  end
  
  if @settings.save
    redirect_to verification_url
  else
    render :setup
  end
end