mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
First checkin
This commit is contained in:
parent
f207e2c8b7
commit
90b30db9e8
260 changed files with 37349 additions and 0 deletions
55
app/models/user.rb
Normal file
55
app/models/user.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
class User < ActiveRecord::Base
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
# :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
has_and_belongs_to_many :roles
|
||||
has_one :person
|
||||
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_id, :role_ids, :person_attributes
|
||||
accepts_nested_attributes_for :person
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
before_save :setup_role
|
||||
before_create :create_person
|
||||
|
||||
def role?(role)
|
||||
Rails.logger.debug("Checking role in user")
|
||||
return !!self.roles.find_by_name(role.to_s.camelize)
|
||||
end
|
||||
|
||||
def get_roles
|
||||
return self.roles
|
||||
end
|
||||
|
||||
def setup_role
|
||||
if self.role_ids.empty?
|
||||
self.role_ids = [1]
|
||||
end
|
||||
end
|
||||
|
||||
def popup_details
|
||||
details = "<b>Sign-in Count</b><br>"
|
||||
details += "#{self.sign_in_count}<br>"
|
||||
details += "<b>Current Sign-in</b><br>"
|
||||
details += "#{self.current_sign_in_at}<br>"
|
||||
details += "<b>Last Sign-in</b><br>"
|
||||
details += "#{self.last_sign_in_at}<br>"
|
||||
details += "<b>Current Sign-in IP</b><br>"
|
||||
details += "#{self.current_sign_in_ip}<br>"
|
||||
details += "<b>Last Sign-in IP</b><br>"
|
||||
details += "#{self.last_sign_in_ip}<br>"
|
||||
details += "<b>Created at</b><br>"
|
||||
details += "#{self.created_at}<br>"
|
||||
end
|
||||
|
||||
private
|
||||
def create_person
|
||||
# TODO Search people for existing email address, add to their account
|
||||
build_person(:email => self.email)
|
||||
true
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue