Class: Caboose::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::User
- Defined in:
- app/models/caboose/user.rb
Class Method Summary collapse
- .logged_out_user ⇒ Object
- .logged_out_user_id ⇒ Object
- .user_for_reset_id(reset_id) ⇒ Object
- .validate_token(token) ⇒ Object
Instance Method Summary collapse
- #add_to_role(role_id) ⇒ Object
- #add_to_role_with_name(role_name) ⇒ Object
- #is_allowed(resource, action) ⇒ Object
- #is_member?(role_id) ⇒ Boolean
Class Method Details
.logged_out_user ⇒ Object
21 22 23 |
# File 'app/models/caboose/user.rb', line 21 def self.logged_out_user return self.where('username' => 'elo').first end |
.logged_out_user_id ⇒ Object
25 26 27 |
# File 'app/models/caboose/user.rb', line 25 def self.logged_out_user_id return self.where('username' => 'elo').limit(1).pluck(:id)[0] end |
.user_for_reset_id(reset_id) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/models/caboose/user.rb', line 69 def self.user_for_reset_id(reset_id) return nil if reset_id.nil? d = DateTime.now - 3.days if self.where("password_reset_id = ? and password_reset_sent > ?", reset_id, d).exists? return self.where("password_reset_id = ? and password_reset_sent > ?", reset_id, d).first end return nil end |
.validate_token(token) ⇒ Object
40 41 42 43 |
# File 'app/models/caboose/user.rb', line 40 def self.validate_token(token) user = self.where('token' => token).first return user end |
Instance Method Details
#add_to_role(role_id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/caboose/user.rb', line 51 def add_to_role(role_id) r = Caboose::Role.find(role_id) return false if r.nil? if (!is_member?(r.id)) roles.push r save end return true end |
#add_to_role_with_name(role_name) ⇒ Object
45 46 47 48 49 |
# File 'app/models/caboose/user.rb', line 45 def add_to_role_with_name(role_name) r = Caboose::Role.where(:name => role_name).first return false if r.nil? return add_to_role(r.id) end |
#is_allowed(resource, action) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/caboose/user.rb', line 29 def is_allowed(resource, action) elo = Caboose::Role.logged_out_role return true if elo.is_allowed(resource, action) eli = Caboose::Role.logged_in_role return true if self.id != elo.id && eli.is_allowed(resource, action) for role in roles return true if role.is_allowed(resource, action) end return false; end |
#is_member?(role_id) ⇒ Boolean
62 63 64 65 66 67 |
# File 'app/models/caboose/user.rb', line 62 def is_member?(role_id) roles.each do |r| return true if (r.id == role_id) end return false end |