1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable, :database_authenticatable
@@authentication_type = "#{Rails.application.config.chouette_authentication_settings[:type]}_authenticatable".to_sym
cattr_reader :authentication_type
devise :invitable, :registerable, :validatable,
:recoverable, :rememberable, :trackable,
:confirmable, :async, authentication_type
# FIXME https://github.com/nbudin/devise_cas_authenticatable/issues/53
# Work around :validatable, when database_authenticatable is diabled.
attr_accessor :password unless authentication_type == :database_authenticatable
# Setup accessible (or protected) attributes for your model
# attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes
belongs_to :organisation
accepts_nested_attributes_for :organisation
validates :organisation, :presence => true
validates :email, :presence => true, :uniqueness => true
validates :name, :presence => true
before_validation(:on => :create) do
self.password ||= Devise.friendly_token.first(6)
self.password_confirmation ||= self.password
end
after_destroy :check_destroy_organisation
def cas_extra_attributes=(extra_attributes)
extra_attributes.each do |name, value|
# case name.to_sym
# Extra attributes
# when :fullname
# self.fullname = value
# when :email
# self.email = value
# end
end
end
private
# remove organisation and referentials if last user of it
def check_destroy_organisation
if organisation.users.empty?
organisation.destroy
end
end
end
|