<commit_before># == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  username               :string(255)      default(""), not null
#  email                  :string(255)      default("")
#  encrypted_password     :string(255)      default(""), not null
#  reset_password_token   :string(255)
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default("0"), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :string(255)
#  last_sign_in_ip        :string(255)
#  created_at             :datetime
#  updated_at             :datetime
#  admin                  :boolean          default("0")
#  enabled                :boolean          default("1")
#  ldap_name              :string(255)
#  failed_attempts        :integer          default("0")
#  locked_at              :datetime
#
# Indexes
#
#  index_users_on_email                 (email) UNIQUE
#  index_users_on_ldap_name             (ldap_name) UNIQUE
#  index_users_on_reset_password_token  (reset_password_token) UNIQUE
#  index_users_on_username              (username) UNIQUE
#

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :lockable,
         :recoverable, :rememberable, :trackable, :validatable, authentication_keys: [:username]

  USERNAME_CHARS  = "a-z0-9"
  USERNAME_FORMAT = /\A[#{USERNAME_CHARS}]{4,30}\Z/

  APPLICATION_TOKENS_MAX = 5

  validates :username, presence: true, uniqueness: true,
    format: {
      with:    USERNAME_FORMAT,
      message: "Only alphanumeric characters are allowed. Minimum 4 characters, maximum 30."
    }

  # Actions performed before/after create.
  validate :private_namespace_and_team_available, on: :create
  after_create :create_personal_namespace!

  has_many :team_users
  has_many :teams, through: :team_users
  has_many :stars
  has_many :application_tokens

  scope :not_portus, -> { where.not username: "portus" }
  scope :enabled,    -> { not_portus.where enabled: true }
  scope :admins,     -> { not_portus.where enabled: true, admin: true }

  # Special method used by Devise to require an email on signup. This is always
  # true except for LDAP.
  def email_required?<commit_msg>user: be more explicit on the allowed name format<commit_after># == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  username               :string(255)      default(""), not null
#  email                  :string(255)      default("")
#  encrypted_password     :string(255)      default(""), not null
#  reset_password_token   :string(255)
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default("0"), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :string(255)
#  last_sign_in_ip        :string(255)
#  created_at             :datetime
#  updated_at             :datetime
#  admin                  :boolean          default("0")
#  enabled                :boolean          default("1")
#  ldap_name              :string(255)
#  failed_attempts        :integer          default("0")
#  locked_at              :datetime
#
# Indexes
#
#  index_users_on_email                 (email) UNIQUE
#  index_users_on_ldap_name             (ldap_name) UNIQUE
#  index_users_on_reset_password_token  (reset_password_token) UNIQUE
#  index_users_on_username              (username) UNIQUE
#

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :lockable,
         :recoverable, :rememberable, :trackable, :validatable, authentication_keys: [:username]

  USERNAME_CHARS  = "a-z0-9"
  USERNAME_FORMAT = /\A[#{USERNAME_CHARS}]{4,30}\Z/

  APPLICATION_TOKENS_MAX = 5

  validates :username, presence: true, uniqueness: true,
    format: {
      with:    USERNAME_FORMAT,
      message: "only lower case alphanumeric characters are allowed. Minimum 4 characters, maximum 30."
    }

  # Actions performed before/after create.
  validate :private_namespace_and_team_available, on: :create
  after_create :create_personal_namespace!

  has_many :team_users
  has_many :teams, through: :team_users
  has_many :stars
  has_many :application_tokens

  scope :not_portus, -> { where.not username: "portus" }
  scope :enabled,    -> { not_portus.where enabled: true }
  scope :admins,     -> { not_portus.where enabled: true, admin: true }

  # Special method used by Devise to require an email on signup. This is always
  # true except for LDAP.
  def email_required?
{'fraction_non_alphanumeric': 0.09242262540021345, 'fraction_numerical': 0.014514407684098186, 'mean_word_length': 2.716098334655036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7614645', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1431, 'n_words': 349}