asciinema.org/app/models/user.rb

32 lines
776 B
Ruby
Raw Normal View History

class User < ActiveRecord::Base
2012-04-06 12:06:40 +00:00
has_many :user_tokens, :dependent => :destroy
has_many :asciicasts, :dependent => :destroy
has_many :comments, :dependent => :destroy
2012-04-06 12:06:40 +00:00
has_many :likes, :dependent => :destroy
2012-03-04 22:07:45 +00:00
has_many :user_tokens, :dependent => :destroy
has_many :asciicasts, :dependent => :destroy
2012-04-06 20:58:44 +00:00
has_many :comments, :dependent => :destroy
2012-04-09 12:42:22 +00:00
attr_accessible :nickname, :email, :name
validates :nickname, :email, presence: true, uniqueness: true
def self.for_credentials(credentials)
where(provider: credentials.provider, uid: credentials.uid).first
end
def self.for_email(email)
where(email: email).first
end
2012-03-04 22:07:45 +00:00
def to_param
nickname
end
2012-03-04 19:29:19 +00:00
def add_user_token(token)
user_tokens.where(:token => token).first_or_create
2012-03-04 19:29:19 +00:00
end
end