debian-mirror-gitlab/app/services/users/email_verification/base_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
548 B
Ruby
Raw Normal View History

2022-10-11 01:57:18 +05:30
# frozen_string_literal: true
module Users
module EmailVerification
class BaseService
VALID_ATTRS = %i[unlock_token confirmation_token].freeze
2023-07-09 08:55:56 +05:30
def initialize(attr:, user:)
2022-10-11 01:57:18 +05:30
@attr = attr
2023-07-09 08:55:56 +05:30
@user = user
2022-10-11 01:57:18 +05:30
validate_attr!
end
protected
2023-07-09 08:55:56 +05:30
attr_reader :attr, :user, :token
2022-10-11 01:57:18 +05:30
def validate_attr!
raise ArgumentError, 'Invalid attribute' unless attr.in?(VALID_ATTRS)
end
def digest
2023-07-09 08:55:56 +05:30
Devise.token_generator.digest(User, user.email, token)
2022-10-11 01:57:18 +05:30
end
end
end
end