2015-09-23 10:02:01 +02:00
|
|
|
class User < ActiveRecord::Base
|
2015-12-24 10:12:23 +01:00
|
|
|
enum loged_in_with_france_connect: {particulier: 'particulier',
|
|
|
|
entreprise: 'entreprise'}
|
|
|
|
|
2015-09-23 10:02:01 +02:00
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
|
|
|
devise :database_authenticatable, :registerable,
|
|
|
|
:recoverable, :rememberable, :trackable, :validatable
|
2015-09-23 12:16:21 +02:00
|
|
|
|
2016-01-18 16:20:51 +01:00
|
|
|
has_many :dossiers, dependent: :destroy
|
2015-10-06 11:21:20 +02:00
|
|
|
|
2015-12-24 10:12:23 +01:00
|
|
|
def self.find_for_france_connect_particulier user_info
|
|
|
|
|
|
|
|
User.find_by(france_connect_particulier_id: user_info[:france_connect_particulier_id])
|
|
|
|
end
|
|
|
|
|
2015-10-07 10:29:44 +02:00
|
|
|
def self.find_for_france_connect email, siret
|
2015-10-06 11:21:20 +02:00
|
|
|
user = User.find_by_email(email)
|
2015-10-07 10:29:44 +02:00
|
|
|
if user.nil?
|
2015-12-24 10:12:23 +01:00
|
|
|
return User.create(email: email, password: Devise.friendly_token[0, 20], siret: siret)
|
2015-10-07 10:29:44 +02:00
|
|
|
else
|
|
|
|
user.update_attributes(siret: siret)
|
|
|
|
user
|
|
|
|
end
|
2015-10-06 11:21:20 +02:00
|
|
|
end
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
def loged_in_with_france_connect?
|
|
|
|
!loged_in_with_france_connect.nil?
|
|
|
|
end
|
2015-09-23 10:02:01 +02:00
|
|
|
end
|