asciinema.org/app/models/user.rb
2012-03-04 23:07:45 +01:00

28 lines
668 B
Ruby

class User < ActiveRecord::Base
validate :provider, :presence => true
validate :uid, :presence => true
validate :nickname, :presence => true
has_many :user_tokens, :dependent => :destroy
has_many :asciicasts, :dependent => :destroy
def self.create_with_omniauth(auth)
create! do |user|
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)
end
end
def to_param
nickname
end
def add_user_token(token)
user_tokens.find_or_create_by_token(token)
end
end