Class: CodeManager::Confirmation

Inherits:
CodeManager show all
Defined in:
app/services/code_manager/confirmation.rb

Overview

Manager for email confirmation codes

Instance Attribute Summary

Attributes inherited from CodeManager

#code, #user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CodeManager

handler, #initialize

Constructor Details

This class inherits a constructor from CodeManager

Class Method Details

.code_for_user(user) ⇒ Object

Parameters:



11
12
13
14
15
16
# File 'app/services/code_manager/confirmation.rb', line 11

def self.code_for_user(user)
  code = code_type.codes.active.find_by(user: user)
  code = code_type.codes.create(user: user, payload: user.email) if code.nil?

  code
end

.code_typeCodeType

Returns:



6
7
8
# File 'app/services/code_manager/confirmation.rb', line 6

def self.code_type
  @code_type ||= CodeType.find_by!(slug: 'confirmation')
end

Instance Method Details

#activateObject



24
25
26
27
28
29
# File 'app/services/code_manager/confirmation.rb', line 24

def activate
  return if @code.quantity < 1

  @code.decrement!(:quantity)
  @code.user.update email_confirmed: true if @code.payload == @code.user.email
end

#code_is_valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/services/code_manager/confirmation.rb', line 18

def code_is_valid?
  return false if @code.nil?

  @code.active? && @code.code_type == self.class.code_type
end