class Employee::EmailVerificationsController < Employee::Controller
  def verification
    token = current_user.build_email_verification_token
    if token.save
      render_success :ok, message: 'Verification sent to email.'
    else
      render_error :unprocessable_entity, errors: token
    end
  end

  def verify
    if token.verify(params[:token])
      render_success :ok, message: "The email address #{token.email} has been verified."
    else
      render_error :unprocessable_entity, errors: token
    end
  end

  private
    def token
      @token ||= current_user.find_or_build_email_verification_token
    end
end
