home,signin,login view and ol logik
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../pages/home_view.dart';
|
||||
import '../pages/login_view.dart';
|
||||
import '../services/directus_service.dart';
|
||||
|
||||
class SigninController extends GetxController {
|
||||
final userNameController = TextEditingController();
|
||||
final emailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final cityController = TextEditingController();
|
||||
final countryController = TextEditingController();
|
||||
final directusService = DirectusService();
|
||||
|
||||
@override
|
||||
void onReady() {}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
userNameController.dispose();
|
||||
emailController.dispose();
|
||||
passwordController.dispose();
|
||||
cityController.dispose();
|
||||
countryController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void register() async {
|
||||
// Eingaben überprüfen
|
||||
if (!_checkInputs()) return;
|
||||
|
||||
// Registrierungslogik
|
||||
var userName = userNameController.text.trim();
|
||||
var email = emailController.text.trim().toLowerCase();
|
||||
var password = passwordController.text;
|
||||
var city = cityController.text.trim();
|
||||
var country = countryController.text.trim();
|
||||
|
||||
print(
|
||||
'Registrieren mit Benutzername: $userName, E-Mail: $email, Stadt: $city, Land: $country',
|
||||
);
|
||||
|
||||
bool registrationSuccess = await directusService.register(userName, email, password, city, country);
|
||||
|
||||
if (registrationSuccess) {
|
||||
Get.snackbar(
|
||||
'Registrierung erfolgreich',
|
||||
'Willkommen, $userName!',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
var userIdentId = base64Encode(utf8.encode('$email:$password'));
|
||||
Get.offAllNamed(HomePage.namedRoute, arguments: {'userIdentId': userIdentId});
|
||||
} else {
|
||||
Get.snackbar(
|
||||
'Registrierung fehlgeschlagen',
|
||||
'Bitte überprüfen Sie Ihre Eingaben und versuchen Sie es erneut.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void goToLoginPage() {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
Get.offAllNamed(LoginPage.namedRoute);
|
||||
}
|
||||
|
||||
bool _checkInputs() {
|
||||
if (userNameController.text.trim().isEmpty ||
|
||||
emailController.text.trim().isEmpty ||
|
||||
passwordController.text.isEmpty) {
|
||||
Get.snackbar(
|
||||
'Fehler',
|
||||
'Bitte alle erforderlichen Felder ausfüllen',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (passwordController.text.length < 6) {
|
||||
Get.snackbar(
|
||||
'Fehler',
|
||||
'Passwort muss mindestens 6 Zeichen lang sein',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user