Module: RegistrationTokenValidation

Defined in:
app/controllers/concerns/registration_token_validation.rb

Class Method Summary collapse

Class Method Details

.before(controller) ⇒ Object



3
4
5
6
7
# File 'app/controllers/concerns/registration_token_validation.rb', line 3

def before(controller)
  @token = controller.params[:registration_token]
  @controller = controller
  controller.redirect_to controller.new_user_session_path unless valid?
end

.resolves?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/concerns/registration_token_validation.rb', line 13

def resolves?
  encrypted_token = Devise.token_generator.digest(
    Jobshop::Team, :registration_token, @token)

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

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

.valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/controllers/concerns/registration_token_validation.rb', line 9

def valid?
  @token.present? && resolves?
end