Created
October 18, 2017 14:14
-
-
Save Nursultan91/c1bb9fbe7a77e678cae8fae99c020a3f to your computer and use it in GitHub Desktop.
Жалуется на 32 строку
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment