Sha256: c21cfb675e171ca81bf0ef449b70dbc0317ccfcd2d1cd2556a2c96ae75e34251

Contents?: true

Size: 470 Bytes

Versions: 2

Compression:

Stored size: 470 Bytes

Contents

module Plotline
  class User < ActiveRecord::Base
    has_secure_password

    validates :email, presence: true, uniqueness: true
    validates :password, presence: { unless: :persisted? }, length: { minimum: 6 }, allow_nil: true

    before_create { generate_token(:auth_token) }

    private

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plotline-0.1.1 app/models/plotline/user.rb
plotline-0.1.0 app/models/plotline/user.rb