Sha256: a14998cfabccafa291375e439779ae781ada59282f06f83309bd1a8d553b68ee

Contents?: true

Size: 747 Bytes

Versions: 11

Compression:

Stored size: 747 Bytes

Contents

module RegistrationTokenValidation
  extend ActiveSupport::Concern

  included do
    before_action :validate_registration_token!
  end

  def validate_registration_token!
    redirect_to new_user_session_path unless registration_token_valid?
  end

  def registration_token_valid?
    params[:registration_token].present? && registration_token_resolves?
  end

  def registration_token_resolves?
    encrypted_token = Devise.token_generator.digest(
      Jobshop::Team, :registration_token, params[:registration_token])

    configurable = Jobshop::Team.find_by(
      id: params[:team_id], registration_token: encrypted_token)

    configurable &&
      configurable.registration_token_period_valid? &&
      configurable.owner.blank?
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jobshop-0.0.16 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.15 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.14 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.13 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.12 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.11 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.10 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.9 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.7 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.6 app/controllers/concerns/registration_token_validation.rb
jobshop-0.0.5 app/controllers/concerns/registration_token_validation.rb