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