<commit_before># encoding: utf-8

# == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  name                   :string(255)
#  email                  :string(255)
#  password_digest        :string(255)
#  created_at             :datetime         not null
#  updated_at             :datetime         not null
#  auth_token             :string(255)
#  password_reset_token   :string(255)
#  password_reset_sent_at :datetime
#  provider               :string(255)
#  uid                    :string(255)
#  asked_for_email        :boolean
#

class User < ActiveRecord::Base

  # Use built-in rails support for password protection
  has_secure_password

  # Callbacks
  before_create             { generate_token(:auth_token) }

  # Relationships
  has_many                  :organized_books, :class_name => "Book", :foreign_key => "organizer_id"
  has_and_belongs_to_many   :books
  has_many                  :invitations, :foreign_key => 'invited_id'
  has_one                   :client

  # Validations
  validates :name,          :presence => true
  validates :email,         :email_format => { :message => 'Não é um formato válido de e-mail', :allow_blank => true },
                            :uniqueness => true,
                            :presence => true
  validates :password,      :presence => true, :on => :create

  # Specify fields that can be accessible through mass assignment
  attr_accessible           :email, :name, :password, :password_confirmation, :asked_for_email

  # Other methods
  def send_password_reset
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!
    UserMailer.password_reset(self).deliver
  end

  def send_book_invitation(inviter, book_uuid)
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!(:validate => false)
    UserMailer.book_invitation(inviter, self, book_uuid).deliver
  end

  def generate_token(column)
    begin
      self[column] = SecureRandom.urlsafe_base64
    end while User.exists?(column => self[column])
  end

  def self.from_omniauth(auth)
    where(auth.slice('provider', 'uid')).first || create_from_omniauth(auth)
  end

  def self.create_from_omniauth(auth)
    new_user = new({ :provider => auth['provider'], :uid => auth['uid'], :name => auth['info']['name'], :email => auth['info']['email'] }, :without_protection => true)
    new_user.save!(:validate => false)
    new_user
  end
end
<commit_msg>Correção em recuperação de senhas<commit_after># encoding: utf-8

# == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  name                   :string(255)
#  email                  :string(255)
#  password_digest        :string(255)
#  created_at             :datetime         not null
#  updated_at             :datetime         not null
#  auth_token             :string(255)
#  password_reset_token   :string(255)
#  password_reset_sent_at :datetime
#  provider               :string(255)
#  uid                    :string(255)
#  asked_for_email        :boolean
#

class User < ActiveRecord::Base

  # Use built-in rails support for password protection
  has_secure_password

  # Callbacks
  before_create             { generate_token(:auth_token) }

  # Relationships
  has_many                  :organized_books, :class_name => "Book", :foreign_key => "organizer_id"
  has_and_belongs_to_many   :books
  has_many                  :invitations, :foreign_key => 'invited_id'
  has_one                   :client

  # Validations
  validates :name,          :presence => true
  validates :email,         :email_format => { :message => 'Não é um formato válido de e-mail', :allow_blank => true },
                            :uniqueness => true,
                            :presence => true
  validates :password,      :presence => true, :on => :create

  # Specify fields that can be accessible through mass assignment
  attr_accessible           :email, :name, :password, :password_confirmation, :asked_for_email

  # Other methods
  def send_password_reset
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!(:validate => false)
    UserMailer.password_reset(self).deliver
  end

  def send_book_invitation(inviter, book_uuid)
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!(:validate => false)
    UserMailer.book_invitation(inviter, self, book_uuid).deliver
  end

  def generate_token(column)
    begin
      self[column] = SecureRandom.urlsafe_base64
    end while User.exists?(column => self[column])
  end

  def self.from_omniauth(auth)
    where(auth.slice('provider', 'uid')).first || create_from_omniauth(auth)
  end

  def self.create_from_omniauth(auth)
    new_user = new({ :provider => auth['provider'], :uid => auth['uid'], :name => auth['info']['name'], :email => auth['info']['email'] }, :without_protection => true)
    new_user.save!(:validate => false)
    new_user
  end
end

{'fraction_non_alphanumeric': 0.1043222003929273, 'fraction_numerical': 0.009430255402750491, 'mean_word_length': 2.6183368869936032, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '7085282', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1512, 'n_words': 343}