// Automatic FlutterFlow imports import '/backend/schema/structs/index.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'index.dart'; // Imports other custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom action code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'dart:convert'; import 'package:http/http.dart' as http; Future drupalLogin( String username, String password, String loginUrl, ) async { try { final response = await http.post( Uri.parse(loginUrl), headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: jsonEncode({ 'username': username, 'password': password, }), ); if (response.statusCode == 200) { final data = jsonDecode(response.body); return { 'success': true, 'sessid': data['sessid'], 'session_name': data['session_name'], 'token': data['token'], 'uid': data['user']['uid']?.toString(), 'name': data['user']['name'], 'mail': data['user']['mail'], }; } else { return { 'success': false, 'error': 'Login failed: ${response.statusCode}', 'body': response.body, }; } } catch (e) { return { 'success': false, 'error': e.toString(), }; } } // Set your action name, define your arguments and return parameter, // and then add the boilerplate code using the `` button on the right!