Advertisement
theminijohn

User Model

Jul 17th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.69 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2.     # Include default devise modules. Others available are:
  3.     # :token_authenticatable, :confirmable,
  4.     # :lockable, :timeoutable and :omniauthable
  5.     devise :database_authenticatable, :registerable, #:recoverable,
  6.            :rememberable, :trackable, :validatable,
  7.            :omniauthable, :omniauth_providers => [:facebook]
  8.  
  9.     # Setup accessible (or protected) attributes for your model
  10.     attr_accessible :email, :password, :password_confirmation, :remember_me, :name,
  11.                     :provider, :uid, :country, :facebooklink, :twitterlink, :tumblrlink,
  12.                                     :avatar, :avatar_file_name, :userbio
  13.  
  14.  
  15.     #Validates User Bio
  16.     #validates :userbio, length: { :minimum => 0, :maximum => 140 }
  17.  
  18.     #For Profile Picture
  19.     has_attached_file :avatar, :default_url => "http://placehold.it/150x150&text=Missing",
  20.                                         :styles => { :thumb => "100x100>",
  21.                                                                                      :avatar => "154x154>",
  22.                                                                                      :medium => "300x300>",
  23.                                                                                      :large => "400x400>"}
  24.  
  25.     #Validates the Profile Picture
  26.     validates_attachment :avatar,
  27.                                              content_type: { content_type: [ 'image/jpeg', 'image/jpg', 'image/png'] },
  28.                                              size: { less_than: 4.megabytes }
  29.  
  30.     # attr_accessible :title, :body
  31.  
  32.     def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
  33.         user = User.where(:provider => auth.provider, :uid => auth.uid).first
  34.         unless user
  35.             user = User.create(name:auth.extra.raw_info.name,
  36.                                provider:auth.provider,
  37.                                uid:auth.uid,
  38.                                email:auth.info.email,
  39.                                password:Devise.friendly_token[0,20]
  40.             )
  41.         end
  42.         user
  43.     end
  44.  
  45.     has_many :pins
  46.     has_many :boards
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement