diff --git a/app/models/user.rb b/app/models/user.rb index 1256b67..97a5bd8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,11 +1,14 @@ class User < ActiveRecord::Base + dragonfly_accessor :avatar + def self.find_or_create_from_auth(auth) user = User.find_by(provider: auth.provider, uid: auth.uid) if user.blank? user = User.create(provider: auth.provider, uid: auth.uid, username: auth.info.nickname, - name: auth.info.name) + name: auth.info.name, + avatar_url: auth.info.image) end user end diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb new file mode 100644 index 0000000..bc38b0d --- /dev/null +++ b/config/initializers/dragonfly.rb @@ -0,0 +1,27 @@ +require 'dragonfly' + +# Configure +Dragonfly.app.configure do + plugin :imagemagick + + protect_from_dos_attacks true + secret "0da375f9754c75707f2a3b4e0c75dffb7ec7d6bb1a4a77e8a8dcfba9037bebce" + + url_format "/media/:job/:name" + + datastore :file, + root_path: Rails.root.join('public/system/dragonfly', Rails.env), + server_root: Rails.root.join('public') +end + +# Logger +Dragonfly.logger = Rails.logger + +# Mount as middleware +Rails.application.middleware.use Dragonfly::Middleware + +# Add model functionality +if defined?(ActiveRecord::Base) + ActiveRecord::Base.extend Dragonfly::Model + ActiveRecord::Base.extend Dragonfly::Model::Validations +end diff --git a/db/migrate/20140324170840_add_avatar_to_user.rb b/db/migrate/20140324170840_add_avatar_to_user.rb new file mode 100644 index 0000000..397c6f9 --- /dev/null +++ b/db/migrate/20140324170840_add_avatar_to_user.rb @@ -0,0 +1,5 @@ +class AddAvatarToUser < ActiveRecord::Migration + def change + add_column :users, :avatar_uid, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 16ee2f1..8c1843a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140324161505) do +ActiveRecord::Schema.define(version: 20140324170840) do create_table "images", force: true do |t| t.integer "user_id" @@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20140324161505) do t.string "uid" t.datetime "created_at" t.datetime "updated_at" + t.string "avatar_uid" end end