Class: User
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- User
- Defined in:
- model/user.rb,
model/security.rb
Overview
Copyright © 2016-2024, Claudio Bustos Navarrete All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Class Method Summary collapse
Instance Method Summary collapse
- #accesible_users ⇒ Object
- #authorizations ⇒ Object
- #change_password(password) ⇒ Object
- #correct_password?(test_password) ⇒ Boolean
- #groups ⇒ Object
- #systematic_reviews ⇒ Object
- #systematic_reviews_id ⇒ Object
Class Method Details
.create_new_user(language = 'en') ⇒ Object
55 56 57 58 59 |
# File 'model/user.rb', line 55 def self.create_new_user(language='en') ultimo_usuario=$db["SELECT max(id) as max_id from users"].get(:max_id).to_i n_id=ultimo_usuario+1 User.insert(:login=>"user_#{n_id}", :name=>I18n::t(:User_only_name, :user_name=>n_id), :password=>Digest::SHA256.hexdigest("user_#{n_id}") , :role_id=>'analyst', :active=>true,:language=>language) end |
Instance Method Details
#accesible_users ⇒ Object
43 44 45 |
# File 'model/user.rb', line 43 def accesible_users User.where(:id=>$db["SELECT DISTINCT(user_id) FROM groups_users WHERE group_id IN (SELECT group_id FROM groups_users WHERE user_id=?)", self[:id]].map(:user_id)) end |
#authorizations ⇒ Object
66 67 68 69 |
# File 'model/security.rb', line 66 def ##$log.info(self.rol) Role[self[:role_id]]. end |
#change_password(password) ⇒ Object
47 48 49 |
# File 'model/user.rb', line 47 def change_password(password) User[self[:id]].update(:password=>Digest::SHA1.hexdigest(password)) end |
#correct_password?(test_password) ⇒ Boolean
51 52 53 |
# File 'model/user.rb', line 51 def correct_password?(test_password) self.password == Digest::SHA1.hexdigest(test_password) end |
#groups ⇒ Object
31 32 33 |
# File 'model/user.rb', line 31 def groups Group.where(:id=>GroupsUser.where(:user_id => self[:id]).map(:group_id)) end |
#systematic_reviews ⇒ Object
39 40 41 |
# File 'model/user.rb', line 39 def systematic_reviews SystematicReview.where(:id => systematic_reviews_id) end |
#systematic_reviews_id ⇒ Object
35 36 37 |
# File 'model/user.rb', line 35 def systematic_reviews_id $db["SELECT id FROM systematic_reviews rs INNER JOIN groups_users gu ON rs.group_id=gu.group_id WHERE user_id=?", self[:id]].select_map(:id) end |