Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_service.rb « email_verification « users « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 174626ac2f9fd1f74319c0da441f3e25408e3102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module Users
  module EmailVerification
    class BaseService
      VALID_ATTRS = %i[unlock_token confirmation_token].freeze

      def initialize(attr:, user:)
        @attr = attr
        @user = user

        validate_attr!
      end

      protected

      attr_reader :attr, :user, :token

      def validate_attr!
        raise ArgumentError, 'Invalid attribute' unless attr.in?(VALID_ATTRS)
      end

      def digest
        Devise.token_generator.digest(User, user.email.downcase.strip, token)
      end
    end
  end
end