### 実現したいこと
gem 'omniauth-line'でLINE認証によるアカウント登録の際に画像もアバター画像も登録する
(deviseを使用。)
### 問題
gem 'omniauth-line'のgithubを見て値を取り出せると思うのですが、
恐らくcarrierwaveかS3への保存段階で問題が起こっているかと思うのですが
解決への道に困っております。
LINE認証に詳しい方、ご教授お願い申し上げます。
※ユーザー画像以外はサーバーへ保存され新規アカウント登録は成功しております
参考にしたサイト
gem 'omniauth-line'のgithub
Rails5系でLineログインを実装する
コード
image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base # リサイズしたり画像形式を変更するのに必要 # Include RMagick or MiniMagick support: include CarrierWave::RMagick #画像が回転してしまう問題を解消 process :fix_rotate def fix_rotate manipulate! do |img| img = img.auto_orient img = yield(img) if block_given? img end end # S3にアップロードする場合 if Rails.env.development? storage :file elsif Rails.env.test? storage :file else storage :fog end # 保存先ーーーーーーーーーーーーーー def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # デフォルト画像は400x400に収まるようリサイズ process :resize_to_limit => [400, 400] # サムネイル画像 version :thumb do process resize_to_fill: [100, 100] end # 保存形式をJPGにする process :convert => 'png' # 許可する画像の拡張子 def extension_whitelist %w(jpg jpeg gif png url) end # 保存するファイルの命名規則 def filename "#{secure_token}.#{file.extension}" if original_filename.present? end protected def secure_token var = :"@#{mounted_as}_secure_token" model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid) end end
OmniauthCallbacksController
1class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 2 3 def line 4 basic_action 5 end 6 7 private 8 def basic_action 9 @omniauth = request.env['omniauth.auth'] 10 if @omniauth.present? 11 @user = User.where(provider: @omniauth['provider'], uid: @omniauth['uid']).first 12 if @user 13 bypass_sign_in(@user) 14 else 15 @user = User.new(omniauth_params) 16 email = @omniauth['info']['email'] ? @omniauth['info']['email'] : "#{@omniauth['uid']}-#{@omniauth['provider']}@example.com" 17 @user = current_user || User.create!(provider: @omniauth['provider'], uid: @omniauth['uid'], email: email, name: @omniauth['info']['name'], avater: @omniauth['info']['image'], password: Devise.friendly_token[0, 20]) 18 bypass_sign_in(@user) 19 redirect_to user_mypage_path(@user.id) and return 20 end 21 end 22 redirect_to user_mypage_path(@user.id) and return 23 end 24 25 def fake_email(uid,provider) 26 return "#{auth.uid}-#{auth.provider}@example.com" 27 end 28 29 30 protected 31 def omniauth_params 32 params.require(:user).permit(:provider, :uid, :email, :name, :avater, :password) 33 end 34 35 36end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。