The code powering m.abunchtell.com https://m.abunchtell.com
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

18 righe
579 B

  1. # frozen_string_literal: true
  2. # See also: USERNAME_RE in the Account class
  3. class UniqueUsernameValidator < ActiveModel::Validator
  4. def validate(account)
  5. return if account.username.nil?
  6. normalized_username = account.username.downcase
  7. normalized_domain = account.domain&.downcase
  8. scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain)
  9. scope = scope.where.not(id: account.id) if account.persisted?
  10. account.errors.add(:username, :taken) if scope.exists?
  11. end
  12. end