Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ApplicationRecord
- # Include default devise modules. Others available are:
- # :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable,
- :confirmable, :omniauthable
- validates :fullname, presence: true, length: {maximum: 50}
- def self.from_omniauth(auth)
- user = User.where(email: auth.info.email).first
- if user
- return user
- else
- where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
- user.email = auth.info.email
- user.password = Devise.friendly_token[0,20]
- user.fullname = auth.info.name
- user.image = auth.info.image
- user.uid = auth.uid
- user.provider = auth.provider
- # If you are using confirmable and the provider(s) you use validate emails,
- # uncomment the line below to skip the confirmation emails.
- user.skip_confirmation!
- end
- end
- end
- def self.find_for_google_oauth2(access_token, signed_in_resourse=nil)
- data = access_token.info
- user = User.where(:provider => access_token.provider, :uid.access_token.uid).first
- if user
- return user
- else
- registered_user = User.where(:email => access_token.email).first
- if registered_user
- return registered_user
- else
- user = User.create(
- name: data["name"],
- provider: access_token.provider,
- email: data["email"],
- uid: access_token.uid,
- password: Divise.friendly_token[0,20]
- )
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment