作成したメール認証機能を削除しようとして日曜日終わった
クラウドなメール送信サービスのひとつである「SendGrid」を使用し作成した
ログイン後のメール認証機能を無くそうとして日曜日終わってしまった記録。
モデル
app\models\user.rb
class User < ActiveRecord::Base
# モデルの設定、:confirmable,を削除する
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
#carrierwave用の設定、deviseの設定配下に追記
mount_uploader :avatar, AvatarUploader
# has_many :hogesにより子モデル(hoge)が複数ひもづくアソシエーションを定義する
has_many :hoges
# ツイッターでログインできるようになるためのメソッドの処理
def self.find_for_twitter_oauth(auth, signed_in_resource = nil)
user = User.find_by(provider: auth.provider, uid: auth.uid)
unless user
user = User.new(
name: auth.info.nickname,
image_url: auth.info.image,
provider: auth.provider,
uid: auth.uid,
email: auth.info.email ||= "#{auth.uid}-#{auth.provider}@example.com",
password: Devise.friendly_token[0, 20]
)
user.skip_confirmation!
user.save
end
user
end
#(アカウント新規登録)ランダムなuidを作成するcreate_unique_stringメソッド
def self.create_unique_string
SecureRandom.uuid
end
# omniauthでサインアップしたアカウントのユーザ情報の変更出来るようにする
def update_with_password(params, *options) # pdate_with_passwordをオーバーライド(メソッドを定義しなおしている)
if provider.blank?
super
else
params.delete :current_password
update_without_password(params, *options)
end
end
end
ひとまずrails s でサーバを起動してブラウザで動作を確認
rails s -b 0.0.0.0
エラー
- NoMethodError in Users::OmniauthCallbacksController#twitter
- Undefind method "user.skip_confirmation!"
app\models\user.rb
class User < ActiveRecord::Base
# モデルの設定、:confirmable,を削除する
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
#carrierwave用の設定、deviseの設定配下に追記
mount_uploader :avatar, AvatarUploader
# has_many :hogesにより子モデル(hoge)が複数ひもづくアソシエーションを定義する
has_many :hoges
# ツイッターでログインできるようになるためのメソッドの処理
def self.find_for_twitter_oauth(auth, signed_in_resource = nil)
user = User.find_by(provider: auth.provider, uid: auth.uid)
unless user
user = User.new(
name: auth.info.nickname,
image_url: auth.info.image,
provider: auth.provider,
uid: auth.uid,
email: auth.info.email ||= "#{auth.uid}-#{auth.provider}@example.com",
password: Devise.friendly_token[0, 20]
)
user.skip_confirmation!
user.save
end
user
end
#(アカウント新規登録)ランダムなuidを作成するcreate_unique_stringメソッド
def self.create_unique_string
SecureRandom.uuid
end
# omniauthでサインアップしたアカウントのユーザ情報の変更出来るようにする
def update_with_password(params, *options) # pdate_with_passwordをオーバーライド(メソッドを定義しなおしている)
if provider.blank?
super
else
params.delete :current_password
update_without_password(params, *options)
end
end
end
rails s -b 0.0.0.0
ここで結構調べる、あきらめかけた
もう一度モデル内の記述"user.skip_confirmation!"確認
app\models\user.rb
# ツイッターでログインできるようになるためのメソッドの処理
def self.find_for_twitter_oauth(auth, signed_in_resource = nil)
user = User.find_by(provider: auth.provider, uid: auth.uid)
unless user
user = User.new(
name: auth.info.nickname,
image_url: auth.info.image,
provider: auth.provider,
uid: auth.uid,
email: auth.info.email ||= "#{auth.uid}-#{auth.provider}@example.com",
password: Devise.friendly_token[0, 20]
)
# ツイッターでログインするときはメール認証要らないですよの意味っぽいこと書いてたのを忘れてた、ここを削除してみた
user.skip_confirmation!
user.save
end
再びrails s でサーバを起動してブラウザで動作を確認
rails s -b 0.0.0.0
解決
ちゃっちゃ系のラーメン屋でも探しに行こう
Author And Source
この問題について(作成したメール認証機能を削除しようとして日曜日終わった), 我々は、より多くの情報をここで見つけました https://qiita.com/okapy0922/items/eb90a421b150dbfad232著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .