Module: Sinatra::SessionAuth::Helpers
- Defined in:
- lib/sinatra/sessionauth.rb
Instance Method Summary collapse
- #allow_password_recovery? ⇒ Boolean
-
#auth_to(auth) ⇒ Object
Verifica que la persona tenga un authorization especĂfico.
- #authorize(login, password) ⇒ Object
- #DELETE__user_ ⇒ Object
- #halt_unless_auth(*args) ⇒ Object
- #halt_unless_auth_any(*args) ⇒ Object
- #is_session_user(user_id) ⇒ Object
- #logout ⇒ Object
- #review_analyzed_by(review_id, user_id) ⇒ Object
- #review_belongs_to(review_id, user_id) ⇒ Object
- #show_user ⇒ Object
Instance Method Details
#allow_password_recovery? ⇒ Boolean
32 33 34 |
# File 'lib/sinatra/sessionauth.rb', line 32 def allow_password_recovery? !ENV['SMTP_SERVER'].nil? end |
#auth_to(auth) ⇒ Object
Verifica que la persona tenga un authorization especĂfico
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sinatra/sessionauth.rb', line 45 def auth_to(auth) #log.info(session['authorizations']) if session['user'].nil? false else if session['role_id']=='administrator' @admin_authorization_roles||=AuthorizationsRole.where(:role_id=>"administrator").select_map(:authorization_id) #@authorizations_cache||=Authorization.to_hash(:id) #Authorization.insert(:id=>auth, :description=>::I18n::t("sinatra_auth.permission_created_by_administrator")) if @authorizations_cache[auth].nil? unless @admin_authorization_roles.include? auth auth_o=Authorization[auth] raise Buhos::NoAuthorizationId, auth unless auth_o Role['administrator'].add_auth_to(auth_o) end true elsif session['authorizations'].include? auth true else false end end end |
#authorize(login, password) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sinatra/sessionauth.rb', line 90 def (login, password) u=User.filter(Sequel.lit("(login=? OR email=?) AND password=?", login,login, Digest::SHA1.hexdigest(password))) ##$log.info(u.first) if u.first user=u.first session['user']=user[:login] session['user_id']=user[:id] session['name']=user[:name] session['role_id']=user[:role_id] session['authorizations']=user..map {|v| v.id} session['language']=user.language ::I18n.locale = session['language'].to_sym true else false end end |
#DELETE__user_ ⇒ Object
111 |
# File 'lib/sinatra/sessionauth.rb', line 111 session.delete('user') |
#halt_unless_auth(*args) ⇒ Object
69 70 71 |
# File 'lib/sinatra/sessionauth.rb', line 69 def halt_unless_auth(*args) halt 403 if args.any? {|per| !auth_to(per)} end |
#halt_unless_auth_any(*args) ⇒ Object
73 74 75 |
# File 'lib/sinatra/sessionauth.rb', line 73 def halt_unless_auth_any(*args) halt 403 unless args.any? {|per| auth_to(per)} end |
#is_session_user(user_id) ⇒ Object
77 78 79 |
# File 'lib/sinatra/sessionauth.rb', line 77 def is_session_user(user_id) user_id.to_i==session['user_id'] end |
#logout ⇒ Object
110 111 112 |
# File 'lib/sinatra/sessionauth.rb', line 110 def logout session.delete('user') end |
#review_analyzed_by(review_id, user_id) ⇒ Object
86 87 88 |
# File 'lib/sinatra/sessionauth.rb', line 86 def review_analyzed_by(review_id, user_id) auth_to("review_analyze") and !$db["SELECT * FROM groups_users gu INNER JOIN systematic_reviews rs ON gu.group_id=rs.group_id WHERE rs.id=? AND gu.user_id=?", review_id, user_id].empty? end |
#review_belongs_to(review_id, user_id) ⇒ Object
82 83 84 |
# File 'lib/sinatra/sessionauth.rb', line 82 def review_belongs_to(review_id,user_id) auth_to("review_admin") and SystematicReview[:id=>review_id, :sr_administrator=>user_id] end |
#show_user ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sinatra/sessionauth.rb', line 35 def show_user ##$log.info(session) if !session['user'].nil? partial(:user) else partial(:guest) end end |