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