adds residence verification

This commit is contained in:
rgarcia
2015-08-27 23:53:49 +02:00
parent 61b7ff5e21
commit 07180bcd04
5 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
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