Class: Devise::PinfirmableController

Inherits:
DeviseController
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
app/controllers/devise/pinfirmable_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/devise/pinfirmable_controller.rb', line 9

def create
  if locked_out?
    @locked_out = true
    render(:new, status: 429) && return
  end

  if Pinfirmable::Pin.new(params[:digits]).matches_user_pin(pinfirmable_user)
    pinfirmable_user.confirm
    redirect_to after_confirmation_path_for(resource_name, pinfirmable_user)
  else
    tries = pinfirmable_user.pinfirmable_tries += 1
    lockout = (tries % 3).zero? ? (tries / 3).minute.from_now : nil
    pinfirmable_user.update_attributes(
      pinfirmable_tries: tries,
      pinfirmable_lockout: lockout
    )
    redirect_to user_confirmemail_path
  end
end

#newObject



5
6
7
# File 'app/controllers/devise/pinfirmable_controller.rb', line 5

def new
  @locked_out = locked_out?
end

#resend_emailObject



29
30
31
32
33
34
35
# File 'app/controllers/devise/pinfirmable_controller.rb', line 29

def resend_email
  flash[:notice] = t("pinfirmable.resend_email.notice_html",
                     email: pinfirmable_user.email,
                     not_correct_link: link_to(t("pinfirmable.resend_email.incorrect_email"), destroy_session_path(resource_name), method: :delete))
  PinfirmableMailer.pin_email(pinfirmable_user).deliver
  redirect_to user_confirmemail_path
end