module Rodauth::InternalRequestClassMethods

  1. lib/rodauth/features/internal_request.rb

Methods

Public Instance

  1. instance_variables_used
  2. internal_request

Public Instance methods

instance_variables_used()
[show source]
    # File lib/rodauth/features/internal_request.rb
308 def instance_variables_used
309   super + [
310     :@session,
311     :@params,
312     :@flash,
313     :@internal_request_block,
314     :@internal_request_return_value,
315     :@internal_request_return_value_set,
316     :@error_reason,
317     :@return_false_on_error
318   ]
319 end
internal_request(route, opts={}, &block)
[show source]
    # File lib/rodauth/features/internal_request.rb
321 def internal_request(route, opts={}, &block)
322   opts = opts.dup
323   
324   env = {
325      'REQUEST_METHOD'=>'POST',
326      'PATH_INFO'=>'/'.dup,
327      "SCRIPT_NAME" => "",
328      "HTTP_HOST" => INVALID_DOMAIN,
329      "SERVER_NAME" => INVALID_DOMAIN,
330      "SERVER_PORT" => 443,
331      "CONTENT_TYPE" => "application/x-www-form-urlencoded",
332      "rack.input"=>StringIO.new(''),
333      "rack.url_scheme"=>"https"
334   }
335   env.merge!(opts.delete(:env)) if opts[:env]
336 
337   session = {}
338   session.merge!(opts.delete(:session)) if opts[:session]
339 
340   params = {}
341   params.merge!(opts.delete(:params)) if opts[:params]
342 
343   scope = roda_class.new(env)
344   rodauth = new(scope)
345   rodauth.session = session
346   rodauth.params = params
347   rodauth.internal_request_block = block
348 
349   unless account_id = opts.delete(:account_id)
350     if (account_login = opts.delete(:account_login))
351       if (account = rodauth.send(:_account_from_login, account_login))
352         account_id = account[rodauth.account_id_column]
353       else
354         raise InternalRequestError, "no account for login: #{account_login.inspect}"
355       end
356     end
357   end
358 
359   if account_id
360     session[rodauth.session_key] = account_id
361     unless authenticated_by = opts.delete(:authenticated_by)
362       authenticated_by = case route
363       when :otp_auth, :sms_request, :sms_auth, :recovery_auth, :webauthn_auth, :webauthn_auth_params, :valid_otp_auth?, :valid_sms_auth?, :valid_recovery_auth?
364         ['internal1']
365       else
366         ['internal1', 'internal2']
367       end
368     end
369     session[rodauth.authenticated_by_session_key] = authenticated_by
370   end
371 
372   opts.keys.each do |k|
373     meth = :"#{k}_param"
374     params[rodauth.public_send(meth).to_s] = opts.delete(k) if rodauth.respond_to?(meth)
375   end
376 
377   unless opts.empty?
378     warn "unhandled options passed to #{route}: #{opts.inspect}"
379   end
380 
381   rodauth.handle_internal_request(:"_handle_#{route}")
382 end