2014-12-04 19:50:02 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users
|
|
|
|
#
|
2014-12-09 18:56:56 +01:00
|
|
|
# id :integer not null, primary key
|
2015-03-19 16:22:55 +01:00
|
|
|
# debt_cents :integer default("0"), not null
|
2014-12-09 18:56:56 +01:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# remember_created_at :datetime
|
2015-03-19 16:22:55 +01:00
|
|
|
# sign_in_count :integer default("0"), not null
|
2014-12-09 18:56:56 +01:00
|
|
|
# current_sign_in_at :datetime
|
|
|
|
# last_sign_in_at :datetime
|
2015-03-19 16:22:55 +01:00
|
|
|
# current_sign_in_ip :string
|
|
|
|
# last_sign_in_ip :string
|
|
|
|
# admin :boolean
|
|
|
|
# dagschotel_id :integer
|
|
|
|
# avatar_file_name :string
|
|
|
|
# avatar_content_type :string
|
|
|
|
# avatar_file_size :integer
|
|
|
|
# avatar_updated_at :datetime
|
|
|
|
# orders_count :integer default("0")
|
|
|
|
# koelkast :boolean default("f")
|
|
|
|
# provider :string
|
|
|
|
# uid :string
|
2015-03-20 02:33:37 +01:00
|
|
|
# encrypted_password :string
|
2014-12-04 19:50:02 +01:00
|
|
|
#
|
|
|
|
|
2015-03-23 11:54:15 +01:00
|
|
|
require 'identicon'
|
2014-11-06 14:46:59 +01:00
|
|
|
class User < ActiveRecord::Base
|
2015-03-25 17:49:37 +01:00
|
|
|
devise :database_authenticatable, :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
|
2015-02-09 17:06:24 +01:00
|
|
|
|
2015-03-23 11:54:15 +01:00
|
|
|
has_paper_trail
|
2015-03-19 17:38:59 +01:00
|
|
|
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
|
2014-12-09 17:17:11 +01:00
|
|
|
|
2014-12-06 17:51:41 +01:00
|
|
|
has_many :orders, -> { includes :products }
|
2015-01-13 13:06:42 +01:00
|
|
|
has_many :products, through: :orders
|
2014-12-09 20:28:50 +01:00
|
|
|
belongs_to :dagschotel, class_name: 'Product'
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2015-03-20 03:57:00 +01:00
|
|
|
validates_attachment :avatar,
|
|
|
|
presence: true,
|
|
|
|
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2015-01-06 20:18:01 +01:00
|
|
|
scope :members, -> { where koelkast: false }
|
2015-06-30 22:30:34 +02:00
|
|
|
scope :publik, -> { where private: false }
|
2015-01-06 20:18:01 +01:00
|
|
|
|
2015-03-19 22:37:16 +01:00
|
|
|
def self.from_omniauth(auth)
|
2015-03-21 17:58:49 +01:00
|
|
|
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
2015-03-19 22:37:16 +01:00
|
|
|
user.provider = auth.provider
|
|
|
|
user.uid = auth.uid
|
2015-03-23 11:54:15 +01:00
|
|
|
user.avatar = Identicon.data_url_for auth.uid
|
2015-03-19 22:37:16 +01:00
|
|
|
end
|
2015-03-20 02:21:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def nickname
|
|
|
|
self.uid
|
|
|
|
end
|
|
|
|
|
2015-03-19 16:22:55 +01:00
|
|
|
def debt
|
|
|
|
self.debt_cents / 100.0
|
2014-12-10 10:00:00 +01:00
|
|
|
end
|
|
|
|
|
2015-03-19 16:22:55 +01:00
|
|
|
def debt=(value)
|
2014-12-10 10:00:00 +01:00
|
|
|
if value.is_a? String then value.sub!(',', '.') end
|
2015-03-19 16:22:55 +01:00
|
|
|
self.debt_cents = (value.to_f * 100).to_int
|
2015-02-09 17:06:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Change URL params for User
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
"#{id} #{nickname}".parameterize
|
|
|
|
end
|
2014-11-06 14:46:59 +01:00
|
|
|
end
|