2012-02-25 16:30:42 +00:00
|
|
|
class User < ActiveRecord::Base
|
|
|
|
|
2012-04-06 12:06:40 +00:00
|
|
|
has_many :user_tokens, :dependent => :destroy
|
|
|
|
has_many :asciicasts, :dependent => :destroy
|
2012-04-09 15:04:58 +00:00
|
|
|
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-03-04 17:14:58 +00:00
|
|
|
|
2012-04-09 12:42:22 +00:00
|
|
|
attr_accessible :nickname, :email, :name
|
|
|
|
|
2013-10-22 15:52:04 +00:00
|
|
|
validates :nickname, :email, presence: true, uniqueness: true
|
|
|
|
|
2013-10-20 16:51:35 +00:00
|
|
|
def self.for_credentials(credentials)
|
2013-10-19 18:59:39 +00:00
|
|
|
where(provider: credentials.provider, uid: credentials.uid).first
|
2013-10-20 16:51:35 +00:00
|
|
|
end
|
2013-10-19 18:59:39 +00:00
|
|
|
|
2013-10-20 16:51:35 +00:00
|
|
|
def self.for_email(email)
|
|
|
|
where(email: email).first
|
|
|
|
end
|
2013-10-19 18:59:39 +00:00
|
|
|
|
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)
|
2013-08-08 13:07:48 +00:00
|
|
|
user_tokens.where(:token => token).first_or_create
|
2012-03-04 19:29:19 +00:00
|
|
|
end
|
2013-08-19 15:08:13 +00:00
|
|
|
|
2012-02-25 16:30:42 +00:00
|
|
|
end
|