Replaces the OMNIAUTH_REGEX logic with a boolean
This commit is contained in:
@@ -13,10 +13,10 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
if resource.email_provided?
|
||||
super(resource)
|
||||
else
|
||||
if resource.pending_finish_signup?
|
||||
finish_signup_path
|
||||
else
|
||||
super(resource)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
class User < ActiveRecord::Base
|
||||
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
|
||||
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
|
||||
|
||||
include Verification
|
||||
|
||||
@@ -31,7 +29,6 @@ class User < ActiveRecord::Base
|
||||
validate :validate_username_length
|
||||
|
||||
validates :official_level, inclusion: {in: 0..5}
|
||||
validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
validates :locale, inclusion: {in: I18n.available_locales.map(&:to_s),
|
||||
@@ -42,6 +39,7 @@ class User < ActiveRecord::Base
|
||||
accepts_nested_attributes_for :organization, update_only: true
|
||||
|
||||
attr_accessor :skip_password_validation
|
||||
attr_accessor :registering_with_oauth
|
||||
|
||||
scope :administrators, -> { joins(:administrators) }
|
||||
scope :moderators, -> { joins(:moderator) }
|
||||
@@ -58,14 +56,15 @@ class User < ActiveRecord::Base
|
||||
email, user = nil, nil
|
||||
if auth.info.verified || auth.info.verified_email
|
||||
email = auth.info.email
|
||||
user = User.where(email: email).first if email
|
||||
user = User.where(email: email).first
|
||||
end
|
||||
user || User.new(
|
||||
registering_with_oauth: true,
|
||||
username: auth.info.nickname || auth.extra.raw_info.name.parameterize('-') || auth.uid,
|
||||
email: email || "#{OMNIAUTH_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
|
||||
email: email,
|
||||
password: Devise.friendly_token[0,20],
|
||||
terms_of_service: '1',
|
||||
confirmed_at: Time.now
|
||||
confirmed_at: DateTime.now
|
||||
)
|
||||
end
|
||||
|
||||
@@ -149,11 +148,6 @@ class User < ActiveRecord::Base
|
||||
erased_at.present?
|
||||
end
|
||||
|
||||
def email_provided?
|
||||
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
|
||||
!!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX)
|
||||
end
|
||||
|
||||
def locked?
|
||||
Lock.find_or_create_by(user: self).locked?
|
||||
end
|
||||
@@ -176,11 +170,11 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def username_required?
|
||||
!organization? && !erased?
|
||||
!organization? && !erased? && !registering_with_oauth
|
||||
end
|
||||
|
||||
def email_required?
|
||||
!erased?
|
||||
!erased? && !registering_with_oauth
|
||||
end
|
||||
|
||||
def has_official_email?
|
||||
@@ -192,6 +186,10 @@ class User < ActiveRecord::Base
|
||||
self[:locale] ||= I18n.default_locale.to_s
|
||||
end
|
||||
|
||||
def pending_finish_signup?
|
||||
email.blank? && unconfirmed_email.blank?
|
||||
end
|
||||
|
||||
private
|
||||
def clean_document_number
|
||||
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?
|
||||
|
||||
Reference in New Issue
Block a user