Class: Crystal::Processors::PrepareAutenticityToken

Inherits:
Processor
  • Object
show all
Defined in:
lib/crystal_ext/protect_from_forgery.rb

Instance Method Summary collapse

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/crystal_ext/protect_from_forgery.rb', line 7

def call        
  if config.session?
    request = workspace.request.must_be.defined
    params = workspace.params.must_be.defined
        
    token = request.session['authenticity_token'] || params['session_authenticity_token']

    if token.blank? and request.get? and
      token = generate_authenticity_token
      request.session['authenticity_token'] = token
    end
          
    workspace.session_authenticity_token = token
  end
  
  next_processor.call
end