Sha256: 5f03d024e5f0942441d1a00b2055d056b5e47643378e2e1b75901b1f9e991a06

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# Model: User
# A user.
#
class User < Sequel::Model
  plugin :aura_editable

  extend Shield::Model

  # For Shield
  def self.fetch(email)
    first(:email => email)
  end

  # For Shield
  def password=(password)
    self.crypted_password = Shield::Password.encrypt(password)
    @password = password
    @password_confirmation = password  if new?
  end

  attr_writer :password_confirmation

  # For Shield
  def validate
    super
    validates_presence :email
    errors.add(:password, 'cannot be empty')  if self.crypted_password.nil?

    duplicate = self.class.fetch(email)
    errors.add(:email, 'is already taken')  if !duplicate.nil? and duplicate.id != self.id
    errors.add(:password_confirmation, 'must match password')  if @password != @password_confirmation
  end

  def slugify(str=email)
    super str
  end

  def to_s
    email
  end

  def self.seed!(type=nil, &blk)
    # Don't clear users!
    seed type, &blk
  end

  def self.seed(type=nil, &blk)
    super
    return  if User.any?

    email    = Main.default_user
    password = Main.default_password

    p1 = self.create :email => email,
                     :password => password,
                     :password_confirmation => password

    blk.call :info, "You may login with '#{email}' and password '#{password}'."  if block_given?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aura-0.0.1.pre10 app/models/user.rb