blob: c41d61bfcf554a52db2cb77d802d876d7ea8f5d8 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 | module ControllerExtension::TokenAuthentication
  extend ActiveSupport::Concern
  protected
  def token
    @token ||= authenticate_with_http_token do |token, options|
      Token.find_by_token(token) || ApiToken.find_by_token(token, request.headers['REMOTE_ADDR'])
    end
  end
  def token_authenticate
    @token_authenticated ||= token.authenticate if token
  end
  def require_token
    login_required unless token_authenticate
  end
  def logout
    super
    clear_token
  end
  def clear_token
    token.destroy if token
  end
end
 |