Skip to Content Skip to Search
Methods
C
E
I
N
R
S
U

Attributes

[R] context
[R] member
[R] new_email
[R] password
[R] prior_websitetoolbox_username
[R] site
[R] token

Class Public methods

new(member:, password: nil, context: nil)

# File engines/member/app/actions/member/member_updator.rb, line 6
def initialize(member:, password: nil, context: nil)
  @member = member
  @site = member.site
  @password = password
  @context = context
  @prior_websitetoolbox_username = member.websitetoolbox_username
end

Instance Public methods

change_email(token)

# File engines/member/app/actions/member/member_updator.rb, line 59
def change_email(token)
  @token = token
  @new_email = member.unconfirmed_email

  validate_token
  check_for_existing_email

  return if invalid?

  if member.update(email: new_email, unconfirmed_email: nil)
    EventBus.publish("member.updated", member:, skip_count: true)
    update_on_website_toolbox if has_website_toolbox_integration?
    customer = StripeCustomer.new(member:)
    customer.sync_email!
  end
end

error()

# File engines/member/app/actions/member/member_updator.rb, line 84
def error
  errors.values.first if errors.values.one?
end

errors()

# File engines/member/app/actions/member/member_updator.rb, line 80
def errors
  @errors ||= {}
end

invalid?()

# File engines/member/app/actions/member/member_updator.rb, line 76
def invalid?
  errors.present?
end

request_new_email(new_email)

# File engines/member/app/actions/member/member_updator.rb, line 39
def request_new_email(new_email)
  @new_email = new_email

  authenticate_password
  check_for_existing_email

  return if invalid?

  if member.update(
    confirmation_digest: secure_token.token_digest,
    unconfirmed_email: new_email
  )
    Emailer.member_email_confirmation(
      site,
      member_id: member.id,
      token: secure_token.token
    ).deliver_later
  end
end

status()

# File engines/member/app/actions/member/member_updator.rb, line 14
def status
  if email_error?
    :conflict
  elsif password_error? || token_error?
    :unauthorized
  else
    :unprocessable_entity
  end
end

update(params, after_signup_plan_id = nil)

# File engines/member/app/actions/member/member_updator.rb, line 24
def update(params, after_signup_plan_id = nil)
  member.after_signup_plan_id = after_signup_plan_id
  member.assign_attributes(params.except(:custom_fields))
  member.custom_fields = member.custom_fields.to_h.merge(params.fetch(:custom_fields, {}))

  member.validate_after_signup_fields = true

  if member.save(context:)
    update_on_website_toolbox if has_website_toolbox_integration?
    EventBus.publish("member.updated", member:, skip_count: true)
  end

  member.valid?(context)
end