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-05 23:25:21 +00:00
|
|
|
validates :provider, :presence => true
|
|
|
|
validates :uid, :presence => true
|
|
|
|
validates :nickname, :presence => true
|
|
|
|
|
2012-03-11 08:23:29 +00:00
|
|
|
validates_uniqueness_of \
|
|
|
|
:nickname,
|
2012-07-29 17:43:03 +00:00
|
|
|
:message => "Sorry, but your nickname is already taken, " \
|
|
|
|
"choose different one"
|
2012-02-25 16:30:42 +00:00
|
|
|
|
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
|
|
|
|
|
2012-02-25 16:30:42 +00:00
|
|
|
def self.create_with_omniauth(auth)
|
2012-03-05 23:25:21 +00:00
|
|
|
user = new
|
|
|
|
user.provider = auth["provider"]
|
|
|
|
user.uid = auth["uid"]
|
|
|
|
user.nickname = auth["info"]["nickname"]
|
|
|
|
user.name = auth["info"]["name"]
|
|
|
|
user.avatar_url = OauthHelper.get_avatar_url(auth)
|
|
|
|
user.save
|
|
|
|
user
|
2012-02-25 16:30:42 +00:00
|
|
|
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.find_or_create_by_token(token)
|
|
|
|
end
|
2012-02-25 16:30:42 +00:00
|
|
|
end
|