Commit c18fefcfa4cef0b0036508ec57dd8d818e007f72
Committed by
Rodrigo Souto
1 parent
4e9cbfd2
Exists in
master
and in
29 other branches
api: set session cookie
Showing
3 changed files
with
8 additions
and
2 deletions
Show diff stats
lib/noosfero/api/api.rb
lib/noosfero/api/helpers.rb
| ... | ... | @@ -9,7 +9,7 @@ module Noosfero |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def current_user |
| 12 | - private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token']).to_s if params | |
| 12 | + private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token'] || cookies['_noosfero_api_session']).to_s if params | |
| 13 | 13 | @current_user ||= User.find_by_private_token(private_token) |
| 14 | 14 | @current_user = nil if !@current_user.nil? && @current_user.private_token_expired? |
| 15 | 15 | @current_user |
| ... | ... | @@ -146,7 +146,11 @@ module Noosfero |
| 146 | 146 | render_api_error!(messages.join(','), 400) |
| 147 | 147 | end |
| 148 | 148 | protected |
| 149 | - | |
| 149 | + | |
| 150 | + def set_session_cookie | |
| 151 | + cookies['_noosfero_api_session'] = { value: @current_user.private_token, httponly: true } if @current_user.present? | |
| 152 | + end | |
| 153 | + | |
| 150 | 154 | def start_log |
| 151 | 155 | logger.info "Started #{request.path} #{request.params.except('password')}" |
| 152 | 156 | end | ... | ... |