Files
nairobi/app/controllers/verification/residence_controller.rb
2015-08-27 23:53:49 +02:00

31 lines
939 B
Ruby

class Verification::ResidenceController < ApplicationController
before_action :authenticate_user!
before_action :verify_attemps_left!, only: [:new, :create]
skip_authorization_check
def new
@residence = Residence.new
end
def create
@residence = Residence.new(residence_params.merge(user: current_user))
if @residence.save
redirect_to verified_user_path, notice: t('verification.residence.create.flash.success')
else
current_user.update(residence_verification_tries: current_user.residence_verification_tries += 1)
render :new
end
end
private
def residence_params
params.require(:residence).permit(:document_number, :document_type, :date_of_birth, :postal_code)
end
def verify_attemps_left!
if current_user.residence_verification_tries >= 5
redirect_to account_path, alert: t('verification.residence.alert.verify_attemps_left')
end
end
end