mirror of
https://github.com/danbee/my-images
synced 2025-03-04 08:49:05 +00:00
Add avatar.
This commit is contained in:
parent
2911dee281
commit
6432c53394
@ -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
|
||||
|
||||
27
config/initializers/dragonfly.rb
Normal file
27
config/initializers/dragonfly.rb
Normal file
@ -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
|
||||
5
db/migrate/20140324170840_add_avatar_to_user.rb
Normal file
5
db/migrate/20140324170840_add_avatar_to_user.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddAvatarToUser < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :avatar_uid, :string
|
||||
end
|
||||
end
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user