Sha256: 27028ee2ee147b36cc8a5f468a9d902cff6f4907036a4b6a25e95360cb20fa69
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
class User < ActiveRecord::Base # Virtual attributes attr_accessor :is_generated_password # Scopes scope :active, -> { where(is_active: true) } # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :async, :recoverable, :rememberable, :trackable, :validatable # Helpers audited except: [:password] # Validations validates_presence_of :name, :email, :surname validates :email, uniqueness: true # Callbacks after_commit :send_login_info, on: :create before_validation :create_password, on: :create after_initialize do |obj| obj.is_generated_password = false end def active_for_authentication? super && self.is_active end def full_name "#{self.name} #{self.surname}" end private def create_password if self.password.nil? password = Devise.friendly_token.first(8) self.password = password self.password_confirmation = password self.is_generated_password = true end end def send_login_info UserMailer.login_info(self.id, self.password).deliver_later! if self.is_generated_password end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cybele-1.9.2 | templates/app/models/user.rb |
cybele-1.9.1 | templates/app/models/user.rb |
cybele-1.9.0 | templates/app/models/user.rb |